11 #include <yarp/math/Math.h>
18 using namespace yarp::os;
19 using namespace yarp::sig;
20 using namespace yarp::math;
26 void CartesianHelper::addVectorOption(Bottle &b,
const int vcb,
const Vector &v)
28 Bottle &part=b.addList();
30 Bottle &vect=part.addList();
32 for (
size_t i=0; i<v.length(); i++)
33 vect.addFloat64(v[i]);
38 bool CartesianHelper::getDesiredOption(
const Bottle &reply, Vector &xdhat,
39 Vector &odhat, Vector &qdhat)
49 Bottle *xData=getEndEffectorPoseOption(reply);
54 for (
size_t i=0; i<xdhat.length(); i++)
55 xdhat[i]=xData->get(i).asFloat64();
58 for (
size_t i=0; i<odhat.length(); i++)
59 odhat[i]=xData->get(xdhat.length()+i).asFloat64();
67 Bottle *qData=getJointsOption(reply);
71 qdhat.resize(qData->size());
72 for (
size_t i=0; i<qdhat.length(); i++)
73 qdhat[i]=qData->get(i).asFloat64();
86 void CartesianHelper::addTargetOption(Bottle &b,
const Vector &xd)
93 void CartesianHelper::addDOFOption(Bottle &b,
const Vector &dof)
100 void CartesianHelper::addJointsResPosOption(Bottle &b,
const Vector &restPos)
107 void CartesianHelper::addJointsRestWeightsOption(Bottle &b,
const Vector &restWeights)
114 void CartesianHelper::addPoseOption(Bottle &b,
const unsigned int pose)
116 Bottle &posePart=b.addList();
127 void CartesianHelper::addModeOption(Bottle &b,
const bool tracking)
129 Bottle &modePart=b.addList();
140 void CartesianHelper::addTokenOption(Bottle &b,
const double token)
142 Bottle &tokenPart=b.addList();
144 tokenPart.addFloat64(token);
149 Bottle *CartesianHelper::getTargetOption(
const Bottle &b)
156 Bottle *CartesianHelper::getEndEffectorPoseOption(
const Bottle &b)
163 Bottle *CartesianHelper::getJointsOption(
const Bottle &b)
170 bool CartesianHelper::getTokenOption(
const Bottle &b,
double *token)
183 bool CartesianHelper::computeFixationPointData(
iKinChain &eyeL,
187 Matrix HL=eyeL.
getH();
188 Matrix HR=eyeR.
getH();
191 double qty1=
dot(HR,2,HL,2);
193 Matrix H2L=HL-qty1*HR;
194 Matrix H2R=qty1*HL-HR;
195 double qty2L=
dot(H2L,2,H1,3);
196 double qty2R=
dot(H2R,2,H1,3);
197 double qty3=qty1*qty1-1.0;
202 double tL=qty2L/qty3;
203 double tR=qty2R/qty3;
208 for (
int i=0; i<3; i++)
209 fp[i]=0.5*(HL(i,3)+tL*HL(i,2)+HR(i,3)+tR*HR(i,2));
216 bool CartesianHelper::computeFixationPointData(
iKinChain &eyeL,
218 Vector &
fp, Matrix &J)
220 Vector dfp1(4), dfp2(4);
221 Vector dfpL1(4),dfpL2(4);
222 Vector dfpR1(4),dfpR2(4);
224 Matrix HL=eyeL.
getH();
225 Matrix HR=eyeR.
getH();
228 double qty1=
dot(HR,2,HL,2);
230 Matrix H2L=HL-qty1*HR;
231 Matrix H2R=qty1*HL-HR;
232 Matrix H3(4,4); H3(3,2)=0.0;
233 double qty2L=
dot(H2L,2,H1,3);
234 double qty2R=
dot(H2R,2,H1,3);
235 double qty3=qty1*qty1-1.0;
240 double tL=qty2L/qty3;
241 double tR=qty2R/qty3;
250 double dqty1, dqty1L, dqty1R;
251 double dqty2, dqty2L, dqty2R;
254 Vector Hz=HL.getCol(2);
255 Matrix M=GeoJacobP_L.submatrix(0,3,0,1)+tL*AnaJacobZ_L.submatrix(0,3,0,1);
259 dqty1=
dot(AnaJacobZ_R,j,HL,2)+
dot(HR,2,AnaJacobZ_L,j);
260 for (
int i=0; i<3; i++)
261 H3(i,2)=AnaJacobZ_L(i,j)-dqty1*HR(i,2)-qty1*AnaJacobZ_R(i,j);
262 dqty2=
dot(H3,2,H1,3)+
dot(H2L,2,GeoJacobP_L-GeoJacobP_R,j);
263 dfp1=M.getCol(j)+Hz*((dqty2-2.0*qty1*qty2L*dqty1/qty3)/qty3);
267 dqty1L=
dot(HR,2,AnaJacobZ_L,j);
268 for (
int i=0; i<3; i++)
269 H3(i,2)=AnaJacobZ_L(i,j)-dqty1*HR(i,2);
270 dqty2L=
dot(H3,2,H1,3)+
dot(H2L,2,GeoJacobP_L,j);
271 dfpL1=M.getCol(j)+Hz*((dqty2L-2.0*qty1*qty2L*dqty1L/qty3)/qty3);
274 dqty1R=
dot(AnaJacobZ_R,j,HL,2);
275 for (
int i=0; i<3; i++)
276 H3(i,2)=-dqty1*HR(i,2)-qty1*AnaJacobZ_R(i,j);
277 dqty2R=
dot(H3,2,H1,3)+
dot(H2L,2,-1.0*GeoJacobP_R,j);
278 dfpR1=Hz*((dqty2R-2.0*qty1*qty2L*dqty1R/qty3)/qty3);
283 double dqty1, dqty1L, dqty1R;
284 double dqty2, dqty2L, dqty2R;
287 Vector Hz=HR.getCol(2);
288 Matrix M=GeoJacobP_R.submatrix(0,3,0,1)+tR*AnaJacobZ_R.submatrix(0,3,0,1);
292 dqty1=
dot(AnaJacobZ_R,j,HL,2)+
dot(HR,2,AnaJacobZ_L,j);
293 for (
int i=0; i<3; i++)
294 H3(i,2)=qty1*AnaJacobZ_L(i,j)+dqty1*HL(i,2)-AnaJacobZ_R(i,j);
295 dqty2=
dot(H3,2,H1,3)+
dot(H2R,2,GeoJacobP_L-GeoJacobP_R,j);
296 dfp2=M.getCol(j)+Hz*((dqty2-2.0*qty1*qty2R*dqty1/qty3)/qty3);
300 dqty1L=
dot(HR,2,AnaJacobZ_L,j);
301 for (
int i=0; i<3; i++)
302 H3(i,2)=qty1*AnaJacobZ_L(i,j)+dqty1L*HL(i,2);
303 dqty2L=
dot(H3,2,H1,3)+
dot(H2R,2,GeoJacobP_L,j);
304 dfpL2=Hz*((dqty2L-2.0*qty1*qty2R*dqty1L/qty3)/qty3);
307 dqty1R=
dot(AnaJacobZ_R,j,HL,2);
308 for (
int i=0; i<3; i++)
309 H3(i,2)=dqty1R*HL(i,2)-AnaJacobZ_R(i,j);
310 dqty2R=
dot(H3,2,H1,3)+
dot(H2R,2,-1.0*GeoJacobP_R,j);
311 dfpR2=M.getCol(j)+Hz*((dqty2R-2.0*qty1*qty2R*dqty1R/qty3)/qty3);
317 if ((J.rows()!=3) || (J.cols()!=3))
320 for (
int i=0; i<3; i++)
323 fp[i]=0.5*(HL(i,3)+tL*HL(i,2)+HR(i,3)+tR*HR(i,2));
329 J(i,0)=0.50*(dfp1[i] + dfp2[i]);
330 J(i,1)=0.50*(dfpL1[i]+dfpR1[i] + dfpL2[i]+dfpR2[i]);
331 J(i,2)=0.25*(dfpL1[i]-dfpR1[i] + dfpL2[i]-dfpR2[i]);
A Base class for defining a Serial Link Chain.
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...
yarp::sig::Matrix GeoJacobian(const unsigned int i)
Returns the geometric Jacobian of the ith link.
yarp::sig::Matrix AnaJacobian(const unsigned int i, unsigned int col)
Returns the analitical Jacobian of the ith link.
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).
#define IKINCTRL_POSE_FULL
#define IKINCTRL_POSE_XYZ
#define IKINSLV_VOCAB_OPT_DOF
#define IKINSLV_VOCAB_VAL_POSE_FULL
#define IKINSLV_VOCAB_VAL_MODE_TRACK
#define IKINSLV_VOCAB_VAL_MODE_SINGLE
#define IKINSLV_VOCAB_OPT_POSE
#define IKINSLV_VOCAB_OPT_Q
#define IKINSLV_VOCAB_OPT_MODE
#define IKINSLV_VOCAB_REP_ACK
#define IKINSLV_VOCAB_OPT_TOKEN
#define IKINSLV_VOCAB_OPT_REST_POS
#define IKINSLV_VOCAB_VAL_POSE_XYZ
#define IKINSLV_VOCAB_OPT_REST_WEIGHTS
#define IKINSLV_VOCAB_OPT_X
#define IKINSLV_VOCAB_OPT_XD
static struct bpf_program fp