22#include <yarp/math/SVD.h>
29 const Vector &_counterRotGain,
const unsigned int _period) :
30 PeriodicThread((double)_period/1000.0),
drvTorso(_drvTorso),
drvHead(_drvHead),
41 imu->setAllConstraints(
false);
44 eyeL->blockLink(3,0.0);
eyeR->blockLink(3,0.0);
45 eyeL->blockLink(4,0.0);
eyeR->blockLink(4,0.0);
46 eyeL->blockLink(5,0.0);
eyeR->blockLink(5,0.0);
76 IEncoders *encTorso;
drvTorso->view(encTorso);
82 IEncoders *encHead;
drvHead->view(encHead);
91 lim=
lim.submatrix(3,5,0,1);
138 lock_guard<mutex> lck(
mtx);
148 lock_guard<mutex> lck(
mtx);
164 lim(2,0)=
lim(2,1)=ver_rad;
172 yInfo(
"eyes constrained at vergence %g deg",
commData->eyesBoundVer);
184 lock_guard<mutex> lck(
mtx);
201 yInfo(
"eyes cleared");
220 lock_guard<mutex> lck(
mtx);
228 lock_guard<mutex> lck(
mtx);
230 for (
size_t i=0; i<len; i++)
232 yInfo(
"counter-rotation gains set to (%s)",
counterRotGain.toString(3,3).c_str());
246 Vector gyro{
commData->get_gyro().first};
260 HN.setSubcol(fph,0,3);
264 ocr_fprelv=ocr_fprelv.subVector(0,2);
275 yInfo(
"Starting Pseudoinverse Reference Generator at %d ms",
period);
294 yInfo(
"Pseudoinverse Reference Generator started successfully");
296 yError(
"Pseudoinverse Reference Generator did not start!");
305 lock_guard<mutex> lck(
mtx);
315 Vector xd=
commData->port_xd->get_xd();
326 Vector fph=xd; fph.push_back(1.0);
327 fph=SE3inv(
chainNeck->getH())*fph; fph[3]=0.0;
332 ang[0]=-atan2(fph[1],fabs(fph[2]));
333 ang[1]=atan2(fph[0],fph[2]);
340 if (rot>
commData->saccadesActivationAngle)
347 axis[0]=1.0; axis[1]=0.0; axis[2]=0.0; axis[3]=-ang[0];
348 fph=axis2dcm(axis)*fph;
383 ctrl->doSaccade(ang,vel);
411 ctrl->resetCtrlEyes();
446 PeriodicThread::suspend();
447 yInfo(
"Pseudoinverse Reference Generator has been suspended!");
454 PeriodicThread::resume();
455 yInfo(
"Pseudoinverse Reference Generator has been resumed!");
462 const unsigned int _period) :
463 PeriodicThread((double)_period/1000.0),
drvTorso(_drvTorso),
drvHead(_drvHead),
475 imu->setAllConstraints(
false);
478 eyeL->blockLink(3,0.0);
eyeR->blockLink(3,0.0);
479 eyeL->blockLink(4,0.0);
eyeR->blockLink(4,0.0);
480 eyeL->blockLink(5,0.0);
eyeR->blockLink(5,0.0);
503 IEncoders *encTorso;
drvTorso->view(encTorso);
509 IEncoders *encHead;
drvHead->view(encHead);
571 lock_guard<mutex> lck(
mtx);
575 (*chainNeck)(0).setMin(min_rad);
576 (*chainNeck)(0).setMax(max_rad);
578 yInfo(
"neck pitch constrained in [%g,%g] deg",min_deg,max_deg);
585 lock_guard<mutex> lck(
mtx);
589 (*chainNeck)(1).setMin(min_rad);
590 (*chainNeck)(1).setMax(max_rad);
592 yInfo(
"neck roll constrained in [%g,%g] deg",min_deg,max_deg);
599 lock_guard<mutex> lck(
mtx);
603 (*chainNeck)(2).setMin(min_rad);
604 (*chainNeck)(2).setMax(max_rad);
606 yInfo(
"neck yaw constrained in [%g,%g] deg",min_deg,max_deg);
613 lock_guard<mutex> lck(
mtx);
622 lock_guard<mutex> lck(
mtx);
631 lock_guard<mutex> lck(
mtx);
640 lock_guard<mutex> lck(
mtx);
644 yInfo(
"neck pitch cleared");
651 lock_guard<mutex> lck(
mtx);
655 yInfo(
"neck roll cleared");
662 lock_guard<mutex> lck(
mtx);
666 yInfo(
"neck yaw cleared");
700 Vector xdh=xd; xdh.push_back(1.0);
701 xdh=SE3inv(
H)*xdh; xdh[3]=0.0;
711 Vector
z(3,0.0);
z[2]=1.0;
712 Vector xdh=xd; xdh.push_back(1.0);
715 Vector xdh3=xdh; xdh3.pop_back();
723 rot=
H*(axis2dcm(rot)*xdh);
751 yInfo(
"Starting Solver at %d ms",
period);
767 yInfo(
"Solver started successfully");
769 yError(
"Solver did not start!");
776 typedef enum { ctrl_off, ctrl_wait, ctrl_on } cstate;
777 static cstate state_=ctrl_off;
779 lock_guard<mutex> lck(
mtx);
782 Vector xd=
commData->port_xd->get_xdDelayed();
809 doSolve&=!(
commData->ctrlActive && !torsoChanged);
815 doSolve|=
commData->trackingModeOn && torsoChanged;
818 doSolve|=
commData->port_xd->get_newDelayed();
824 commData->port_xd->get_newDelayed()=
false;
829 Vector gDir(3,0.0); gDir[2]=-1.0;
834 gDir=
H.submatrix(0,2,0,2)*
acc;
849 if (state_==ctrl_off)
858 else if (state_==ctrl_wait)
863 else if (state_==ctrl_on)
875 PeriodicThread::suspend();
876 yInfo(
"Solver has been suspended!");
883 lock_guard<mutex> lck(
mtx);
902 PeriodicThread::resume();
903 yInfo(
"Solver has been resumed!");
void minAllowedVergenceChanged() override
EyePinvRefGen(PolyDriver *_drvTorso, PolyDriver *_drvHead, ExchangeData *_commData, Controller *_ctrl, const Vector &_counterRotGain, const unsigned int _period)
Vector getCounterRotGain()
void afterStart(bool s) override
void manageBindEyes(const double ver)
bool bindEyes(const double ver)
void threadRelease() override
bool threadInit() override
Vector getEyesCounterVelocity(const Matrix &eyesJ, const Vector &fp)
void setCounterRotGain(const Vector &gain)
Solver(PolyDriver *_drvTorso, PolyDriver *_drvHead, ExchangeData *_commData, EyePinvRefGen *_eyesRefGen, Localizer *_loc, Controller *_ctrl, const unsigned int _period)
void threadRelease() override
void bindNeckPitch(const double min_deg, const double max_deg)
void getCurNeckYawRange(double &min_deg, double &max_deg)
bool threadInit() override
void getCurNeckPitchRange(double &min_deg, double &max_deg)
EyePinvRefGen * eyesRefGen
Vector computeTargetUserTolerance(const Vector &xd)
double getNeckAngleUserTolerance() const
double neckTargetRotAngle(const Vector &xd)
void bindNeckYaw(const double min_deg, const double max_deg)
double neckAngleUserTolerance
void setNeckAngleUserTolerance(const double angle)
void getCurNeckRollRange(double &min_deg, double &max_deg)
void afterStart(bool s) override
AWLinEstimator * torsoVel
void bindNeckRoll(const double min_deg, const double max_deg)
Adaptive window linear fitting to estimate the first derivative.
Basic element for adaptive polynomial fitting.
A class for defining a saturated integrator based on Tustin formula: .
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.
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)
void updateNeckBlockedJoints(iKinChain *chain, const Vector &fbNeck)
void updateTorsoBlockedJoints(iKinChain *chain, const Vector &fbTorso)
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
constexpr double NECKSOLVER_ACTIVATIONANGLE_JOINTS
constexpr double SACCADES_VEL
constexpr double EYEPINVREFGEN_GAIN
constexpr double NECKSOLVER_ACTIVATIONANGLE