29 const double _neckTime,
const double _eyesTime,
const double _min_abs_vel,
30 const unsigned int _period) :
31 PeriodicThread((double)_period/1000.0),
drvTorso(_drvTorso),
drvHead(_drvHead),
43 imu->setAllConstraints(
false);
46 neck->releaseLink(0);
eyeL->releaseLink(0);
eyeR->releaseLink(0);
47 neck->releaseLink(1);
eyeL->releaseLink(1);
eyeR->releaseLink(1);
48 neck->releaseLink(2);
eyeL->releaseLink(2);
eyeR->releaseLink(2);
69 IEncoders *encTorso;
drvTorso->view(encTorso);
75 IEncoders *encHead;
drvHead->view(encHead);
86 yInfo(
"### neck control - requested POSITION mode: IPositionDirect [%s] => %s mode selected",
87 commData->neckPosCtrlOn?
"available":
"not available",
commData->neckPosCtrlOn?
"POSITION":
"VELOCITY");
90 yInfo(
"### neck control - requested VELOCITY mode => VELOCITY mode selected");
101 Vector a_robHead(
nJointsHead,std::numeric_limits<double>::max());
102 velHead->setRefAccelerations(a_robHead.data());
176 cl.setAng(
zeros(cl.getDOF()));
181 for (
double ver=minVer; ver<maxVer; ver+=0.5*
CTRL_DEG2RAD)
183 cl(cl.getDOF()-1).setAng(ver/2.0);
195 Vector fpe=SE3inv(cl.getH())*
fp;
204 yInfo(
"### computed minimum allowed vergence = %g [deg]",minVer*
CTRL_RAD2DEG);
205 commData->minAllowedVergence=minVer;
228 ev.addFloat64(checkPoint);
269 if (execStopPosition)
286 if (execStopPosition)
291 ss<<
"pos_"<<neckJoint;
292 info.addString(ss.str());
293 info.addString(
"stop");
304 info.addString(ss.str());
305 info.addFloat64(0.0);
344 Vector &
v,
double printTime)
350 printf(
"norm(e) = %g\n",
norm(xd-
fp));
351 printf(
"Target fix. point = %s\n",xd.toString().c_str());
352 printf(
"Actual fix. point = %s\n",
fp.toString().c_str());
353 printf(
"Target Joints = %s\n",
qd.toString().c_str());
354 printf(
"Actual Joints = %s\n",q.toString().c_str());
355 printf(
"Velocity = %s\n",
v.toString().c_str());
371 yInfo(
"Starting Controller at %d ms",
period);
405 yInfo(
"Controller started successfully");
407 yError(
"Controller did not start!");
413 const Vector &w,
const Vector &x_FP)
419 H_(0,3)=x_FP[0]-H_(0,3);
420 H_(1,3)=x_FP[1]-H_(1,3);
421 H_(2,3)=x_FP[2]-H_(2,3);
422 Vector dx_FP_pos=
v+(w_[0]*
cross(H_,0,H_,3)+
423 w_[1]*
cross(H_,1,H_,3)+
424 w_[2]*
cross(H_,2,H_,3));
426 H_(0,3)=H_(1,3)=H_(2,3)=0.0;
427 Vector dx_FP_rot=H_*w_;
428 dx_FP_rot.pop_back();
430 return cat(dx_FP_pos,dx_FP_rot);
440 Vector fpE=SE3inv(
chainNeck->getH())*fpR;
457 Matrix JNp=JN.submatrix(3,5,3,5);
459 return pinv(JNp)*dfp.subVector(3,5);
466 Matrix eyesJ; Vector tmp;
469 return pinv(eyesJ)*dfp.subVector(0,2);
496 for (
size_t i=0; i<ang_.length(); i++)
500 info.addString(ss.str());
501 info.addFloat64(ang_[i]);
550 modHead->getControlModes(modes.data());
553 for (
int i=0; i<(int)modes.size(); i++)
555 if ((modes[i]==VOCAB_CM_HW_FAULT) || (modes[i]==VOCAB_CM_IDLE))
561 if (modes[i]!=VOCAB_CM_POSITION_DIRECT)
564 else if (modes[i]!=VOCAB_CM_VELOCITY)
567 else if (modes[i]!=VOCAB_CM_MIXED)
587 modes.push_back(VOCAB_CM_POSITION_DIRECT);
589 modes.push_back(VOCAB_CM_VELOCITY);
592 modes.push_back(VOCAB_CM_MIXED);
682 yError(
"Communication timeout detected!");
697 for (
int i=0; i<3; i++)
719 double errEyes=
norm(
qd.subVector(3,(
unsigned int)
qd.length()-1)-
fbEyes);
733 event=
"motion-onset";
760 else if (jointsHealthy)
791 event=
"motion-onset";
800 if (event==
"motion-onset")
842 Vector gyro{resGyro.first};
843 bool statusGyro = resGyro.second;
870 Vector gyro{resGyro.first};
871 bool statusGyro = resGyro.second;
892 for (
size_t i=0; i<
v.length(); i++)
925 for (
size_t i=0; i<posdeg.length(); i++)
929 info.addString(ss.str());
930 info.addFloat64(posdeg[i]);
936 for (
size_t i=j; i<
vdeg.length(); i++)
940 info.addString(ss.str());
941 info.addFloat64(
vdeg[i]);
962 for (; (size_t)j<q.length(); j++)
966 if (
port_x.getOutputCount()>0)
974 if (
port_q.getOutputCount()>0)
981 if (event==
"motion-onset")
986 if (event==
"motion-done")
1004 PeriodicThread::suspend();
1007 yInfo(
"Controller has been suspended!");
1019 PeriodicThread::resume();
1020 yInfo(
"Controller has been resumed!");
1042 double lowerThresNeck=
eyesTime+0.2;
1043 if (execTime<lowerThresNeck)
1045 yWarning(
"neck execution time is under the lower bound!");
1046 yWarning(
"a new neck execution time of %g s is chosen",lowerThresNeck);
1057 double lowerThresEyes=10.0*
Ts;
1058 if (execTime<lowerThresEyes)
1060 yWarning(
"eyes execution time is under the lower bound!");
1061 yWarning(
"a new eyes execution time of %g s is chosen",lowerThresEyes);
1090 yInfo(
"tracking mode set to %s",
1091 commData->trackingModeOn?
"on":
"off");
1125 if (poseSel==
"left")
1131 else if (poseSel==
"right")
1137 else if (poseSel==
"head")
1152 if ((checkPoint>=0.0) && (checkPoint<=1.0))
1168 if ((checkPoint>=0.0) && (checkPoint<=1.0))
1189 events.addFloat64(motionOngoingEvent);
bool unregisterMotionOngoingEvent(const double checkPoint)
void stopLimb(const bool execStopPosition=true)
bool setGazeStabilization(const bool f)
BufferedPort< Bottle > port_event
bool getPose(const string &poseSel, Vector &x, Stamp &stamp)
void afterStart(bool s) override
void threadRelease() override
Vector computedxFP(const Matrix &H, const Vector &v, const Vector &w, const Vector &x_FP)
void printIter(Vector &xd, Vector &fp, Vector &qd, Vector &q, Vector &v, double printTime)
minJerkVelCtrl * mjCtrlNeck
Vector computeEyesVelFromdxFP(const Vector &dfp)
void setTeyes(const double execTime)
bool areJointsHealthyAndSet()
void motionOngoingEventsFlush()
vector< int > jointsToSet
multiset< double > motionOngoingEvents
bool look(const Vector &x)
void notifyEvent(const string &event, const double checkPoint=-1.0)
minJerkVelCtrl * mjCtrlEyes
void minAllowedVergenceChanged() override
void setTneck(const double execTime)
bool getVelocity(Vector &vel)
void doSaccade(const Vector &ang, const Vector &vel)
bool threadInit() override
bool getDesired(Vector &des)
void findMinimumAllowedVergence()
IPositionControl * posHead
void setTrackingMode(const bool f)
bool getGazeStabilization() const
double ctrlActiveRisingEdgeTime
void motionOngoingEventsHandling()
BufferedPort< Vector > port_q
Integrator * IntStabilizer
IPositionDirect * posNeck
IVelocityControl * velHead
Controller(PolyDriver *_drvTorso, PolyDriver *_drvHead, ExchangeData *_commData, const double _neckTime, const double _eyesTime, const double _min_abs_vel, const unsigned int _period)
BufferedPort< Bottle > port_debug
BufferedPort< Vector > port_x
multiset< double > motionOngoingEventsCurrent
Vector computeNeckVelFromdxFP(const Vector &fp, const Vector &dfp)
bool getTrackingMode() const
condition_variable cv_eventLook
Bottle listMotionOngoingEvents()
bool registerMotionOngoingEvent(const double checkPoint)
A class for defining a saturated integrator based on Tustin formula: .
Implements a minimum-jerk controller with velocity commands in the assumption that the plant can be m...
static bool computeFixationPointData(iKinChain &eyeL, iKinChain &eyeR, yarp::sig::Vector &fp)
Retrieves current fixation point given the current kinematics configuration of the eyes.
A class for defining the iCub Eye.
A class for describing the kinematic of the straight line coming out from the point located between t...
A class for defining the Inertia Sensor Kinematics of the iCub.
A Base class for defining a Serial Link Chain.
yarp::sig::Vector setAng(const yarp::sig::Vector &q)
Sets the free joint angles to values of q[i].
unsigned int getDOF() const
Returns the current number of Chain's DOF.
constexpr double GAZECTRL_MOTIONDONE_EYES_QTHRES
constexpr int32_t GAZECTRL_SWOFFCOND_DISABLESLOT
constexpr double GAZECTRL_CRITICVER_STABILIZATION
constexpr double GAZECTRL_MOTIONDONE_NECK_QTHRES
double norm(const yarp::sig::Matrix &M, int col)
Returns the norm of the vector given in the form: matrix(:,col).
yarp::sig::Vector cross(const yarp::sig::Matrix &A, int colA, const yarp::sig::Matrix &B, int colB)
Returns the cross product between two vectors given in the form: matrix(:,col).
void copyJointsBounds(iKinChain *ch1, iKinChain *ch2)
bool getAlignHN(const ResourceFinder &rf, const string &type, iKinChain *chain, const bool verbose=false)
bool getFeedback(Vector &fbTorso, Vector &fbHead, PolyDriver *drvTorso, PolyDriver *drvHead, const ExchangeData *commData, double *timeStamp=nullptr)
Matrix alignJointsBounds(iKinChain *chain, PolyDriver *drvTorso, PolyDriver *drvHead, const ExchangeData *commData)
double sat(const double val, const double min, const double max)
constexpr double CTRL_RAD2DEG
180/PI.
constexpr double CTRL_DEG2RAD
PI/180.
static struct bpf_program fp