11 #include <boost/bind.hpp> 29 for(
unsigned int i = 1; i < model.
mBodies.size(); i++)
31 unsigned int q_index = model.
mJoints[i].q_index;
34 unsigned int lambda = model.
lambda[i];
36 jcalc(model, i, Q, QDot);
40 model.
v[i].set(model.
v[lambda].transform_copy(bodyFrame->getTransformFromParent()) + model.
v_J[i]);
44 model.
v[i] = model.
v_J[i];
47 model.
c[i] = model.
c_J[i] + model.
v[i] % model.
v_J[i];
48 model.
a[i].set(model.
a[lambda].transform_copy(bodyFrame->getTransformFromParent())+ model.
c[i]);
52 if(model.
mJoints[i].mDoFCount == 1)
54 model.
a[i].set(model.
a[i] + model.
S[i] * QDDot[q_index]);
56 else if(model.
mJoints[i].mDoFCount == 3)
58 model.
a[i].set(model.
a[i] + model.
multdof3_S[i] *
Vector3d(QDDot[q_index], QDDot[q_index + 1], QDDot[q_index + 2]));
63 unsigned int custom_index = model.
mJoints[i].custom_joint_index;
65 unsigned int joint_dof_count = custom_joint->
mDoFCount;
67 model.
a[i].set(model.
a[i] + (model.
mCustomJoints[custom_index]->S * QDDot.block(q_index, 0, joint_dof_count, 1)));
76 if(Q && !QDot && !QDDot)
78 for(
unsigned int i = 1; i < model.
mBodies.size(); i++)
83 else if(Q && QDot && !QDDot)
85 for(
unsigned int i = 1; i < model.
mBodies.size(); i++)
87 jcalc(model, i, (*Q), (*QDot));
90 unsigned int lambda = model.
lambda[i];
94 model.
v[i].set(model.
v[lambda].transform_copy(bodyFrame->getTransformFromParent()) + model.
v_J[i]);
95 model.
c[i] = model.
c_J[i] + model.
v[i] % model.
v_J[i];
99 model.
v[i].set(model.
v_J[i]);
100 model.
c[i] = model.
c_J[i] + model.
v[i] % model.
v_J[i];
104 else if(Q && QDot && QDDot)
106 for(
unsigned int i = 1; i < model.
mBodies.size(); i++)
108 jcalc(model, i, (*Q), (*QDot));
111 unsigned int lambda = model.
lambda[i];
115 model.
v[i].set(model.
v[lambda].transform_copy(bodyFrame->getTransformFromParent()) + model.
v_J[i]);
116 model.
c[i] = model.
c_J[i] + model.
v[i] % model.
v_J[i];
117 model.
a[i].set(model.
a[lambda].transform_copy(bodyFrame->getTransformFromParent()) + model.
c[i]);
121 model.
v[i].set(model.
v_J[i]);
122 model.
c[i] = model.
c_J[i] + model.
v[i] % model.
v_J[i];
123 model.
a[i].set(model.
c[i]);
126 unsigned int q_index = model.
mJoints[i].q_index;
130 if(model.
mJoints[i].mDoFCount == 1)
132 model.
a[i].set(model.
a[i] + model.
S[i] * (*QDDot)[q_index]);
134 else if(model.
mJoints[i].mDoFCount == 3)
136 Vector3d omegadot_temp((*QDDot)[q_index], (*QDDot)[q_index + 1], (*QDDot)[q_index + 2]);
137 model.
a[i].set(model.
a[i] + model.
multdof3_S[i] * omegadot_temp);
142 unsigned int custom_index = model.
mJoints[i].custom_joint_index;
144 unsigned int joint_dof_count = custom_joint->
mDoFCount;
146 model.
a[i].set(model.
a[i] + (model.
mCustomJoints[custom_index]->S * (QDDot->block(q_index, 0, joint_dof_count, 1))));
154 model.
a[0].setZero();
156 for(
unsigned int i = 1; i < model.
mBodies.size(); i++)
158 unsigned int q_index = model.
mJoints[i].q_index;
160 unsigned int lambda = model.
lambda[i];
164 model.
a[i].set(model.
a[lambda].transform_copy(bodyFrame->getTransformFromParent()) + model.
c[i]);
168 model.
a[i].set(model.
c[i]);
173 if(model.
mJoints[i].mDoFCount == 1)
175 model.
a[i].set(model.
a[i] + model.
S[i] * QDDot[q_index]);
177 else if(model.
mJoints[i].mDoFCount == 3)
179 Vector3d omegadot_temp(QDDot[q_index], QDDot[q_index + 1], QDDot[q_index + 2]);
180 model.
a[i].set(model.
a[i] + model.
multdof3_S[i] * omegadot_temp);
185 unsigned int custom_index = model.
mJoints[i].custom_joint_index;
187 unsigned int joint_dof_count = custom_joint->
mDoFCount;
189 model.
a[i].set(model.
a[i] + (model.
mCustomJoints[custom_index]->S * (QDDot.block(q_index, 0, joint_dof_count, 1))));
197 model.
a[0].setZero();
204 std::atomic<unsigned int> branch_ends = 0;
217 model.
a[0].setZero();
224 std::atomic<unsigned int> branch_ends = 0;
236 ReferenceFramePtr expressedInFrameRef = expressedInFrame==
nullptr ? baseFrame : expressedInFrame;
238 if(update_kinematics)
243 unsigned int common_parent_id = model.
getCommonMovableParentId(baseFrame->getMovableBodyId(),relativeFrame->getMovableBodyId());
244 unsigned int j = baseFrame->getMovableBodyId();
246 while(j > common_parent_id)
250 if(model.
mJoints[j].mDoFCount == 1)
252 G.col(model.
mJoints[j].q_index) = model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToDesiredFrame(expressedInFrameRef));
254 else if(model.
mJoints[j].mDoFCount == 3)
256 for(
int k = 0;k<3;k++)
264 unsigned int k = model.
mJoints[j].custom_joint_index;
272 j = relativeFrame->getMovableBodyId();
274 while(j > common_parent_id)
278 if(model.
mJoints[j].mDoFCount == 1)
280 G.col(model.
mJoints[j].q_index) -= model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToDesiredFrame(expressedInFrameRef));
282 else if(model.
mJoints[j].mDoFCount == 3)
284 for(
int k = 0;k<3;k++)
292 unsigned int k = model.
mJoints[j].custom_joint_index;
303 assert(G.rows()==6 && G.cols()==model.
qdot_size);
305 ReferenceFramePtr expressedInFrameRef = expressedInFrame==
nullptr ? baseFrame : expressedInFrame;
307 if(update_kinematics)
312 unsigned int common_parent_id = model.
getCommonMovableParentId(baseFrame->getMovableBodyId(),relativeFrame->getMovableBodyId());
313 unsigned int j = baseFrame->getMovableBodyId();
321 if(model.
mJoints[j].mDoFCount == 1)
323 G.col(model.
mJoints[j].q_index) = v_cur_wrt_new_expr_in_new%model.
S[j].transform_copy(X_j_to_expressedInFrame);
327 if(j>common_parent_id)
332 else if(model.
mJoints[j].mDoFCount == 3)
334 for(
int k = 0;k<3;k++)
338 if(j>common_parent_id)
347 unsigned int k = model.
mJoints[j].custom_joint_index;
351 if(j>common_parent_id)
360 j = relativeFrame->getMovableBodyId();
361 v_cur_wrt_new_expr_in_new =
calcSpatialVelocity(model,Q,QDot,relativeFrame,expressedInFrameRef,expressedInFrameRef,
false);
367 if(model.
mJoints[j].mDoFCount == 1)
369 G.col(model.
mJoints[j].q_index) -= v_cur_wrt_new_expr_in_new%model.
S[j].transform_copy(X_j_to_expressedInFrame);
370 if(j>common_parent_id)
375 else if(model.
mJoints[j].mDoFCount == 3)
377 for(
int k = 0;k<3;k++)
380 if(j>common_parent_id)
389 unsigned int k = model.
mJoints[j].custom_joint_index;
392 if(j>common_parent_id)
405 assert(G.rows()==6 && G.cols()==model.
qdot_size && GDot.rows()==6 && GDot.cols()==model.
qdot_size);
406 ReferenceFramePtr expressedInFrameRef = expressedInFrame==
nullptr ? baseFrame : expressedInFrame;
408 if(update_kinematics)
413 unsigned int common_parent_id = model.
getCommonMovableParentId(baseFrame->getMovableBodyId(),relativeFrame->getMovableBodyId());
414 unsigned int j = baseFrame->getMovableBodyId();
422 if(model.
mJoints[j].mDoFCount == 1)
424 GDot.col(model.
mJoints[j].q_index) = v_cur_wrt_new_expr_in_new%model.
S[j].transform_copy(X_j_to_expressedInFrame);
428 if(j>common_parent_id)
431 G.col(model.
mJoints[j].q_index) = model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToDesiredFrame(expressedInFrameRef));
434 else if(model.
mJoints[j].mDoFCount == 3)
436 for(
int k = 0;k<3;k++)
440 if(j>common_parent_id)
451 unsigned int k = model.
mJoints[j].custom_joint_index;
455 if(j>common_parent_id)
465 j = relativeFrame->getMovableBodyId();
466 v_cur_wrt_new_expr_in_new =
calcSpatialVelocity(model,Q,QDot,relativeFrame,expressedInFrameRef,expressedInFrameRef,
false);
472 if(model.
mJoints[j].mDoFCount == 1)
474 GDot.col(model.
mJoints[j].q_index) -= v_cur_wrt_new_expr_in_new%model.
S[j].transform_copy(X_j_to_expressedInFrame);
475 if(j>common_parent_id)
478 G.col(model.
mJoints[j].q_index) -= model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToDesiredFrame(expressedInFrameRef));
481 else if(model.
mJoints[j].mDoFCount == 3)
483 for(
int k = 0;k<3;k++)
486 if(j>common_parent_id)
496 unsigned int k = model.
mJoints[j].custom_joint_index;
499 if(j>common_parent_id)
514 if(update_kinematics)
519 unsigned int reference_body_id = body_id;
525 reference_body_id = model.
mFixedBodies[fbody_id].mMovableParent;
537 assert (G.rows() == 3 && G.cols() == model.
qdot_size);
539 unsigned int j = reference_body_id;
545 if(model.
mJoints[j].mDoFCount == 1)
547 G.col(model.
mJoints[j].q_index) = model.
S[j].transform_copy(point_trans*model.
bodyFrames[j]->getTransformToRoot()).getLinearPart();
549 else if(model.
mJoints[j].mDoFCount == 3)
556 unsigned int k = model.
mJoints[j].custom_joint_index;
566 bool update_kinematics)
569 if(update_kinematics)
576 assert (G.rows() == 3 && G.cols() == model.
qdot_size);
578 unsigned int j = frame->getMovableBodyId();
584 if(model.
mJoints[j].mDoFCount == 1)
586 G.col(model.
mJoints[j].q_index) = model.
S[j].transform_copy(point_trans*model.
bodyFrames[j]->getTransformToRoot()).getLinearPart();
588 else if(model.
mJoints[j].mDoFCount == 3)
595 unsigned int k = model.
mJoints[j].custom_joint_index;
605 bool update_kinematics)
608 if(update_kinematics)
615 assert (G.rows() == 6 && G.cols() == model.
qdot_size);
617 unsigned int j = frame->getMovableBodyId();
623 if(model.
mJoints[j].mDoFCount == 1)
625 G.col(model.
mJoints[j].q_index) = model.
S[j].transform_copy(point_trans*model.
bodyFrames[j]->getTransformToRoot());
627 else if(model.
mJoints[j].mDoFCount == 3)
634 unsigned int k = model.
mJoints[j].custom_joint_index;
649 bool update_kinematics)
651 assert(baseFrame!=
nullptr && relativeFrame!=
nullptr && expressedInFrame!=
nullptr);
652 assert(G.rows()==6 && G.cols()==model.
qdot_size);
654 if(update_kinematics)
659 assert(G.rows()==6 && G.cols() == model.
qdot_size);
661 unsigned int common_parent_id = model.
getCommonMovableParentId(baseFrame->getMovableBodyId(),relativeFrame->getMovableBodyId());
667 unsigned int j = baseFrame->getMovableBodyId();
668 while(j > common_parent_id)
672 if(model.
mJoints[j].mDoFCount == 1)
674 G.col(model.
mJoints[j].q_index) = model.
S[j].transform_copy(point_trans*model.
bodyFrames[j]->getTransformToRoot());
676 else if(model.
mJoints[j].mDoFCount == 3)
683 unsigned int k = model.
mJoints[j].custom_joint_index;
691 point_trans = X_rot*
Xtrans(relativeFrame->getInverseTransformToRoot().r);
692 j = relativeFrame->getMovableBodyId();
694 while(j > common_parent_id)
698 if(model.
mJoints[j].mDoFCount == 1)
700 G.col(model.
mJoints[j].q_index) = -model.
S[j].transform_copy(point_trans*model.
bodyFrames[j]->getTransformToRoot());
702 else if(model.
mJoints[j].mDoFCount == 3)
709 unsigned int k = model.
mJoints[j].custom_joint_index;
723 matrix_trans.block<3,3>(3,0) =
toTildeForm(-baseFrame->getInverseTransformToRoot().r+relativeFrame->getInverseTransformToRoot().r);
725 j = common_parent_id;
731 if(model.
mJoints[j].mDoFCount == 1)
733 G.col(model.
mJoints[j].q_index) = expr_X_world*matrix_trans*model.
bodyFrames[j]->getTransformToRoot().toMatrix()*model.
S[j];
735 else if(model.
mJoints[j].mDoFCount == 3)
737 G.block(0, model.
mJoints[j].q_index, 6, 3) = expr_X_world*matrix_trans*model.
bodyFrames[j]->getTransformToRoot().toMatrix() * model.
multdof3_S[j];
742 unsigned int k = model.
mJoints[j].custom_joint_index;
754 assert (G.rows() == 3 && G.cols() == model.
qdot_size);
766 if(update_kinematics)
773 unsigned int reference_body_id = body_id;
778 reference_body_id = model.
mFixedBodies[fbody_id].mMovableParent;
790 assert (G.rows() == 6 && G.cols() == model.
qdot_size);
792 unsigned int j = reference_body_id;
799 if(model.
mJoints[j].mDoFCount == 1)
801 G.col(model.
mJoints[j].q_index) = model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToRoot()).transform_copy(point_trans);
803 else if(model.
mJoints[j].mDoFCount == 3)
807 for(
int k = 0;k<3;k++)
810 m_vec.
transform(frame->getTransformToRoot());
817 unsigned int k = model.
mJoints[j].custom_joint_index;
830 if(update_kinematics)
839 assert (G.rows() == 6 && G.cols() == model.
qdot_size);
841 unsigned int j = frame->getMovableBodyId();
848 if(model.
mJoints[j].mDoFCount == 1)
850 G.block<3,1>(3,model.
mJoints[j].q_index) = v.getAngularPart().cross(model.
S[j].transform_copy(X_tmp).getLinearPart());
853 else if(model.
mJoints[j].mDoFCount == 3)
855 for(
int k = 0;k<3;k++)
864 unsigned int k = model.
mJoints[j].custom_joint_index;
866 for(
unsigned int l = 0; l<model.
mCustomJoints[k]->mDoFCount;l++)
880 assert(baseFrame && relativeFrame && expressedInFrame);
881 assert (G.rows() == 6 && G.cols() == model.
qdot_size);
883 if(update_kinematics)
890 X_rot_to_expressed_in_frame.
r.setZero();
896 unsigned int j = baseFrame->getMovableBodyId();
897 unsigned int common_parent_id = model.
getCommonMovableParentId(baseFrame->getMovableBodyId(),relativeFrame->getMovableBodyId());
898 while(j > common_parent_id)
903 if(model.
mJoints[j].mDoFCount == 1)
905 G.block<3,1>(3,model.
mJoints[j].q_index) = v_base.getAngularPart().cross(model.
S[j].transform_copy(X_tmp).getLinearPart());
909 else if(model.
mJoints[j].mDoFCount == 3)
911 for(
int k = 0;k<3;k++)
917 G.block<6,3>(0,model.
mJoints[j].q_index) = X_rot_to_expressed_in_frame.
toMatrix()*G.block<6,3>(0,model.
mJoints[j].q_index);
922 unsigned int k = model.
mJoints[j].custom_joint_index;
924 for(
unsigned int l = 0; l<model.
mCustomJoints[k]->mDoFCount;l++)
928 G.col(model.
mJoints[j].q_index+l) = X_rot_to_expressed_in_frame.
toMatrix()*G.col(model.
mJoints[j].q_index+l);
936 SpatialMotion v_relative = model.
v[relativeFrame->getMovableBodyId()];
939 j = relativeFrame->getMovableBodyId();
944 while(j > common_parent_id)
949 if(model.
mJoints[j].mDoFCount == 1)
951 G.block<3,1>(3,model.
mJoints[j].q_index) = -v_relative.getAngularPart().cross(model.
S[j].transform_copy(X_tmp).getLinearPart());
955 else if(model.
mJoints[j].mDoFCount == 3)
957 for(
int k = 0;k<3;k++)
963 G.block<6,3>(0,model.
mJoints[j].q_index) = X_rot_to_expressed_in_frame.
toMatrix()*G.block<6,3>(0,model.
mJoints[j].q_index);
968 unsigned int k = model.
mJoints[j].custom_joint_index;
970 for(
unsigned int l = 0; l<model.
mCustomJoints[k]->mDoFCount;l++)
974 G.col(model.
mJoints[j].q_index+l) = X_rot_to_expressed_in_frame.
toMatrix()*G.col(model.
mJoints[j].q_index+l);
981 j = common_parent_id;
987 X.block<3,3>(3,0) =
toTildeForm(v_base.getAngularPart())*base_point_trans.toMatrix().block<3,3>(3,0) -
997 X_tmp = (base_point_trans.toMatrix()-relative_point_trans.
toMatrix())*model.
bodyFrames[j]->getTransformToRoot().toMatrix();
1000 if(model.
mJoints[j].mDoFCount == 1)
1002 G.block<3,1>(3,model.
mJoints[j].q_index) = (X*model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToRoot())).block<3,1>(3,0);
1004 G.col(model.
mJoints[j].q_index) = X_rot_to_expressed_in_frame.
toMatrix()*G.col(model.
mJoints[j].q_index);
1006 else if(model.
mJoints[j].mDoFCount == 3)
1008 for(
int k = 0;k<3;k++)
1014 G.block<6,3>(0,model.
mJoints[j].q_index) = X_rot_to_expressed_in_frame.
toMatrix()*G.block<6,3>(0,model.
mJoints[j].q_index);
1019 unsigned int k = model.
mJoints[j].custom_joint_index;
1021 for(
unsigned int l = 0; l<model.
mCustomJoints[k]->mDoFCount;l++)
1025 G.col(model.
mJoints[j].q_index+l) = X_rot_to_expressed_in_frame.
toMatrix()*G.col(model.
mJoints[j].q_index+l);
1036 assert(baseFrame && relativeFrame && expressedInFrame);
1037 assert (GDot.rows() == 6 && GDot.cols() == model.
qdot_size);
1038 assert (G.rows() == 6 && G.cols() == model.
qdot_size);
1040 if(update_kinematics)
1045 SpatialTransform X_rot_to_expressed_in_frame = expressedInFrame->getInverseTransformToRoot();
1047 X_rot_to_expressed_in_frame.
r.setZero();
1053 SpatialTransform point_trans = X_rot_to_expressed_in_frame*base_point_trans;
1055 unsigned int j = baseFrame->getMovableBodyId();
1056 unsigned int common_parent_id = model.
getCommonMovableParentId(baseFrame->getMovableBodyId(),relativeFrame->getMovableBodyId());
1057 while(j > common_parent_id)
1062 if(model.
mJoints[j].mDoFCount == 1)
1064 G.col(model.
mJoints[j].q_index) = model.
S[j].transform_copy(point_trans*model.
bodyFrames[j]->getTransformToRoot());
1066 GDot.block<3,1>(3,model.
mJoints[j].q_index) = v_base.getAngularPart().cross(model.
S[j].transform_copy(X_tmp).getLinearPart());
1068 GDot.col(model.
mJoints[j].q_index) = X_rot_to_expressed_in_frame.
toMatrix()*GDot.col(model.
mJoints[j].q_index);
1070 else if(model.
mJoints[j].mDoFCount == 3)
1074 for(
int k = 0;k<3;k++)
1080 GDot.block<6,3>(0,model.
mJoints[j].q_index) = X_rot_to_expressed_in_frame.
toMatrix()*GDot.block<6,3>(0,model.
mJoints[j].q_index);
1085 unsigned int k = model.
mJoints[j].custom_joint_index;
1089 for(
unsigned int l = 0; l<model.
mCustomJoints[k]->mDoFCount;l++)
1093 GDot.col(model.
mJoints[j].q_index+l) = X_rot_to_expressed_in_frame.
toMatrix()*GDot.col(model.
mJoints[j].q_index+l);
1101 SpatialMotion v_relative = model.
v[relativeFrame->getMovableBodyId()];
1104 point_trans = X_rot_to_expressed_in_frame*relative_point_trans;
1106 j = relativeFrame->getMovableBodyId();
1111 while(j > common_parent_id)
1116 if(model.
mJoints[j].mDoFCount == 1)
1118 G.col(model.
mJoints[j].q_index) = -model.
S[j].transform_copy(point_trans*model.
bodyFrames[j]->getTransformToRoot());
1120 GDot.block<3,1>(3,model.
mJoints[j].q_index) = -v_relative.getAngularPart().cross(model.
S[j].transform_copy(X_tmp).getLinearPart());
1122 GDot.col(model.
mJoints[j].q_index) = X_rot_to_expressed_in_frame.
toMatrix()*GDot.col(model.
mJoints[j].q_index);
1124 else if(model.
mJoints[j].mDoFCount == 3)
1128 for(
int k = 0;k<3;k++)
1134 GDot.block<6,3>(0,model.
mJoints[j].q_index) = X_rot_to_expressed_in_frame.
toMatrix()*GDot.block<6,3>(0,model.
mJoints[j].q_index);
1139 unsigned int k = model.
mJoints[j].custom_joint_index;
1143 for(
unsigned int l = 0; l<model.
mCustomJoints[k]->mDoFCount;l++)
1147 GDot.col(model.
mJoints[j].q_index+l) = X_rot_to_expressed_in_frame.
toMatrix()*GDot.col(model.
mJoints[j].q_index+l);
1158 X.block<3,3>(3,0) =
toTildeForm(v_base.getAngularPart())*base_point_trans.toMatrix().block<3,3>(3,0) -
1159 toTildeForm(v_relative.getAngularPart())*relative_point_trans.toMatrix().block<3,3>(3,0);
1169 matrix_trans.block<3,3>(3,0) =
toTildeForm(-baseFrame->getInverseTransformToRoot().r+relativeFrame->getInverseTransformToRoot().r);
1172 j = common_parent_id;
1179 X_tmp = (base_point_trans.toMatrix()-relative_point_trans.toMatrix())*model.
bodyFrames[j]->getTransformToRoot().toMatrix();
1182 if(model.
mJoints[j].mDoFCount == 1)
1184 G.col(model.
mJoints[j].q_index) = expr_X_world*matrix_trans*model.
bodyFrames[j]->getTransformToRoot().toMatrix()*model.
S[j];
1186 GDot.block<3,1>(3,model.
mJoints[j].q_index) = (X*model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToRoot())).block<3,1>(3,0);
1188 GDot.col(model.
mJoints[j].q_index) = X_rot_to_expressed_in_frame.
toMatrix()*GDot.col(model.
mJoints[j].q_index);
1190 else if(model.
mJoints[j].mDoFCount == 3)
1192 G.block(0, model.
mJoints[j].q_index, 6, 3) = expr_X_world*matrix_trans*model.
bodyFrames[j]->getTransformToRoot().toMatrix() * model.
multdof3_S[j];
1194 for(
int k = 0;k<3;k++)
1200 GDot.block<6,3>(0,model.
mJoints[j].q_index) = X_rot_to_expressed_in_frame.
toMatrix()*GDot.block<6,3>(0,model.
mJoints[j].q_index);
1205 unsigned int k = model.
mJoints[j].custom_joint_index;
1209 for(
unsigned int l = 0; l<model.
mCustomJoints[k]->mDoFCount;l++)
1213 GDot.col(model.
mJoints[j].q_index+l) = X_rot_to_expressed_in_frame.
toMatrix()*GDot.col(model.
mJoints[j].q_index+l);
1224 assert (G.rows() == 3 && G.cols() == model.
qdot_size);
1229 G = GDot6D.block(3,0,3,model.
qdot_size);
1236 if(update_kinematics)
1243 unsigned int reference_body_id = body_id;
1248 reference_body_id = model.
mFixedBodies[fbody_id].mMovableParent;
1262 assert (G.rows() == 6 && G.cols() == model.
qdot_size);
1264 unsigned int j = reference_body_id;
1270 if(model.
mJoints[j].mDoFCount == 1)
1276 vw_x_S.
setLinearPart(model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToRoot()).transform_copy(point_trans).getLinearPart());
1282 else if(model.
mJoints[j].mDoFCount == 3)
1284 for(
int k = 0;k<3;k++)
1295 unsigned int k = model.
mJoints[j].custom_joint_index;
1297 for(
unsigned int l = 0; l<model.
mCustomJoints[k]->mDoFCount;l++)
1311 bool update_kinematics)
1314 if(update_kinematics)
1319 assert (G.rows() == 6 && G.cols() == model.
qdot_size);
1321 unsigned int reference_body_id = body_id;
1330 reference_body_id = model.
mFixedBodies[fbody_id].mMovableParent;
1335 bodyFrame = model.
bodyFrames[reference_body_id];
1338 unsigned int j = reference_body_id;
1344 if(model.
mJoints[j].mDoFCount == 1)
1346 G.col(model.
mJoints[j].q_index) = model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToDesiredFrame(bodyFrame));
1348 else if(model.
mJoints[j].mDoFCount == 3)
1350 for(
int k = 0;k<3;k++)
1358 unsigned int k = model.
mJoints[j].custom_joint_index;
1370 if(update_kinematics)
1375 assert (G.rows() == 6 && G.cols() == model.
qdot_size);
1377 unsigned int reference_body_id = body_id;
1385 reference_body_id = model.
mFixedBodies[fbody_id].mMovableParent;
1390 bodyFrame = model.
bodyFrames[reference_body_id];
1393 unsigned int j = reference_body_id;
1399 if(model.
mJoints[j].mDoFCount == 1)
1403 else if(model.
mJoints[j].mDoFCount == 3)
1405 for(
int k = 0;k<3;k++)
1413 unsigned int k = model.
mJoints[j].custom_joint_index;
1423 const Vector3d &point_position,
bool update_kinematics)
1426 assert (model.
q_size == Q.size());
1427 assert (model.
qdot_size == QDot.size());
1430 model.
v[0].setZero();
1432 if(update_kinematics)
1437 unsigned int reference_body_id = body_id;
1443 reference_body_id = model.
mFixedBodies[fbody_id].mMovableParent;
1461 bool update_kinematics)
1464 assert (model.
q_size == Q.size());
1465 assert (model.
qdot_size == QDot.size());
1468 model.
v[0].setZero();
1470 if(update_kinematics)
1475 unsigned int reference_body_id = body_id;
1481 reference_body_id = model.
mFixedBodies[fbody_id].mMovableParent;
1494 return point_velocity;
1500 assert (model.
q_size == Q.size());
1501 assert (model.
qdot_size == QDot.size());
1504 model.
v[0].setZero();
1506 if(update_kinematics)
1512 unsigned int body_id = frame->getMovableBodyId();
1513 if(!frame->getIsBodyFrame())
1515 p = frame->getTransformFromParent().r;
1522 return point_velocity;
1528 bool update_kinematics)
1530 if(update_kinematics)
1550 const bool update_kinematics)
1553 model.
v[0].setZero();
1554 model.
a[0].setZero();
1556 if(update_kinematics)
1563 if(!body_frame->getIsBodyFrame())
1565 p = body_frame->getTransformFromParent().r;
1566 moveable_body_frame = model.
bodyFrames[body_frame->getMovableBodyId()];
1574 accel.setLinearPart(accel.linear()+point_velocity.angular().cross(point_velocity.linear()));
1578 if(!relative_body_frame->getIsBodyFrame())
1580 p = relative_body_frame->getTransformFromParent().r;
1581 movable_relative_body_frame = model.
bodyFrames[relative_body_frame->getMovableBodyId()];
1584 p_X_i =
SpatialTransform(movable_relative_body_frame->getTransformToRoot().E,p);
1588 accel.setLinearPart(accel.linear()-point_velocity.
angular().
cross(point_velocity.
linear()));
1590 return accel.changeFrameAndCopy(expressedInFrame);
1594 const VectorNd &
QDDot,
unsigned int body_id,
const Vector3d &point_position,
bool update_kinematics)
1598 model.
v[0].setZero();
1599 model.
a[0].setZero();
1601 if(update_kinematics)
1606 unsigned int reference_body_id = body_id;
1612 reference_body_id = model.
mFixedBodies[fbody_id].mMovableParent;
1624 MotionVector p_v_i = model.
v[reference_body_id].transform_copy(p_X_i);
1626 MotionVector p_a_i = model.
a[reference_body_id].transform_copy(p_X_i);
1632 const VectorNd &
QDDot,
unsigned int body_id,
const Vector3d &point_position,
bool update_kinematics)
1635 model.
v[0].setZero();
1636 model.
a[0].setZero();
1638 if(update_kinematics)
1643 unsigned int reference_body_id = body_id;
1649 reference_body_id = model.
mFixedBodies[fbody_id].mMovableParent;
1663 MotionVector p_v_i = model.
v[reference_body_id].transform_copy(p_X_i);
1665 accel.setLinearPart(accel.linear()+a_dash);
1676 const bool update_kinematics)
1680 expressedInFrameRef = expressedInFrame==
nullptr ? body_frame : expressedInFrame;
1681 assert(body_frame!=
nullptr && relative_body_frame!=
nullptr && expressedInFrameRef!=
nullptr);
1682 if(body_frame==relative_body_frame)
1689 if(update_kinematics)
1695 if(!body_frame->getIsBodyFrame())
1703 if(!relative_body_frame->getIsBodyFrame())
1713 return (v_body-v_relative_body);
1731 expressedInFrameRef = expressedInFrame==
nullptr ? body_frame : expressedInFrame;
1739 relative_body_frame = model.
bodyFrames[relative_body_id];
1742 assert(body_frame!=
nullptr && relative_body_frame!=
nullptr && expressedInFrameRef!=
nullptr);
1744 if(body_id==relative_body_id)
1749 if(update_kinematics)
1763 v_body = model.
v[body_id];
1775 v_relative_body = model.
v[relative_body_id];
1781 return (v_body-v_relative_body);
1791 const bool update_kinematics)
1793 if(body_frame==relative_body_frame)
1798 if(update_kinematics)
1804 if(!body_frame->getIsBodyFrame())
1812 if(!relative_body_frame->getIsBodyFrame())
1827 a_body-=a_relative_body;
1842 twistOfCurrentFrameWithRespectToNewFrame =
1844 twistOfBodyWrtBaseExpressedInCurrent =
1872 relative_body_frame = model.
bodyFrames[relative_body_id];
1875 return calcSpatialAcceleration(model,Q,QDot,QDDot,body_frame,relative_body_frame,expressedInFrame,update_kinematics);
1879 const std::vector<Vector3d> &body_point,
const std::vector<Vector3d> &target_pos,
VectorNd &Qres,
1880 double step_tol,
double lambda,
unsigned int max_iter)
1882 assert (Qinit.size() == model.
q_size);
1883 assert (body_id.size() == body_point.size());
1884 assert (body_id.size() == target_pos.size());
1887 VectorNd e = VectorNd::Zero(3 * body_id.size());
1894 for(
unsigned int ik_iter = 0; ik_iter < max_iter; ik_iter++)
1898 for(
unsigned int k = 0; k < body_id.size(); k++)
1906 for(
unsigned int i = 0; i < 3; i++)
1908 for(
unsigned int j = 0; j < model.
qdot_size; j++)
1910 unsigned int row = k * 3 + i;
1911 J(row, j) = G(i, j);
1914 e[k * 3 + i] = target_pos[k][i] - tmp_vec[i];
1919 if(e.norm() < step_tol)
1924 MatrixNd JJTe_lambda2_I = J * J.transpose() + lambda * lambda * MatrixNd::Identity(e.size(), e.size());
1928 assert (solve_successful);
1930 VectorNd delta_theta = J.transpose() * z;
1932 Qres = Qres + delta_theta;
1934 if(delta_theta.norm() < step_tol)
1944 for(
unsigned int i = 0; i < z.size(); i++)
1948 VectorNd test_delta = J.transpose() * test_1;
1950 test_res[i] = test_delta.squaredNorm();
bool IsFixedBodyId(unsigned int body_id) const
Checks whether the body is rigidly attached to another body.
File containing the FramePoint<T> object definition.
void calcPointJacobian(Model &model, const Math::VectorNd &Q, unsigned int body_id, const Math::Vector3d &point_position, Math::MatrixNd &G, bool update_kinematics=true)
Computes the 3D point jacobian for a point on a body.
std::vector< Joint > mJoints
All joints.
ReferenceFramePtr getReferenceFrame() const
Get a pointer to the reference frame this FrameObject is expressed in.
SpatialMatrix crossm()
Get the spatial motion cross matrix, .
SpatialVector SpatialVectorZero
A FramePoint is a 3D point that is expressed in a ReferenceFrame. To change the ReferenceFrame a Fram...
std::vector< Math::SpatialVector > c_J
void calcRelativeBodySpatialJacobianAndJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, Math::MatrixNd &GDot, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=nullptr, bool update_kinematics=true)
Computes both the body spatial jacobian and its time derivative. This function will be a bit more eff...
User defined joints of varying size.
Matrix3d Matrix3dIdentity
CustomJoint is a struct used to create a joint with user defined parameters. This is accomplished by ...
FrameVector linear() const
Get copy of linear component.
std::vector< FixedBody > mFixedBodies
All bodies that are attached to a body via a fixed joint.
std::vector< unsigned int > lambda
unsigned int num_branch_ends
bool linSolveGaussElimPivot(MatrixNd A, VectorNd b, VectorNd &x)
Solves a linear system using gaussian elimination with pivoting.
Math::SpatialMotion calcSpatialVelocity(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, ReferenceFramePtr body_frame, ReferenceFramePtr relative_body_frame, ReferenceFramePtr expressedInFrame=nullptr, const bool update_kinematics=true)
Compute the spatial velocity of any frame with respect to any other frame, expressed in an arbirtary ...
void transform(const SpatialTransform &X)
Transforms a motion vector. Performs .
void calcRelativeBodySpatialJacobian(Model &model, const Math::VectorNd &Q, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=nullptr, bool update_kinematics=true)
Computes the jacobian of a frame with being the "base" frame, being the "relative" frame...
void setLinearPart(const Vector3d &v)
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
void calcPointJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, Math::MatrixNd &G, bool update_kinematics=true)
Computes the time derivative of the linear components the a point jacobian on a body.
FrameVector angular() const
Get copy of angular component.
void calcRelativePointJacobian6D(Model &model, const Math::VectorNd &Q, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=RobotDynamics::ReferenceFrame::getWorldFrame(), bool update_kinematics=true)
Compute the 6D jacobian of the origin of a reference frame relative to the origin of another referenc...
void jcalc(Model &model, unsigned int joint_id, const Math::VectorNd &q, const Math::VectorNd &qdot)
Computes all variables for a joint model and updates the body frame as well as the body's center of m...
std::vector< boost::thread * > threads
Math::FrameVector calcPointAcceleration(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes the linear acceleration of a point on a body.
static Matrix3d toTildeForm(const Point3d &p)
void calcRelativePointJacobianAndJacobianDot6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, Math::MatrixNd &GDot, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=RobotDynamics::ReferenceFrame::getWorldFrame(), bool update_kinematics=true)
Compute the point Jacobian of the origin of baseFrame, relative to the origin of relativeFrame, expressed in expressedInFrame. Also compute that point Jacobians time derivative.
static ReferenceFramePtr getWorldFrame()
Get a pointer to the world frame.
FrameVector cross(const FrameVector &vector) const
Cross product between two FrameVectors, i.e. .
Math::SpatialAcceleration calcSpatialAcceleration(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, const unsigned int body_id, const unsigned int relative_body_id, ReferenceFramePtr expressedInFrame=nullptr, const bool update_kinematics=true)
Compute the spatial acceleration of any body with respect to any other body and express the result in...
std::vector< ReferenceFramePtr > bodyFrames
ReferenceFramePtr worldFrame
void calcPointJacobian6D(Model &model, const Math::VectorNd &Q, Math::MatrixNd &G, ReferenceFramePtr frame, bool update_kinematics=true)
Compute the 6D point jacobian of the origin of a reference frame If a position of a point is computed...
EIGEN_STRONG_INLINE void setIncludingFrame(const Math::Vector3d &v, ReferenceFramePtr referenceFrame)
Set both the ReferenceFrame this object is expressed in as well as the (x,y,z) coordinates of the poi...
EIGEN_STRONG_INLINE Math::Vector3d vec() const
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
Math::FrameVector calcPointVelocity(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes the velocity of a point on a body.
unsigned int q_size
The size of the -vector. For models without spherical joints the value is the same as Model::dof_coun...
bool IsBodyId(unsigned int id) const
void calcRelativePointJacobianDot6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=RobotDynamics::ReferenceFrame::getWorldFrame(), bool update_kinematics=true)
Compute the time derivative of the 6D jacobian of the origin of a reference frame relative to the ori...
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
void calcPointJacobianDot6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, RobotDynamics::ReferenceFramePtr frame, Math::MatrixNd &G, bool update_kinematics=true)
Computes the time derivative of a point jacobian of a point on a body.
std::vector< Math::Matrix63 > multdof3_S_o
std::vector< Body > mBodies
All bodies 0 ... N_B, including the base.
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
A SpatialMotion vector is a MotionVector with a RobotDynamics::ReferenceFrame it is expressed in...
void changeFrame(ReferenceFramePtr referenceFrame)
Change the frame of the two 3d vectors. Equivalent to the following math expression ...
void calcBodySpatialJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd QDot, unsigned int body_id, Math::MatrixNd &G, const bool update_kinematics=true)
Computes the time derivative of the spatial jacobian for a body. The result will be returned via the ...
void updateKinematicsParallel(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot)
Updates and computes velocities and accelerations of the bodies.
ReferenceFramePtr getBaseFrame() const
Get a SpatialMotions SpatialMotion::baseFrame.
void crawlChainKinematics(unsigned int b_id, std::atomic< unsigned int > *branch_ends, const Math::VectorNd *Q, const Math::VectorNd *QDot, const Math::VectorNd *QDDot)
void calcBodySpatialJacobian(Model &model, const Math::VectorNd &Q, unsigned int body_id, Math::MatrixNd &G, bool update_kinematics=true)
Computes the spatial jacobian for a body. The result will be returned via the G argument and represen...
void updateKinematics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot)
Updates and computes velocities and accelerations of the bodies.
Math::SpatialAccelerationV a
The spatial velocity of the bodies.
std::vector< CustomJoint * > mCustomJoints
ReferenceFramePtr getBodyFrame() const
Get a SpatialMotions SpatialMotion::bodyFrame.
EIGEN_STRONG_INLINE Vector3d getAngularPart() const
bool inverseKinematics(Model &model, const Math::VectorNd &Qinit, const std::vector< unsigned int > &body_id, const std::vector< Math::Vector3d > &body_point, const std::vector< Math::Vector3d > &target_pos, Math::VectorNd &Qres, double step_tol=1.0e-12, double lambda=0.01, unsigned int max_iter=50)
Computes the inverse kinematics iteratively using a damped Levenberg-Marquardt method (also known as ...
Contains all information about the rigid body model.
void calcRelativeBodySpatialJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=nullptr, bool update_kinematics=true)
Computes the rate of change of the jacobian, , with being the "base" frame, being the relative" fra...
void setLinearPart(const Vector3d &v)
Set the linear vector.
void updateKinematicsCustom(Model &model, const Math::VectorNd *Q, const Math::VectorNd *QDot=nullptr, const Math::VectorNd *QDDot=nullptr)
Selectively updates model internal states of body positions, velocities and/or accelerations.
unsigned int getCommonMovableParentId(unsigned int id_1, unsigned int id_2) const
std::vector< Math::SpatialVector > c
The velocity dependent spatial acceleration.
Eigen::Matrix< double, 6, 3 > Matrix63
Vector3d cross(const Vector3d &v)
Cross product between a point and vector.
unsigned int fixed_body_discriminator
Value that is used to discriminate between fixed and movable bodies.
SpatialAcceleration. For clarity, the ReferenceFrames are stated as follows. A spatial acceleration i...
void changeFrameWithRelativeMotion(ReferenceFramePtr newFrame, SpatialMotion twistOfCurrentFrameWithRespectToNewFrame, const SpatialMotion &twistOfBodyWrtBaseExpressedInCurrent)
Use this method to change the ReferenceFrame::expressedInFrame of a SpatialAcceleration if there is r...
A FrameVector is a pair of 3D vector with a ReferenceFrame.
Math::MatrixNd three_x_qd0
Math::FrameVectorPair calcPointAcceleration6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes linear and angular acceleration of a point on a body.
Math::FrameVectorPair calcPointVelocity6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes angular and linear velocity of a point that is fixed on a body.
EIGEN_STRONG_INLINE Vector3d getLinearPart() const
std::vector< Math::Matrix63 > multdof3_S
Motion subspace for joints with 3 degrees of freedom.
void updateAccelerations(Model &model, const Math::VectorNd &QDDot)
Computes only the accelerations of the bodies.
std::vector< ReferenceFramePtr > fixedBodyFrames
MotionVector transform_copy(const SpatialTransform &X) const
Copies, transforms, and returns a MotionVector. Performs .
void updateKinematicsCustomParallel(Model &model, const Math::VectorNd *Q, const Math::VectorNd *QDot=nullptr, const Math::VectorNd *QDDot=nullptr)
Selectively updates model internal states of body positions, velocities and/or accelerations and spaw...
static Matrix3d toMatrix(const Quaternion &q)
Convert quaternion to rotation matrix.
void setBodyFrame(ReferenceFramePtr referenceFrame)
Sets the body frame of a spatial motion.
Namespace for all structures of the RobotDynamics library.
unsigned int qdot_size
The size of the.