32 double b_mass, c_mass;
33 fVec3 b_com(0,0,0), c_com(0,0,0);
35 c_mass = child->com_jacobian(J, c_com, charname);
37 int is_target =
false;
45 if(my_chname && !strcmp(my_chname, charname))
53 static fVec3 abs_com_pos, my_com;
54 abs_com_pos.
mul(abs_att, loc_com);
55 abs_com_pos += abs_pos;
57 my_com.
mul(abs_com_pos, mass);
67 ms = c_com - (c_mass * abs_pos);
70 msXatt.
mul(msX, abs_att);
75 msXaxis.
mul(msXatt, axis);
76 J(0, i_dof) = msXaxis(0);
77 J(1, i_dof) = msXaxis(1);
78 J(2, i_dof) = msXaxis(2);
82 msXaxis.
mul(abs_att, axis);
84 J(0, i_dof) = msXaxis(0);
85 J(1, i_dof) = msXaxis(1);
86 J(2, i_dof) = msXaxis(2);
91 J(0, i_dof+i) = msXatt(0, i);
92 J(1, i_dof+i) = msXatt(1, i);
93 J(2, i_dof+i) = msXatt(2, i);
99 J(0, i_dof+i) = c_mass * abs_att(0, i);
100 J(1, i_dof+i) = c_mass * abs_att(1, i);
101 J(2, i_dof+i) = c_mass * abs_att(2, i);
102 J(0, i_dof+3+i) = msXatt(0, i);
103 J(1, i_dof+3+i) = msXatt(1, i);
104 J(2, i_dof+3+i) = msXatt(2, i);
114 b_mass = brother->com_jacobian(J, b_com, charname);
115 com.
add(c_com, b_com);
116 return c_mass + b_mass;
121 J.
resize(6, chain->n_dof);
123 calc_jacobian(J,
this);
132 if(t_given) calc_jacobian_rotate(J, target);
135 if(t_given) calc_jacobian_slide(J, target);
138 if(t_given) calc_jacobian_sphere(J, target);
141 if(t_given) calc_jacobian_free(J, target);
146 parent->calc_jacobian(J, target);
152 static fVec3 axis0, pp, lin;
153 axis0.
mul(abs_att, axis);
155 lin.
cross(axis0, pp);
156 double*
a = J.
data() + 6*i_dof;
174 double*
a = J.
data() + 6*i_dof;
176 axis0.
mul(abs_att, axis);
194 static fVec3 axis, axis0, pp, lin;
195 double*
a = J.
data() + 6*i_dof;
197 for(
int i=0;
i<3; a+=6,
i++)
200 axis0.
mul(abs_att, axis);
202 lin.
cross(axis0, pp);
222 double*
a = J.
data() + 6*i_dof;
223 static fVec3 axis, axis0, pp, lin;
226 for(i=0; i<3; a+=6, i++)
229 axis0.
mul(abs_att, axis);
231 lin.
cross(axis0, pp);
263 static fVec save_acc, zero_acc;
264 static fVec3 space_acc;
265 save_acc.
resize(chain->n_dof);
266 zero_acc.
resize(chain->n_dof);
271 space_acc.
set(chain->root->loc_lin_acc);
272 chain->GetJointAcc(save_acc);
274 chain->root->loc_lin_acc.zero();
275 chain->SetJointAcc(zero_acc);
277 chain->CalcAcceleration();
279 jdot(0) = loc_lin_acc(0);
280 jdot(1) = loc_lin_acc(1);
281 jdot(2) = loc_lin_acc(2);
282 jdot(3) = loc_ang_acc(0);
283 jdot(4) = loc_ang_acc(1);
284 jdot(5) = loc_ang_acc(2);
286 chain->root->loc_lin_acc.set(space_acc);
287 chain->SetJointAcc(save_acc);
288 chain->CalcAcceleration();
299 for(i=0; i<chain->n_dof; i++)
304 calc_jacobian_2(J,
this);
324 else if(j_type ==
JFREE)
328 parent->calc_jacobian_2(J, target);
337 static fVec3 x(1, 0, 0),
y(0, 1, 0), z(0, 0, 1);
340 calc_jacobian_2_rotate_rotate(J, target, j1, j1->
axis, j1->
i_dof, axis, i_dof);
344 calc_jacobian_2_rotate_slide(J, target, j1, j1->
axis, j1->
i_dof, axis, i_dof);
348 calc_jacobian_2_rotate_rotate(J, target, j1, j1->
axis, j1->
i_dof,
x, i_dof);
349 calc_jacobian_2_rotate_rotate(J, target, j1, j1->
axis, j1->
i_dof,
y, i_dof+1);
350 calc_jacobian_2_rotate_rotate(J, target, j1, j1->
axis, j1->
i_dof, z, i_dof+2);
352 else if(j_type ==
JFREE)
354 calc_jacobian_2_rotate_slide(J, target, j1, j1->
axis, j1->
i_dof,
x, i_dof);
355 calc_jacobian_2_rotate_slide(J, target, j1, j1->
axis, j1->
i_dof,
y, i_dof+1);
356 calc_jacobian_2_rotate_slide(J, target, j1, j1->
axis, j1->
i_dof, z, i_dof+2);
357 calc_jacobian_2_rotate_rotate(J, target, j1, j1->
axis, j1->
i_dof,
x, i_dof+3);
358 calc_jacobian_2_rotate_rotate(J, target, j1, j1->
axis, j1->
i_dof,
y, i_dof+4);
359 calc_jacobian_2_rotate_rotate(J, target, j1, j1->
axis, j1->
i_dof, z, i_dof+5);
361 parent->calc_jacobian_2_rotate_sub(J, target, j1);
368 static fVec3 x(1, 0, 0),
y(0, 1, 0), z(0, 0, 1);
371 calc_jacobian_2_slide_rotate(J, target, j1, j1->
axis, j1->
i_dof, axis, i_dof);
378 calc_jacobian_2_slide_rotate(J, target, j1, j1->
axis, j1->
i_dof,
x, i_dof);
379 calc_jacobian_2_slide_rotate(J, target, j1, j1->
axis, j1->
i_dof,
y, i_dof+1);
380 calc_jacobian_2_slide_rotate(J, target, j1, j1->
axis, j1->
i_dof, z, i_dof+2);
382 else if(j_type ==
JFREE)
384 calc_jacobian_2_slide_rotate(J, target, j1, j1->
axis, j1->
i_dof,
x, i_dof+3);
385 calc_jacobian_2_slide_rotate(J, target, j1, j1->
axis, j1->
i_dof,
y, i_dof+4);
386 calc_jacobian_2_slide_rotate(J, target, j1, j1->
axis, j1->
i_dof, z, i_dof+5);
388 parent->calc_jacobian_2_slide_sub(J, target, j1);
395 static fVec3 x(1, 0, 0),
y(0, 1, 0), z(0, 0, 1);
398 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof, axis, i_dof);
399 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+1, axis, i_dof);
400 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+2, axis, i_dof);
404 calc_jacobian_2_rotate_slide(J, target, j1,
x, j1->
i_dof, axis, i_dof);
405 calc_jacobian_2_rotate_slide(J, target, j1,
y, j1->
i_dof+1, axis, i_dof);
406 calc_jacobian_2_rotate_slide(J, target, j1, z, j1->
i_dof+2, axis, i_dof);
411 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof,
x, i_dof);
412 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+1,
x, i_dof);
413 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+2,
x, i_dof);
415 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof,
y, i_dof+1);
416 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+1,
y, i_dof+1);
417 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+2,
y, i_dof+1);
419 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof, z, i_dof+2);
420 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+1, z, i_dof+2);
421 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+2, z, i_dof+2);
423 else if(j_type ==
JFREE)
426 calc_jacobian_2_rotate_slide(J, target, j1,
x, j1->
i_dof,
x, i_dof);
427 calc_jacobian_2_rotate_slide(J, target, j1,
y, j1->
i_dof+1,
x, i_dof);
428 calc_jacobian_2_rotate_slide(J, target, j1, z, j1->
i_dof+2,
x, i_dof);
430 calc_jacobian_2_rotate_slide(J, target, j1,
x, j1->
i_dof,
y, i_dof+1);
431 calc_jacobian_2_rotate_slide(J, target, j1,
y, j1->
i_dof+1,
y, i_dof+1);
432 calc_jacobian_2_rotate_slide(J, target, j1, z, j1->
i_dof+2,
y, i_dof+1);
434 calc_jacobian_2_rotate_slide(J, target, j1,
x, j1->
i_dof, z, i_dof+2);
435 calc_jacobian_2_rotate_slide(J, target, j1,
y, j1->
i_dof+1, z, i_dof+2);
436 calc_jacobian_2_rotate_slide(J, target, j1, z, j1->
i_dof+2, z, i_dof+2);
438 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof,
x, i_dof+3);
439 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+1,
x, i_dof+3);
440 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+2,
x, i_dof+3);
442 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof,
y, i_dof+4);
443 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+1,
y, i_dof+4);
444 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+2,
y, i_dof+4);
446 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof, z, i_dof+5);
447 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+1, z, i_dof+5);
448 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+2, z, i_dof+5);
450 parent->calc_jacobian_2_sphere_sub(J, target, j1);
457 static fVec3 x(1, 0, 0),
y(0, 1, 0), z(0, 0, 1);
460 calc_jacobian_2_slide_rotate(J, target, j1,
x, j1->
i_dof, axis, i_dof);
461 calc_jacobian_2_slide_rotate(J, target, j1,
y, j1->
i_dof+1, axis, i_dof);
462 calc_jacobian_2_slide_rotate(J, target, j1, z, j1->
i_dof+2, axis, i_dof);
463 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof+3, axis, i_dof);
464 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+4, axis, i_dof);
465 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+5, axis, i_dof);
469 calc_jacobian_2_rotate_slide(J, target, j1,
x, j1->
i_dof+3, axis, i_dof);
470 calc_jacobian_2_rotate_slide(J, target, j1,
y, j1->
i_dof+4, axis, i_dof);
471 calc_jacobian_2_rotate_slide(J, target, j1, z, j1->
i_dof+5, axis, i_dof);
476 calc_jacobian_2_slide_rotate(J, target, j1,
x, j1->
i_dof,
x, i_dof);
477 calc_jacobian_2_slide_rotate(J, target, j1,
y, j1->
i_dof+1,
x, i_dof);
478 calc_jacobian_2_slide_rotate(J, target, j1, z, j1->
i_dof+2,
x, i_dof);
479 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof+3,
x, i_dof);
480 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+4,
x, i_dof);
481 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+5,
x, i_dof);
483 calc_jacobian_2_slide_rotate(J, target, j1,
x, j1->
i_dof,
y, i_dof+1);
484 calc_jacobian_2_slide_rotate(J, target, j1,
y, j1->
i_dof+1,
y, i_dof+1);
485 calc_jacobian_2_slide_rotate(J, target, j1, z, j1->
i_dof+2,
y, i_dof+1);
486 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof+3,
y, i_dof+1);
487 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+4,
y, i_dof+1);
488 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+5,
y, i_dof+1);
490 calc_jacobian_2_slide_rotate(J, target, j1,
x, j1->
i_dof, z, i_dof+2);
491 calc_jacobian_2_slide_rotate(J, target, j1,
y, j1->
i_dof+1, z, i_dof+2);
492 calc_jacobian_2_slide_rotate(J, target, j1, z, j1->
i_dof+2, z, i_dof+2);
493 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof+3, z, i_dof+2);
494 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+4, z, i_dof+2);
495 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+5, z, i_dof+2);
497 else if(j_type ==
JFREE)
500 calc_jacobian_2_rotate_slide(J, target, j1,
x, j1->
i_dof+3,
x, i_dof);
501 calc_jacobian_2_rotate_slide(J, target, j1,
y, j1->
i_dof+4,
x, i_dof);
502 calc_jacobian_2_rotate_slide(J, target, j1, z, j1->
i_dof+5,
x, i_dof);
504 calc_jacobian_2_rotate_slide(J, target, j1,
x, j1->
i_dof+3,
y, i_dof+1);
505 calc_jacobian_2_rotate_slide(J, target, j1,
y, j1->
i_dof+4,
y, i_dof+1);
506 calc_jacobian_2_rotate_slide(J, target, j1, z, j1->
i_dof+5,
y, i_dof+1);
508 calc_jacobian_2_rotate_slide(J, target, j1,
x, j1->
i_dof+3, z, i_dof+2);
509 calc_jacobian_2_rotate_slide(J, target, j1,
y, j1->
i_dof+4, z, i_dof+2);
510 calc_jacobian_2_rotate_slide(J, target, j1, z, j1->
i_dof+5, z, i_dof+2);
512 calc_jacobian_2_slide_rotate(J, target, j1,
x, j1->
i_dof,
x, i_dof+3);
513 calc_jacobian_2_slide_rotate(J, target, j1,
y, j1->
i_dof+1,
x, i_dof+3);
514 calc_jacobian_2_slide_rotate(J, target, j1, z, j1->
i_dof+2,
x, i_dof+3);
515 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof+3,
x, i_dof+3);
516 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+4,
x, i_dof+3);
517 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+5,
x, i_dof+3);
519 calc_jacobian_2_slide_rotate(J, target, j1,
x, j1->
i_dof,
y, i_dof+4);
520 calc_jacobian_2_slide_rotate(J, target, j1,
y, j1->
i_dof+1,
y, i_dof+4);
521 calc_jacobian_2_slide_rotate(J, target, j1, z, j1->
i_dof+2,
y, i_dof+4);
522 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof+3,
y, i_dof+4);
523 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+4,
y, i_dof+4);
524 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+5,
y, i_dof+4);
526 calc_jacobian_2_slide_rotate(J, target, j1,
x, j1->
i_dof, z, i_dof+5);
527 calc_jacobian_2_slide_rotate(J, target, j1,
y, j1->
i_dof+1, z, i_dof+5);
528 calc_jacobian_2_slide_rotate(J, target, j1, z, j1->
i_dof+2, z, i_dof+5);
529 calc_jacobian_2_rotate_rotate(J, target, j1,
x, j1->
i_dof+3, z, i_dof+5);
530 calc_jacobian_2_rotate_rotate(J, target, j1,
y, j1->
i_dof+4, z, i_dof+5);
531 calc_jacobian_2_rotate_rotate(J, target, j1, z, j1->
i_dof+5, z, i_dof+5);
533 parent->calc_jacobian_2_free_sub(J, target, j1);
539 static fVec3 out1, out2;
541 static fVec3 jk_axis, my_axis, d_jk_axis, dp, dJ;
543 my_axis.
mul(abs_att, loc_axis);
544 if(
this != jk && isAscendant(jk))
550 d_jk_axis.
cross(my_axis, jk_axis);
553 out1.
cross(d_jk_axis, dp);
557 Jt.
cross(my_axis, dp);
558 if(
this != jk && isAscendant(jk))
565 Jk.
cross(my_axis, dp);
568 out2.
cross(jk_axis, dJ);
570 J[loc_index](0, k_index) = out1(0) + out2(0);
571 J[loc_index](1, k_index) = out1(1) + out2(1);
572 J[loc_index](2, k_index) = out1(2) + out2(2);
573 J[loc_index](3, k_index) = d_jk_axis(0);
574 J[loc_index](4, k_index) = d_jk_axis(1);
575 J[loc_index](5, k_index) = d_jk_axis(2);
581 static fVec3 jk_axis, my_axis, d_jk_axis;
583 my_axis.
mul(abs_att, loc_axis);
585 if(
this != jk && isAscendant(jk))
591 d_jk_axis.
cross(my_axis, jk_axis);
593 J[loc_index](0, k_index) = d_jk_axis(0);
594 J[loc_index](1, k_index) = d_jk_axis(1);
595 J[loc_index](2, k_index) = d_jk_axis(2);
603 static fVec3 jk_axis, my_axis, out1;
605 my_axis.
mul(abs_att, loc_axis);
606 out1.
cross(jk_axis, my_axis);
607 J[loc_index](0, k_index) = out1(0);
608 J[loc_index](1, k_index) = out1(1);
609 J[loc_index](2, k_index) = out1(2);
void add(const fVec3 &vec1, const fVec3 &vec2)
int CalcJdot(fVec &jdot)
Jdot x thdot.
fVec3 axis
joint axis in local frame (for 1DOF joints)
int resize(int i, int j)
Changes the matrix size.
int calc_jacobian_free(fMat &J, Joint *target)
int CalcJacobian(fMat &J)
The Jacobian matrix of position/orientation w.r.t. the joint values.
char * CharName(const char *_name)
Extracts the character name from a joint name.
void zero()
Creates a zero vector.
int calc_jacobian_2_rotate_rotate(fMat *J, Joint *target, Joint *j1, const fVec3 &axis1, int index1, const fVec3 &axis2, int index2)
void mul(const fMat33 &mat1, const fMat33 &mat2)
void cross(const fVec3 &vec1, const fVec3 &vec2)
Cross product.
int calc_jacobian(fMat &J, Joint *target)
Joint * root
Chain information.
void set(double *v)
Set element values from array or three values.
int calc_jacobian_2_rotate_slide(fMat *J, Joint *target, Joint *jk, const fVec3 &k_axis, int k_index, const fVec3 &loc_axis, int loc_index)
int calc_jacobian_2_sphere_sub(fMat *J, Joint *target, Joint *j1)
double com_jacobian(fMat &J, fVec3 &com, const char *chname)
void zero()
Creates a zero matrix.
int CalcJacobian2(fMat *J2)
2nd-order derivatives of the Jacobian matrix.
int i_dof
index in all DOF
int calc_jacobian_sphere(fMat &J, Joint *target)
JointType j_type
joint type
int calc_jacobian_rotate(fMat &J, Joint *target)
fMat33 abs_att
absolute orientation
void cross(const fVec3 &p)
Sets spectial matrices.
int calc_jacobian_2_free_sub(fMat *J, Joint *target, Joint *j1)
int calc_jacobian_slide(fMat &J, Joint *target)
void resize(int i)
Change the size.
int calc_jacobian_2_slide_sub(fMat *J, Joint *target, Joint *j1)
double * data() const
Returns the pointer to the first element.
Classes for defining open/closed kinematic chains.
double ComJacobian(fMat &J, fVec3 &com, const char *chname=0)
Computes the com Jacobian.
int calc_jacobian_2(fMat *J, Joint *target)
int calc_jacobian_2_slide_rotate(fMat *J, Joint *target, Joint *jk, const fVec3 &k_axis, int k_index, const fVec3 &loc_axis, int loc_index)
void zero()
Creates a zero vector.
void sub(const fVec3 &vec1, const fVec3 &vec2)
fVec3 abs_pos
absolute position
void mul(const fVec3 &vec, double d)
The class for representing a joint.
int calc_jacobian_2_rotate_sub(fMat *J, Joint *target, Joint *j1)
Matrix of generic size. The elements are stored in a one-dimensional array in row-major order...