jameshead.cpp
来自「一个语言识别引擎」· C++ 代码 · 共 1,200 行 · 第 1/4 页
CPP
1,200 行
computeModifiedPitchRoll(yaw-90, roll, pitch, roll_hat, pitch_hat);
computeOriginalPitchRoll(yaw-90, roll_d_hat, pitch_d_hat, roll_d, pitch_d);
computeTendonsLength(d1, d2, d3, roll_hat, pitch_hat);
vCmds[0]=-600*(roll_hat-roll_d_hat);
vCmds[1]=500*(pitch_hat-pitch_d_hat)+400*(roll_hat-roll_d_hat);
vCmds[2]=-500*(pitch_hat-pitch_d_hat)+400*(roll_hat-roll_d_hat);
//vCmds[0]=-400*(roll-roll_d);
//vCmds[1]=500*(pitch-pitch_d)+600*(roll-roll_d);
//vCmds[2]=-500*(pitch-pitch_d)+600*(roll-roll_d);
vCmds[0]*=pGain;
vCmds[1]*=pGain;
vCmds[2]*=pGain;
vCmds[0]=-(1-REL_WEIGHT)*3*(encoders[5]-d3) + REL_WEIGHT*vCmds[0];
vCmds[1]=-(1-REL_WEIGHT)*3*(encoders[6]-d2) + REL_WEIGHT*vCmds[1];
vCmds[2]=-(1-REL_WEIGHT)*3*(encoders[7]-d1) + REL_WEIGHT*vCmds[2];
ivel->velocityMove(5, vCmds[0]);
ivel->velocityMove(6, vCmds[1]);
ivel->velocityMove(7, vCmds[2]);
mutex.post();
double t2=Time::now();
count++;
static double dT=0;
dT+=t2-t1;
if (count%100==0)
{
fprintf(stderr, "%.2lf %.2lf %.2lf ", (encoders[5]-d3), (encoders[6]-d2), (encoders[7]-d1));
//fprintf(stderr, "%.2lf %.2lf %.2lf ", d3, d2, d1);
fprintf(stderr, "Inertial: %.2lf %.2lf %.2lf %.2lf", roll_hat, pitch_hat, roll_d_hat, pitch_d_hat);
//fprintf(stderr, "Inertial: %.2lf %.2lf", roll, pitch);
fprintf(stderr, "dT=%.3lf\n", (dT)/100);
dT=0;
}
}
void doRelease()
{
fprintf(stderr, "HeadControl::releasing...");
mutex.wait();
ivel->velocityMove(5, 0);
ivel->velocityMove(6, 0);
ivel->velocityMove(7, 0);
disableControl();
mutex.post();
delete [] encoders;
encoders=0;
fprintf(stderr, "done\n");
}
double roll;
double pitch;
double yaw;
double cmd_roll;
double cmd_pitch;
Vector inertiaValue;
double *encoders;
double *vCmds;
double pGain;
int nAxes;
Semaphore mutex;
};
JamesHead::JamesHead():
ImplementPositionControl<JamesHead, IPositionControl>(this),
ImplementVelocityControl<JamesHead, IVelocityControl>(this),
ImplementEncoders<JamesHead, IEncoders>(this),
ImplementPidControl<JamesHead, IPidControl>(this),
ImplementAmplifierControl<JamesHead, IAmplifierControl>(this),
ImplementControlLimits<JamesHead, IControlLimits>(this),
controller(0),
axisMap(0),
angleToEncoder(0),
zeros(0)
{
nj=HEAD_JOINTS;
axisMap=new int[nj];
angleToEncoder=new double [nj];
zeros=new double [nj];
for(int k=0;k<nj;k++)
{
axisMap[k]=k;
angleToEncoder[k]=1.0;
zeros[k]=0.0;
}
}
JamesHead::~JamesHead()
{
HeadControl *c=my_cast(controller);
if (c!=0)
delete c;
c=0;
}
bool JamesHead::open(yarp::os::Searchable& config)
{
Property headParams;
Property inertialParams;
headParams.fromString(config.toString());
ACE_OS::fprintf(stderr, "Opening JamesHead device\n");
//////////// head
Value &hdevice=headParams.findGroup("HEAD").find("device");
Value &hsubdevice=headParams.findGroup("HEAD").find("subdevice");
headParams.put("device", hdevice);
headParams.put("subdevice", hsubdevice);
// create a device for the head
ddHead.open(headParams);
if (!ddHead.isValid())
{
ACE_OS::printf("JamesHead: head device either not found or could not open\n");
return false;
}
// initialize interfaces
ImplementPositionControl<JamesHead, IPositionControl>::
initialize(nj, axisMap, angleToEncoder, zeros);
ImplementVelocityControl<JamesHead, IVelocityControl>::
initialize(nj, axisMap, angleToEncoder, zeros);
ImplementEncoders<JamesHead, IEncoders>::
initialize(nj, axisMap, angleToEncoder, zeros);
ImplementPidControl<JamesHead, IPidControl>::
initialize(nj, axisMap, angleToEncoder, zeros);
ImplementAmplifierControl<JamesHead, IAmplifierControl>::
initialize(nj, axisMap, angleToEncoder, zeros);
ImplementControlLimits<JamesHead, IControlLimits>::
initialize(nj, axisMap, angleToEncoder, zeros);
//////////// inertial
inertialParams.fromString(config.toString());
Value &idevice=inertialParams.findGroup("INERTIAL").find("device");
Value &isubdevice=inertialParams.findGroup("INERTIAL").find("subdevice");
inertialParams.put("device", idevice);
inertialParams.put("subdevice", isubdevice);
// create a device for the arm
ddInertia.open(inertialParams);
if (!ddInertia.isValid())
{
ACE_OS::printf("JamesHead: inertia device either not found or could not open");
return false;
}
// instantiate inertia and head
controller = new HeadControl(NC_RATE, &ddInertia, &ddHead);
HeadControl *c=my_cast(controller);
c->start();
return true;
}
bool JamesHead::close()
{
fprintf(stderr, "JamesHead::calling close\n");
HeadControl *c=my_cast(controller);
if (c!=0)
{
fprintf(stderr, "JamesHead::calling close\n");
c->stop();
}
return true;
}
bool JamesHead::getAxes(int *ax)
{
fprintf(stderr, "JamesHead::getAxes: %d\n", nj);
*ax=nj;
return true;
}
bool JamesHead::resetEncoderRaw(int j)
{
return true;
}
bool JamesHead::resetEncodersRaw()
{
return true;
}
bool JamesHead::setEncoderRaw(int j, double val)
{
return true;
}
bool JamesHead::setEncodersRaw(const double *vals)
{
return true;
}
bool JamesHead::getEncoderRaw(int j, double *v)
{
HeadControl *c=my_cast(controller);
if (c!=0)
c->getEncoder(j, v);
return true;
}
bool JamesHead::getEncodersRaw(double *encs)
{
HeadControl *c=my_cast(controller);
if (c!=0)
c->getEncoders(encs);
return true;
}
bool JamesHead::getEncoderSpeedRaw(int j, double *sp)
{
return true;
}
bool JamesHead::getEncoderSpeedsRaw(double *spds)
{
return true;
}
bool JamesHead::getEncoderAccelerationRaw(int j, double *spds)
{
return true;
}
bool JamesHead::getEncoderAccelerationsRaw(double *accs)
{
return true;
}
bool JamesHead::setPositionMode()
{
return true;
}
bool JamesHead::positionMoveRaw(int j, double ref)
{
HeadControl *c=my_cast(controller);
if (c!=0)
c->positionMove(j, ref);
return true;
}
bool JamesHead::positionMoveRaw(const double *refs)
{
HeadControl *c=my_cast(controller);
if (c!=0)
c->positionMove(refs);
return true;
}
bool JamesHead::relativeMoveRaw(int j, double delta)
{
HeadControl *c=my_cast(controller);
if (c!=0)
c->relativeMove(j, delta);
return true;
}
bool JamesHead::relativeMoveRaw(const double *deltas)
{
HeadControl *c=my_cast(controller);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?