22#include <yarp/math/SVD.h>
29 PeriodicThread((double)_period/1000.0), commData(_commData),
58 Vector q(eyeC.
getDOF(),0.0);
84 invPrjL=
new Matrix(pinv(
PrjL->transposed()).transposed());
105 invPrjR=
new Matrix(pinv(
PrjR->transposed()).transposed());
110 Vector Kp(1,0.001), Ki(1,0.001), Kd(1,0.0);
111 Vector Wp(1,1.0), Wi(1,1.0), Wd(1,1.0);
112 Vector N(1,10.0), Tt(1,1.0);
155 yInfo(
"Starting Localizer at %d ms",
period);
178 yInfo(
"Localizer started successfully");
180 yError(
"Localizer did not start!");
187 lock_guard<mutex> lck(
mtx);
189 Bottle &bDominantEye=options.addList();
190 bDominantEye.addString(
"dominantEye");
198 lock_guard<mutex> lck(
mtx);
200 if (options.check(
"dominantEye"))
202 string domEye=options.find(
"dominantEye").asString();
203 if ((domEye==
"left") || (domEye==
"right"))
220 ang[0]=atan2(fph[0],fph[2]);
221 ang[1]=-atan2(fph[1],fabs(fph[2]));
231 lock_guard<mutex> lck(
mtx);
275 Matrix R=axis2dcm(
y)*axis2dcm(
x);
281 fph=SE3inv(frame)*
fp;
298 lock_guard<mutex> lck(
mtx);
301 yError(
"Not enough values given for the point!");
305 bool isLeft=(type==
"left");
323 q[7]=head[4]+head[5]/(isLeft?2.0:-2.0);
331 xo=xo.subVector(0,3);
336 Vector xe=SE3inv(eye->
getH(q))*xo;
346 yError(
"Unspecified projection matrix for %s camera!",type.c_str());
354 const double z, Vector &
x)
356 lock_guard<mutex> lck(
mtx);
357 bool isLeft=(type==
"left");
375 q[7]=head[4]+head[5]/(isLeft?2.0:-2.0);
394 yError(
"Unspecified projection matrix for %s camera!",type.c_str());
402 const Vector &plane, Vector &
x)
404 if (plane.length()<4)
406 yError(
"Not enough values given for the projection plane!");
410 bool isLeft=(type==
"left");
415 lock_guard<mutex> lck(
mtx);
420 p0[0]=-plane[3]/plane[0];
421 else if (plane[1]!=0.0)
422 p0[1]=-plane[3]/plane[1];
423 else if (plane[2]!=0.0)
424 p0[2]=-plane[3]/plane[2];
427 yError(
"Error while specifying projection plane!");
452 lock_guard<mutex> lck(
mtx);
453 if ((pxl.length()<2) || (pxr.length()<2))
455 yError(
"Not enough values given for the pixels!");
472 qL[7]=head[4]+head[5]/2.0;
480 Matrix tmp=
zeros(3,4); tmp(2,2)=1.0;
481 tmp(0,2)=pxl[0]; tmp(1,2)=pxl[1];
482 Matrix AL=(*
PrjL-tmp)*HL;
484 tmp(0,2)=pxr[0]; tmp(1,2)=pxr[1];
485 Matrix AR=(*
PrjR-tmp)*HR;
489 for (
int i=0; i<2; i++)
494 for (
int j=0; j<3; j++)
508 yError(
"Unspecified projection matrix for at least one camera!");
529 string type=mono->get(0).asString();
530 double u=mono->get(1).asFloat64();
531 double v=mono->get(2).asFloat64();
535 if (mono->get(3).isFloat64())
537 z=mono->get(3).asFloat64();
540 else if ((mono->get(3).asString()==
"ver") && (mono->size()>=5))
542 double ver=mono->get(4).asFloat64();
556 yError(
"Got wrong monocular information!");
566 if ((
PrjL!=
nullptr) || (
PrjR!=
nullptr))
568 if (stereo->size()>=4)
570 double ul=stereo->get(0).asFloat64();
571 double vl=stereo->get(1).asFloat64();
572 double ur=stereo->get(2).asFloat64();
573 double vr=stereo->get(3).asFloat64();
575 Vector ref(1), fb(1),
fp;
602 yError(
"Got wrong stereo information!");
605 yError(
"Unspecified projection matrix!");
615 if (angles->size()>=4)
619 string type=angles->get(0).asString();
628 yError(
"Got wrong angles information!");
665 else if (type==
"right")
684 const int w,
const int h)
691 *
invPrjL=pinv(M.transposed()).transposed();
696 invPrjL=
new Matrix(pinv(M.transposed()).transposed());
704 else if (type==
"right")
709 *
invPrjR=pinv(M.transposed()).transposed();
714 invPrjR=
new Matrix(pinv(M.transposed()).transposed());
ResourceFinder rf_cameras
double minAllowedVergence
iKinLimbVersion head_version
void getPidOptions(Bottle &options)
bool setIntrinsicsMatrix(const string &type, const Matrix &M, const int w, const int h)
BufferedPort< Bottle > port_stereo
BufferedPort< Bottle > port_mono
double getDistFromVergence(const double ver)
void handleMonocularInput()
Vector get3DPoint(const string &type, const Vector &ang)
void setPidOptions(const Bottle &options)
BufferedPort< Bottle > port_anglesIn
BufferedPort< Vector > port_anglesOut
void handleAnglesOutput()
bool getIntrinsicsMatrix(const string &type, Matrix &M, int &w, int &h)
Localizer(ExchangeData *_commData, const unsigned int _period)
bool triangulatePoint(const Vector &pxl, const Vector &pxr, Vector &x)
bool projectPoint(const string &type, const Vector &x, Vector &px)
Vector getAbsAngles(const Vector &x)
General structure of parallel (non-interactive) PID.
virtual void getOptions(yarp::os::Bottle &options)
Returns the current options used by the pid.
virtual void setOptions(const yarp::os::Bottle &options)
Update the options used by the pid.
virtual void reset(const yarp::sig::Vector &u0)
Resets the internal state of integral and derivative part.
virtual const yarp::sig::Vector & compute(const yarp::sig::Vector &ref, const yarp::sig::Vector &fb)
Computes the PID output.
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...
yarp::sig::Matrix getH(const unsigned int i, const bool allLink=false)
Returns the rigid roto-translation matrix from the root reference frame to the ith frame in Denavit-H...
bool releaseLink(const unsigned int i)
Releases the ith Link.
yarp::sig::Vector EndEffPose(const bool axisRep=true)
Returns the coordinates of end-effector.
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.
void setAllConstraints(bool _constrained)
Sets the constraint status of all chain links.
std::string get_version() const
Return the version string.
iKinChain * asChain()
Returns a pointer to the Limb seen as Chain object.
bool set_xd(const Vector &_xd)
double dot(const yarp::sig::Matrix &A, int colA, const yarp::sig::Matrix &B, int colB)
Returns the dot product between two vectors given in the form: matrix(:,col).
double norm(const yarp::sig::Matrix &M, int col)
Returns the norm of the vector given in the form: matrix(:,col).
bool getAlignHN(const ResourceFinder &rf, const string &type, iKinChain *chain, const bool verbose=false)
bool getCamParams(const ResourceFinder &rf, const string &type, Matrix **Prj, int &w, int &h, const bool verbose=false)
constexpr double CTRL_RAD2DEG
180/PI.
constexpr double CTRL_DEG2RAD
PI/180.
static struct bpf_program fp