23#include <iCub/utils.h>
71 size_t n=std::min(b.size(),
xd.length());
72 for (
size_t i=0; i<
n; i++)
73 xd[i]=b.get(i).asFloat64();
118 while (!isStopping() && !
closing)
123 double timeDelay=0.0;
124 double theta=
static_cast<Solver*
>(
slv)->neckTargetRotAngle(
xd);
128 Time::delay(timeDelay);
154 eyeTiltLim[0]=-std::numeric_limits<double>::max();
155 eyeTiltLim[1]=std::numeric_limits<double>::max();
346 std::pair<Vector, bool> ret;
353 ret.second =
iGyro->getThreeAxisGyroscopeStatus(0) == MAS_OK;
354 ret.second &=
iGyro->getThreeAxisGyroscopeMeasure(0, gyro, ts);
363 std::pair<Vector, bool> ret;
370 ret.second =
iAccel->getThreeAxisLinearAccelerometerStatus(0) == MAS_OK;
371 ret.second &=
iAccel->getThreeAxisLinearAccelerometerMeasure(0, accel, ts);
386 else if (type==
"right")
404 else if (type==
"right")
416 Matrix **Prj,
int &w,
int &
h,
const bool verbose)
418 ResourceFinder &_rf=
const_cast<ResourceFinder&
>(rf);
421 if (!_rf.isConfigured())
424 string message=_rf.findFile(
"from");
425 if (!message.empty())
427 message+=
": intrinsic parameters for "+type;
428 Bottle &parType=_rf.findGroup(type);
429 if (parType.check(
"w") && parType.check(
"h") &&
430 parType.check(
"fx") && parType.check(
"fy") &&
431 parType.check(
"cx") && parType.check(
"cy"))
433 w=parType.find(
"w").asInt32();
434 h=parType.find(
"h").asInt32();
435 double fx=parType.find(
"fx").asFloat64();
436 double fy=parType.find(
"fy").asFloat64();
437 double cx=parType.find(
"cx").asFloat64();
438 double cy=parType.find(
"cy").asFloat64();
442 yInfo(
"%s found:",message.c_str());
451 *Prj=
new Matrix(eye(3,4));
454 K(0,0)=fx; K(1,1)=fy;
455 K(0,2)=cx; K(1,2)=cy;
462 message=_rf.find(
"from").asString();
463 message+=
": intrinsic parameters for "+type;
467 yWarning(
"%s not found!",message.c_str());
477 ResourceFinder &_rf=
const_cast<ResourceFinder&
>(rf);
478 if ((chain!=
nullptr) && _rf.isConfigured())
480 string message=_rf.findFile(
"from");
481 if (!message.empty())
483 message+=
": aligning matrix for "+type;
484 Bottle &parType=_rf.findGroup(type);
485 if (Bottle *bH=parType.find(
"HN").asList())
490 Matrix HN(4,4); HN=0.0;
491 for (
int cnt=0; (cnt<bH->size()) && (cnt<HN.rows()*HN.cols()); cnt++)
493 HN(i,j)=bH->get(cnt).asFloat64();
502 HN(3,0)=HN(3,1)=HN(3,2)=0.0;
509 yInfo(
"%s found:",message.c_str());
510 yInfo(
"%s",HN.toString(3,3).c_str());
518 message=_rf.find(
"from").asString();
519 message+=
": aligning matrix for "+type;
523 yWarning(
"%s not found!",message.c_str());
535 IControlLimits *lims;
540 if (drvTorso!=
nullptr)
542 drvTorso->view(encs);
543 drvTorso->view(lims);
544 encs->getAxes(&nJointsTorso);
546 for (
int i=0; i<nJointsTorso; i++)
548 if (lims->getLimits(i,&min,&max))
562 yError(
"unable to retrieve limits for torso joint #%d",i);
569 encs->getAxes(&nJointsHead);
570 Matrix lim(nJointsHead,2);
572 for (
int i=0; i<nJointsHead; i++)
574 if (lims->getLimits(i,&min,&max))
589 (*chain)[nJointsTorso+i].setMin(lim(i,0));
590 (*chain)[nJointsTorso+i].setMax(lim(i,1));
594 yError(
"unable to retrieve limits for head joint #%d",i);
604 unsigned int N1=ch1->
getN();
605 unsigned int N2=ch2->
getN();
606 unsigned int N =N1>N2 ? N2 : N1;
608 for (
unsigned int i=0; i<N; i++)
610 (*ch2)[i].setMin((*ch1)[i].getMin());
611 (*ch2)[i].setMax((*ch1)[i].getMax());
619 for (
unsigned int i=0; i<(
unsigned int)fbTorso.length(); i++)
627 for (
int i=0; i<3; i++)
633bool getFeedback(Vector &fbTorso, Vector &fbHead, PolyDriver *drvTorso,
637 IEncodersTimed *encs;
639 int nJointsTorso=(int)fbTorso.length();
640 int nJointsHead=(int)fbHead.length();
642 Vector fb(std::max(nJointsTorso,nJointsHead));
643 Vector stamps(nJointsTorso+nJointsHead,0.0);
646 if (drvTorso!=
nullptr)
648 drvTorso->view(encs);
649 if (encs->getEncodersTimed(fb.data(),stamps.data()))
651 for (
int i=0; i<nJointsTorso; i++)
661 if (encs->getEncodersTimed(fb.data(),stamps.data()+nJointsTorso))
663 for (
int i=0; i<nJointsHead; i++)
670 if (commData!=
nullptr)
674 if (timeStamp!=
nullptr)
675 *timeStamp=findMax(stamps);
double saccadesActivationAngle
IThreeAxisLinearAccelerometers * iAccel
std::pair< Vector, bool > get_gyro()
void set_fpFrame(const Matrix &_S)
void set_xd(const Vector &_xd)
void set_qd(const Vector &_qd)
void set_q(const Vector &_q)
double saccadesInhibitionPeriod
std::pair< Vector, bool > get_accel()
void resize_counterv(const int sz, const double val)
double minAllowedVergence
IThreeAxisGyroscopes * iGyro
void resize_v(const int sz, const double val)
void set_v(const Vector &_v)
iKinLimbVersion head_version
void set_x(const Vector &_x)
void set_counterv(const Vector &_counterv)
void set_torso(const Vector &_torso)
virtual bool getExtrinsicsMatrix(const string &type, Matrix &M)
virtual bool setExtrinsicsMatrix(const string &type, const Matrix &M)
A Base class for defining a Serial Link Chain.
yarp::sig::Matrix getHN() const
Returns HN, the rigid roto-translation matrix from the Nth frame to the end-effector.
bool setHN(const yarp::sig::Matrix &_HN)
Sets HN, the rigid roto-translation matrix from the Nth frame to the end-effector.
bool setBlockingValue(const unsigned int i, double Ang)
Changes the value of the ith blocked Link.
unsigned int getN() const
Returns the number of Links belonging to the Chain.
A class for defining the versions of the iCub limbs.
iKinChain * asChain()
Returns a pointer to the Limb seen as Chain object.
bool set_xd(const Vector &_xd)
void init(const Vector &xd0)
void onRead(Bottle &b) override
condition_variable cv_triggerNeck
constexpr int32_t MUTEX_QD
constexpr int32_t MUTEX_X
bool getFeedback(Vector &fbTorso, Vector &fbHead, PolyDriver *drvTorso, PolyDriver *drvHead, const ExchangeData *commData, double *timeStamp)
void copyJointsBounds(iKinChain *ch1, iKinChain *ch2)
bool getCamParams(const ResourceFinder &rf, const string &type, Matrix **Prj, int &w, int &h, const bool verbose)
constexpr int32_t MUTEX_FPFRAME
constexpr int32_t MUTEX_V
constexpr int32_t MUTEX_TORSO
bool getAlignHN(const ResourceFinder &rf, const string &type, iKinChain *chain, const bool verbose)
constexpr int32_t MUTEX_Q
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)
constexpr int32_t MUTEX_XD
constexpr int32_t MUTEX_COUNTERV
constexpr double CTRL_DEG2RAD
PI/180.
constexpr double SACCADES_ACTIVATION_ANGLE
constexpr double NECKSOLVER_RESTORINGANGLE
constexpr double SACCADES_INHIBITION_PERIOD
constexpr double NECKSOLVER_ACTIVATIONDELAY