32 std::vector<SpatialVector> *f_ext) {
33 LOG <<
"-------- " << __func__ <<
" --------" << std::endl;
37 model.a[0].set (0., 0., 0., -model.gravity[0], -model.gravity[1], -model.gravity[2]);
39 for (
unsigned int i = 1; i < model.mBodies.size(); i++) {
40 unsigned int q_index = model.mJoints[i].q_index;
41 unsigned int lambda = model.lambda[i];
43 jcalc (model, i, Q, QDot);
45 model.v[i] = model.X_lambda[i].apply(model.v[lambda]) + model.v_J[i];
46 model.c[i] = model.c_J[i] +
crossm(model.v[i],model.v_J[i]);
48 if(model.mJoints[i].mJointType != JointTypeCustom){
49 if (model.mJoints[i].mDoFCount == 1) {
50 model.a[i] = model.X_lambda[i].apply(model.a[lambda])
52 + model.S[i] * QDDot[q_index];
53 }
else if (model.mJoints[i].mDoFCount == 3) {
54 model.a[i] = model.X_lambda[i].apply(model.a[lambda])
56 + model.multdof3_S[i] *
Vector3d (QDDot[q_index],
60 }
else if(model.mJoints[i].mJointType == JointTypeCustom){
61 unsigned int k = model.mJoints[i].custom_joint_index;
62 VectorNd customJointQDDot(model.mCustomJoints[k]->mDoFCount);
63 for(
unsigned z = 0; z < model.mCustomJoints[k]->mDoFCount; ++z){
64 customJointQDDot[z] = QDDot[q_index+z];
66 model.a[i] = model.X_lambda[i].apply(model.a[lambda])
68 + model.mCustomJoints[k]->S * customJointQDDot;
71 if (!model.mBodies[i].mIsVirtual) {
72 model.f[i] = model.I[i] * model.a[i] +
crossf(model.v[i],model.I[i] * model.v[i]);
79 for (
unsigned int i = 1; i < model.mBodies.size(); i++) {
80 unsigned int lambda = model.lambda[i];
81 model.X_base[i] = model.X_lambda[i] * model.X_base[lambda];
82 model.f[i] -= model.X_base[i].toMatrixAdjoint() * (*f_ext)[i];
86 for (
unsigned int i = model.mBodies.size() - 1; i > 0; i--) {
87 if(model.mJoints[i].mJointType != JointTypeCustom){
88 if (model.mJoints[i].mDoFCount == 1) {
89 Tau[model.mJoints[i].q_index] = model.S[i].dot(model.f[i]);
90 }
else if (model.mJoints[i].mDoFCount == 3) {
91 Tau.block<3,1>(model.mJoints[i].q_index, 0)
92 = model.multdof3_S[i].transpose() * model.f[i];
94 }
else if (model.mJoints[i].mJointType == JointTypeCustom) {
95 unsigned int k = model.mJoints[i].custom_joint_index;
96 Tau.block(model.mJoints[i].q_index,0,
97 model.mCustomJoints[k]->mDoFCount, 1)
98 = model.mCustomJoints[k]->S.transpose() * model.f[i];
101 if (model.lambda[i] != 0) {
102 model.f[model.lambda[i]] = model.f[model.lambda[i]] + model.X_lambda[i].applyTranspose(model.f[i]);
112 std::vector<Math::SpatialVector> *f_ext) {
113 LOG <<
"-------- " << __func__ <<
" --------" << std::endl;
115 SpatialVector spatial_gravity (0., 0., 0., -model.gravity[0], -model.gravity[1], -model.gravity[2]);
118 model.v[0].setZero();
119 model.a[0] = spatial_gravity;
121 for (
unsigned int i = 1; i < model.mJointUpdateOrder.size(); i++) {
122 jcalc (model, model.mJointUpdateOrder[i], Q, QDot);
125 for (
unsigned int i = 1; i < model.mBodies.size(); i++) {
126 if (model.lambda[i] == 0) {
127 model.v[i] = model.v_J[i];
128 model.a[i] = model.X_lambda[i].apply(spatial_gravity);
130 model.v[i] = model.X_lambda[i].apply(model.v[model.lambda[i]]) + model.v_J[i];
131 model.c[i] = model.c_J[i] +
crossm(model.v[i],model.v_J[i]);
132 model.a[i] = model.X_lambda[i].apply(model.a[model.lambda[i]]) + model.c[i];
135 if (!model.mBodies[i].mIsVirtual) {
136 model.f[i] = model.I[i] * model.a[i] +
crossf(model.v[i],model.I[i] * model.v[i]);
137#ifdef RBDL_USE_CASADI_MATH
140 if (f_ext != NULL && (*f_ext)[i] != SpatialVector::Zero())
143 model.f[i] -= model.X_base[i].toMatrixAdjoint() * (*f_ext)[i];
146 model.f[i].setZero();
150 for (
unsigned int i = model.mBodies.size() - 1; i > 0; i--) {
151 if(model.mJoints[i].mJointType != JointTypeCustom){
152 if (model.mJoints[i].mDoFCount == 1) {
153 Tau[model.mJoints[i].q_index]
154 = model.S[i].dot(model.f[i]);
155 }
else if (model.mJoints[i].mDoFCount == 3) {
156 Tau.block<3,1>(model.mJoints[i].q_index, 0)
157 = model.multdof3_S[i].transpose() * model.f[i];
159 }
else if(model.mJoints[i].mJointType == JointTypeCustom) {
160 unsigned int k = model.mJoints[i].custom_joint_index;
161 Tau.block(model.mJoints[i].q_index,0,
162 model.mCustomJoints[k]->mDoFCount, 1)
163 = model.mCustomJoints[k]->S.transpose() * model.f[i];
166 if (model.lambda[i] != 0) {
167 model.f[model.lambda[i]] = model.f[model.lambda[i]] + model.X_lambda[i].applyTranspose(model.f[i]);
176 bool update_kinematics) {
177 LOG <<
"-------- " << __func__ <<
" --------" << std::endl;
179 assert (H.rows() == model.dof_count && H.cols() == model.dof_count);
181 for (
unsigned int i = 1; i < model.mBodies.size(); i++) {
182 if (update_kinematics) {
185 model.Ic[i] = model.I[i];
188 for (
unsigned int i = model.mBodies.size() - 1; i > 0; i--) {
189 if (model.lambda[i] != 0) {
190 model.Ic[model.lambda[i]] = model.Ic[model.lambda[i]] + model.X_lambda[i].applyTranspose(model.Ic[i]);
193 unsigned int dof_index_i = model.mJoints[i].q_index;
195 if (model.mJoints[i].mDoFCount == 1
196 && model.mJoints[i].mJointType != JointTypeCustom) {
199 H(dof_index_i, dof_index_i) = model.S[i].dot(F);
202 unsigned int dof_index_j = dof_index_i;
204 while (model.lambda[j] != 0) {
205 F = model.X_lambda[j].applyTranspose(F);
207 dof_index_j = model.mJoints[j].q_index;
209 if(model.mJoints[j].mJointType != JointTypeCustom) {
210 if (model.mJoints[j].mDoFCount == 1) {
211 H(dof_index_i,dof_index_j) = F.dot(model.S[j]);
212 H(dof_index_j,dof_index_i) = H(dof_index_i,dof_index_j);
213 }
else if (model.mJoints[j].mDoFCount == 3) {
215 (F.transpose() * model.multdof3_S[j]).transpose();
216 LOG << F.transpose() << std::endl
217 << model.multdof3_S[j] << std::endl;
218 LOG << H_temp2.transpose() << std::endl;
220 H.block<1,3>(dof_index_i,dof_index_j) = H_temp2.transpose();
221 H.block<3,1>(dof_index_j,dof_index_i) = H_temp2;
223 }
else if (model.mJoints[j].mJointType == JointTypeCustom){
224 unsigned int k = model.mJoints[j].custom_joint_index;
225 unsigned int dof = model.mCustomJoints[k]->mDoFCount;
227 (F.transpose() * model.mCustomJoints[k]->S).transpose();
231 << model.mCustomJoints[j]->S << std::endl;
235 H.
block(dof_index_i,dof_index_j,1,dof) = H_temp2.transpose();
236 H.block(dof_index_j,dof_index_i,dof,1) = H_temp2;
239 }
else if (model.mJoints[i].mDoFCount == 3
240 && model.mJoints[i].mJointType != JointTypeCustom) {
241 Matrix63 F_63 = model.Ic[i].toMatrix() * model.multdof3_S[i];
242 H.
block<3,3>(dof_index_i, dof_index_i) = model.multdof3_S[i].transpose() * F_63;
245 unsigned int dof_index_j = dof_index_i;
247 while (model.lambda[j] != 0) {
248 F_63 = model.X_lambda[j].toMatrixTranspose() * (F_63);
250 dof_index_j = model.mJoints[j].q_index;
252 if(model.mJoints[j].mJointType != JointTypeCustom){
253 if (model.mJoints[j].mDoFCount == 1) {
254 Vector3d H_temp2 = F_63.transpose() * (model.S[j]);
256 H.block<3,1>(dof_index_i,dof_index_j) = H_temp2;
257 H.block<1,3>(dof_index_j,dof_index_i) = H_temp2.transpose();
258 }
else if (model.mJoints[j].mDoFCount == 3) {
259 Matrix3d H_temp2 = F_63.transpose() * (model.multdof3_S[j]);
261 H.block<3,3>(dof_index_i,dof_index_j) = H_temp2;
262 H.block<3,3>(dof_index_j,dof_index_i) = H_temp2.transpose();
264 }
else if (model.mJoints[j].mJointType == JointTypeCustom){
265 unsigned int k = model.mJoints[j].custom_joint_index;
266 unsigned int dof = model.mCustomJoints[k]->mDoFCount;
270 H.
block(dof_index_i,dof_index_j,3,dof) = H_temp2;
271 H.block(dof_index_j,dof_index_i,dof,3) = H_temp2.transpose();
274 }
else if (model.mJoints[i].mJointType == JointTypeCustom) {
275 unsigned int kI = model.mJoints[i].custom_joint_index;
276 unsigned int dofI = model.mCustomJoints[kI]->mDoFCount;
278 MatrixNd F_Nd = model.Ic[i].toMatrix()
279 * model.mCustomJoints[kI]->S;
281 H.
block(dof_index_i, dof_index_i,dofI,dofI)
282 = model.mCustomJoints[kI]->S.transpose() * F_Nd;
285 unsigned int dof_index_j = dof_index_i;
287 while (model.lambda[j] != 0) {
288 F_Nd = model.X_lambda[j].toMatrixTranspose() * (F_Nd);
290 dof_index_j = model.mJoints[j].q_index;
292 if(model.mJoints[j].mJointType != JointTypeCustom){
293 if (model.mJoints[j].mDoFCount == 1) {
295 H.
block( dof_index_i, dof_index_j,
296 H_temp2.rows(),H_temp2.cols()) = H_temp2;
297 H.block(dof_index_j,dof_index_i,
298 H_temp2.cols(),H_temp2.rows()) = H_temp2.transpose();
299 }
else if (model.mJoints[j].mDoFCount == 3) {
301 H.
block(dof_index_i, dof_index_j,
302 H_temp2.rows(),H_temp2.cols()) = H_temp2;
303 H.block(dof_index_j, dof_index_i,
304 H_temp2.cols(),H_temp2.rows()) = H_temp2.transpose();
306 }
else if (model.mJoints[j].mJointType == JointTypeCustom){
307 unsigned int k = model.mJoints[j].custom_joint_index;
308 unsigned int dof = model.mCustomJoints[k]->mDoFCount;
312 H.
block(dof_index_i,dof_index_j,3,dof) = H_temp2;
313 H.block(dof_index_j,dof_index_i,dof,3) = H_temp2.transpose();
326 std::vector<SpatialVector> *f_ext) {
327 LOG <<
"-------- " << __func__ <<
" --------" << std::endl;
329 SpatialVector spatial_gravity (0., 0., 0., model.gravity[0], model.gravity[1], model.gravity[2]);
333 LOG <<
"Q = " << Q.transpose() << std::endl;
334 LOG <<
"QDot = " << QDot.transpose() << std::endl;
335 LOG <<
"Tau = " << Tau.transpose() << std::endl;
336 LOG <<
"---" << std::endl;
339 model.v[0].setZero();
341 for (i = 1; i < model.mBodies.size(); i++) {
342 unsigned int lambda = model.lambda[i];
344 jcalc (model, i, Q, QDot);
347 model.X_base[i] = model.X_lambda[i] * model.X_base[lambda];
349 model.X_base[i] = model.X_lambda[i];
351 model.v[i] = model.X_lambda[i].apply( model.v[lambda]) + model.v_J[i];
361 model.c[i] = model.c_J[i] +
crossm(model.v[i],model.v_J[i]);
362 model.I[i].setSpatialMatrix (model.IA[i]);
364 model.pA[i] =
crossf(model.v[i],model.I[i] * model.v[i]);
366#ifdef RBDL_USE_CASADI_MATH
369 if (f_ext != NULL && (*f_ext)[i] != SpatialVector::Zero()) {
371 LOG <<
"External force (" << i <<
") = " << model.X_base[i].toMatrixAdjoint() * (*f_ext)[i] << std::endl;
372 model.pA[i] -= model.X_base[i].toMatrixAdjoint() * (*f_ext)[i];
378 LOG <<
"--- first loop ---" << std::endl;
380 for (i = model.mBodies.size() - 1; i > 0; i--) {
381 unsigned int q_index = model.mJoints[i].q_index;
383 if (model.mJoints[i].mDoFCount == 1
384 && model.mJoints[i].mJointType != JointTypeCustom) {
386 model.U[i] = model.IA[i] * model.S[i];
387 model.d[i] = model.S[i].dot(model.U[i]);
388 model.u[i] = Tau[q_index] - model.S[i].dot(model.pA[i]);
391 unsigned int lambda = model.lambda[i];
395 * (model.U[i] / model.d[i]).transpose();
399 + model.U[i] * model.u[i] / model.d[i];
401#ifdef RBDL_USE_CASADI_MATH
403 += model.X_lambda[i].toMatrixTranspose()
404 * Ia * model.X_lambda[i].toMatrix();
406 model.pA[lambda] += model.X_lambda[i].applyTranspose(pa);
408 model.IA[lambda].noalias()
409 += model.X_lambda[i].toMatrixTranspose()
410 * Ia * model.X_lambda[i].toMatrix();
411 model.pA[lambda].noalias()
412 += model.X_lambda[i].applyTranspose(pa);
415 LOG <<
"pA[" << lambda <<
"] = "
416 << model.pA[lambda].transpose() << std::endl;
418 }
else if (model.mJoints[i].mDoFCount == 3
419 && model.mJoints[i].mJointType != JointTypeCustom) {
420 model.multdof3_U[i] = model.IA[i] * model.multdof3_S[i];
422#ifdef RBDL_USE_CASADI_MATH
423 model.multdof3_Dinv[i] = (model.multdof3_S[i].transpose()
424 * model.multdof3_U[i]).inverse();
426 model.multdof3_Dinv[i] = (model.multdof3_S[i].transpose()
427 * model.multdof3_U[i]).inverse().eval();
429 Vector3d tau_temp(Tau.block(q_index,0,3,1));
430 model.multdof3_u[i] = tau_temp
431 - model.multdof3_S[i].transpose() * model.pA[i];
435 unsigned int lambda = model.lambda[i];
438 - model.multdof3_U[i]
439 * model.multdof3_Dinv[i]
440 * model.multdof3_U[i].transpose();
444 + model.multdof3_U[i]
445 * model.multdof3_Dinv[i]
446 * model.multdof3_u[i];
447#ifdef RBDL_USE_CASADI_MATH
449 += model.X_lambda[i].toMatrixTranspose()
451 * model.X_lambda[i].toMatrix();
453 model.pA[lambda] += model.X_lambda[i].applyTranspose(pa);
455 model.IA[lambda].noalias()
456 += model.X_lambda[i].toMatrixTranspose()
458 * model.X_lambda[i].toMatrix();
460 model.pA[lambda].noalias()
461 += model.X_lambda[i].applyTranspose(pa);
463 LOG <<
"pA[" << lambda <<
"] = "
464 << model.pA[lambda].transpose()
467 }
else if (model.mJoints[i].mJointType == JointTypeCustom) {
468 unsigned int kI = model.mJoints[i].custom_joint_index;
469 unsigned int dofI = model.mCustomJoints[kI]->mDoFCount;
470 model.mCustomJoints[kI]->U =
471 model.IA[i] * model.mCustomJoints[kI]->S;
473#ifdef RBDL_USE_CASADI_MATH
474 model.mCustomJoints[kI]->Dinv
475 = (model.mCustomJoints[kI]->S.transpose()
476 * model.mCustomJoints[kI]->U).inverse();
478 model.mCustomJoints[kI]->Dinv
479 = (model.mCustomJoints[kI]->S.transpose()
480 * model.mCustomJoints[kI]->U).inverse().eval();
482 VectorNd tau_temp(Tau.block(q_index,0,dofI,1));
483 model.mCustomJoints[kI]->u = tau_temp
484 - model.mCustomJoints[kI]->S.transpose() * model.pA[i];
488 unsigned int lambda = model.lambda[i];
491 - (model.mCustomJoints[kI]->U
492 * model.mCustomJoints[kI]->Dinv
493 * model.mCustomJoints[kI]->U.transpose());
496 + (model.mCustomJoints[kI]->U
497 * model.mCustomJoints[kI]->Dinv
498 * model.mCustomJoints[kI]->u);
500#ifdef RBDL_USE_CASADI_MATH
501 model.IA[lambda] += model.X_lambda[i].toMatrixTranspose()
503 * model.X_lambda[i].toMatrix();
504 model.pA[lambda] += model.X_lambda[i].applyTranspose(pa);
506 model.IA[lambda].noalias() += model.X_lambda[i].toMatrixTranspose()
508 * model.X_lambda[i].toMatrix();
509 model.pA[lambda].noalias() += model.X_lambda[i].applyTranspose(pa);
511 LOG <<
"pA[" << lambda <<
"] = "
512 << model.pA[lambda].transpose()
520 model.a[0] = spatial_gravity * -1.;
522 for (i = 1; i < model.mBodies.size(); i++) {
523 unsigned int q_index = model.mJoints[i].q_index;
524 unsigned int lambda = model.lambda[i];
525 SpatialTransform X_lambda = model.X_lambda[i];
527 model.a[i] = X_lambda.apply(model.a[lambda]) + model.c[i];
528 LOG <<
"a'[" << i <<
"] = " << model.a[i].transpose() << std::endl;
530 if (model.mJoints[i].mDoFCount == 1
531 && model.mJoints[i].mJointType != JointTypeCustom) {
532 QDDot[q_index] = (1./model.d[i]) * (model.u[i] - model.U[i].dot(model.a[i]));
533 model.a[i] = model.a[i] + model.S[i] * QDDot[q_index];
534 }
else if (model.mJoints[i].mDoFCount == 3
535 && model.mJoints[i].mJointType != JointTypeCustom) {
536 Vector3d qdd_temp = model.multdof3_Dinv[i] * (model.multdof3_u[i] - model.multdof3_U[i].transpose() * model.a[i]);
537 QDDot[q_index] = qdd_temp[0];
538 QDDot[q_index + 1] = qdd_temp[1];
539 QDDot[q_index + 2] = qdd_temp[2];
540 model.a[i] = model.a[i] + model.multdof3_S[i] * qdd_temp;
541 }
else if (model.mJoints[i].mJointType == JointTypeCustom) {
542 unsigned int kI = model.mJoints[i].custom_joint_index;
543 unsigned int dofI=model.mCustomJoints[kI]->mDoFCount;
545 VectorNd qdd_temp = model.mCustomJoints[kI]->Dinv
546 * ( model.mCustomJoints[kI]->u
547 - model.mCustomJoints[kI]->U.transpose()
550 for(
int z=0; z<dofI; ++z){
551 QDDot[q_index+z] = qdd_temp[z];
554 model.a[i] = model.a[i]
555 + model.mCustomJoints[kI]->S * qdd_temp;
559 LOG <<
"QDDot = " << QDDot.
transpose() << std::endl;
568 Math::LinearSolver linear_solver,
569 std::vector<SpatialVector> *f_ext,
572 LOG <<
"-------- " << __func__ <<
" --------" << std::endl;
594 LOG <<
"A = " << std::endl << *H << std::endl;
595 LOG <<
"b = " << std::endl << *C * -1. + Tau << std::endl;
597#ifdef RBDL_USE_CASADI_MATH
598 QDDot = H->inverse() * (*C * -1. + Tau);
600 switch (linear_solver) {
602 QDDot = H->partialPivLu().solve (*C * -1. + Tau);
605 QDDot = H->colPivHouseholderQr().solve (*C * -1. + Tau);
608 QDDot = H->householderQr().solve (*C * -1. + Tau);
611 QDDot = H->llt().solve (*C * -1. + Tau);
614 LOG <<
"Error: Invalid linear solver: " << linear_solver << std::endl;
628 LOG <<
"x = " << QDDot << std::endl;
635 bool update_kinematics) {
637 LOG <<
"Q = " << Q.transpose() << std::endl;
638 LOG <<
"---" << std::endl;
641 model.v[0].setZero();
642 model.a[0].setZero();
644 if (update_kinematics) {
645 for (
unsigned int i = 1; i < model.mBodies.size(); i++) {
648 model.v_J[i].setZero();
649 model.v[i].setZero();
650 model.c[i].setZero();
651 model.pA[i].setZero();
652 model.I[i].setSpatialMatrix (model.IA[i]);
656 for (
unsigned int i = 1; i < model.mBodies.size(); i++) {
657 model.pA[i].setZero();
662 if (update_kinematics) {
664 for (
unsigned int i = model.mBodies.size() - 1; i > 0; i--) {
665 unsigned int q_index = model.mJoints[i].q_index;
667 if (model.mJoints[i].mDoFCount == 1
668 && model.mJoints[i].mJointType != JointTypeCustom) {
669 model.U[i] = model.IA[i] * model.S[i];
670 model.d[i] = model.S[i].dot(model.U[i]);
672 unsigned int lambda = model.lambda[i];
676 model.U[i] * (model.U[i] / model.d[i]).transpose();
678#ifdef RBDL_USE_CASADI_MATH
679 model.IA[lambda] += model.X_lambda[i].toMatrixTranspose()
681 * model.X_lambda[i].toMatrix();
683 model.IA[lambda].noalias() += model.X_lambda[i].toMatrixTranspose()
685 * model.X_lambda[i].toMatrix();
688 }
else if (model.mJoints[i].mDoFCount == 3
689 && model.mJoints[i].mJointType != JointTypeCustom) {
691 model.multdof3_U[i] = model.IA[i] * model.multdof3_S[i];
693#ifdef RBDL_USE_CASADI_MATH
694 model.multdof3_Dinv[i] =
695 (model.multdof3_S[i].transpose() * model.multdof3_U[i]).inverse();
697 model.multdof3_Dinv[i] =
698 (model.multdof3_S[i].transpose()*model.multdof3_U[i]).inverse().eval();
703 unsigned int lambda = model.lambda[i];
707 - ( model.multdof3_U[i]
708 * model.multdof3_Dinv[i]
709 * model.multdof3_U[i].transpose());
711#ifdef RBDL_USE_CASADI_MATH
713 model.X_lambda[i].toMatrixTranspose()
714 * Ia * model.X_lambda[i].toMatrix();
716 model.IA[lambda].noalias() +=
717 model.X_lambda[i].toMatrixTranspose()
719 * model.X_lambda[i].toMatrix();
722 }
else if (model.mJoints[i].mJointType == JointTypeCustom) {
723 unsigned int kI = model.mJoints[i].custom_joint_index;
724 unsigned int dofI = model.mCustomJoints[kI]->mDoFCount;
725 model.mCustomJoints[kI]->U = model.IA[i] * model.mCustomJoints[kI]->S;
727#ifdef RBDL_USE_CASADI_MATH
728 model.mCustomJoints[kI]->Dinv=(model.mCustomJoints[kI]->S.transpose()
729 * model.mCustomJoints[kI]->U
732 model.mCustomJoints[kI]->Dinv = (model.mCustomJoints[kI]->S.transpose()
733 * model.mCustomJoints[kI]->U
738 unsigned int lambda = model.lambda[i];
742 - ( model.mCustomJoints[kI]->U
743 * model.mCustomJoints[kI]->Dinv
744 * model.mCustomJoints[kI]->U.transpose());
745#ifdef RBDL_USE_CASADI_MATH
746 model.IA[lambda] += model.X_lambda[i].toMatrixTranspose()
747 * Ia * model.X_lambda[i].toMatrix();
749 model.IA[lambda].noalias() += model.X_lambda[i].toMatrixTranspose()
751 * model.X_lambda[i].toMatrix();
759 for (
unsigned int i = model.mBodies.size() - 1; i > 0; i--) {
760 unsigned int q_index = model.mJoints[i].q_index;
762 if (model.mJoints[i].mDoFCount == 1
763 && model.mJoints[i].mJointType != JointTypeCustom) {
765 model.u[i] = Tau[q_index] - model.S[i].dot(model.pA[i]);
767 unsigned int lambda = model.lambda[i];
769 SpatialVector pa = model.pA[i] + model.U[i] * model.u[i] / model.d[i];
771#ifdef RBDL_USE_CASADI_MATH
772 model.pA[lambda] += model.X_lambda[i].applyTranspose(pa);
774 model.pA[lambda].noalias() += model.X_lambda[i].applyTranspose(pa);
776 LOG <<
"pA[" << lambda <<
"] = "
777 << model.pA[lambda].transpose() << std::endl;
779 }
else if (model.mJoints[i].mDoFCount == 3
780 && model.mJoints[i].mJointType != JointTypeCustom) {
785 model.multdof3_u[i] = tau_temp
786 - model.multdof3_S[i].transpose()*model.pA[i];
789 unsigned int lambda = model.lambda[i];
793 + model.multdof3_U[i]
794 * model.multdof3_Dinv[i]
795 * model.multdof3_u[i];
797#ifdef RBDL_USE_CASADI_MATH
798 model.pA[lambda] += model.X_lambda[i].applyTranspose(pa);
800 model.pA[lambda].noalias() +=
801 model.X_lambda[i].applyTranspose(pa);
803 LOG <<
"pA[" << lambda <<
"] = "
804 << model.pA[lambda].transpose() << std::endl;
806 }
else if (model.mJoints[i].mJointType == JointTypeCustom) {
807 unsigned int kI = model.mJoints[i].custom_joint_index;
808 unsigned int dofI = model.mCustomJoints[kI]->mDoFCount;
809 VectorNd tau_temp(Tau.block(q_index,0,dofI,1));
811 model.mCustomJoints[kI]->u =
812 tau_temp - ( model.mCustomJoints[kI]->S.transpose()* model.pA[i]);
815 unsigned int lambda = model.lambda[i];
819 + ( model.mCustomJoints[kI]->U
820 * model.mCustomJoints[kI]->Dinv
821 * model.mCustomJoints[kI]->u);
823#ifdef RBDL_USE_CASADI_MATH
824 model.pA[lambda] += model.X_lambda[i].applyTranspose(pa);
826 model.pA[lambda].noalias() +=
827 model.X_lambda[i].applyTranspose(pa);
829 LOG <<
"pA[" << lambda <<
"] = "
830 << model.pA[lambda].transpose() << std::endl;
837 for (
unsigned int i = 1; i < model.mBodies.size(); i++) {
838 unsigned int q_index = model.mJoints[i].q_index;
839 unsigned int lambda = model.lambda[i];
840 SpatialTransform X_lambda = model.X_lambda[i];
842 model.a[i] = X_lambda.apply(model.a[lambda]) + model.c[i];
843 LOG <<
"a'[" << i <<
"] = " << model.a[i].transpose() << std::endl;
845 if (model.mJoints[i].mDoFCount == 1
846 && model.mJoints[i].mJointType != JointTypeCustom) {
847 QDDot[q_index] = (1./model.d[i])*(model.u[i]-model.U[i].dot(model.a[i]));
848 model.a[i] = model.a[i] + model.S[i] * QDDot[q_index];
849 }
else if (model.mJoints[i].mDoFCount == 3
850 && model.mJoints[i].mJointType != JointTypeCustom) {
852 model.multdof3_Dinv[i] * (model.multdof3_u[i]
853 - model.multdof3_U[i].transpose()*model.a[i]);
855 QDDot[q_index] = qdd_temp[0];
856 QDDot[q_index + 1] = qdd_temp[1];
857 QDDot[q_index + 2] = qdd_temp[2];
858 model.a[i] = model.a[i] + model.multdof3_S[i] * qdd_temp;
859 }
else if (model.mJoints[i].mJointType == JointTypeCustom) {
860 unsigned int kI = model.mJoints[i].custom_joint_index;
861 unsigned int dofI = model.mCustomJoints[kI]->mDoFCount;
863 VectorNd qdd_temp = model.mCustomJoints[kI]->Dinv
864 * ( model.mCustomJoints[kI]->u
865 - model.mCustomJoints[kI]->U.transpose() * model.a[i]);
867 for(
unsigned z = 0; z < dofI; ++z){
868 QDDot[q_index+z] = qdd_temp[z];
871 model.a[i] = model.a[i]
872 + model.mCustomJoints[kI]->S * qdd_temp;
876 LOG <<
"QDDot = " << QDDot.
transpose() << std::endl;
MX_Xd_dynamic transpose() const
static MX_Xd_dynamic Zero(unsigned int nrows, unsigned int ncols=1)
MX_Xd_SubMatrix block(unsigned int row_start, unsigned int col_start)
MX_Xd_SubMatrix block(unsigned int row_start, unsigned int col_start)
RBDL_DLLAPI void InverseDynamics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, Math::VectorNd &Tau, std::vector< Math::SpatialVector > *f_ext=NULL)
Computes inverse dynamics with the Newton-Euler Algorithm.
RBDL_DLLAPI void CalcMInvTimesTau(Model &model, const Math::VectorNd &Q, const Math::VectorNd &Tau, Math::VectorNd &QDDot, bool update_kinematics=true)
Computes the effect of multiplying the inverse of the joint space inertia matrix with a vector in lin...
RBDL_DLLAPI void NonlinearEffects(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::VectorNd &Tau, std::vector< Math::SpatialVector > *f_ext=NULL)
Computes the coriolis forces.
RBDL_DLLAPI void ForwardDynamicsLagrangian(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, Math::VectorNd &QDDot, Math::LinearSolver linear_solver=Math::LinearSolverColPivHouseholderQR, std::vector< Math::SpatialVector > *f_ext=NULL, Math::MatrixNd *H=NULL, Math::VectorNd *C=NULL)
Computes forward dynamics by building and solving the full Lagrangian equation.
RBDL_DLLAPI void ForwardDynamics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, Math::VectorNd &QDDot, std::vector< Math::SpatialVector > *f_ext=NULL)
Computes forward dynamics with the Articulated Body Algorithm.
RBDL_DLLAPI void CompositeRigidBodyAlgorithm(Model &model, const Math::VectorNd &Q, Math::MatrixNd &H, bool update_kinematics=true)
Computes the joint space inertia matrix by using the Composite Rigid Body Algorithm.
SpatialMatrix_t SpatialMatrix
SpatialMatrix crossf(const SpatialVector &v)
SpatialVector_t SpatialVector
SpatialMatrix crossm(const SpatialVector &v)
RBDL_DLLAPI void jcalc(Model &model, unsigned int joint_id, const VectorNd &q, const VectorNd &qdot)
RBDL_DLLAPI void jcalc_X_lambda_S(Model &model, unsigned int joint_id, const VectorNd &q)
LinearSolverColPivHouseholderQR
LinearSolverHouseholderQR