75 using namespace NEWMAT;
83 ColumnVector torque(dof);
85 for(
int i = 1; i <= dof; i++) {
86 for(
int j = 1; j <= dof; j++) {
87 torque(j) = (i == j ? 1.0 : 0.0);
89 torque = torque_novelocity(torque);
92 M.Release();
return M;
97 const ColumnVector & qp,
98 const ColumnVector & tau_cmd)
101 ColumnVector qpp(dof);
103 qpp = inertia(q).i()*(tau_cmd-torque(q,qp,qpp));
109 const ColumnVector & tau_cmd,
const ColumnVector & Fext,
110 const ColumnVector & Next)
124 ColumnVector qpp(dof);
126 qpp = inertia(q).i()*(tau_cmd-torque(q, qp, qpp, Fext, Next));
132 const ColumnVector & qpp)
138 ColumnVector Fext(3), Next(3);
141 return torque(q, qp, qpp, Fext, Next);
145 const ColumnVector & qpp,
const ColumnVector & Fext,
146 const ColumnVector & Next)
213 ColumnVector ltorque(dof);
215 if(q.Nrows() != dof) error(
"q has wrong dimension");
216 if(qp.Nrows() != dof) error(
"qp has wrong dimension");
217 if(qpp.Nrows() != dof) error(
"qpp has wrong dimension");
222 for(i = 1; i <= dof; i++) {
224 if(links[i].get_joint_type() == 0) {
225 w[i] = Rt*(w[i-1] + z0*qp(i));
226 wp[i] = Rt*(wp[i-1] + z0*qpp(i)
227 + CrossProduct(w[i-1],z0*qp(i)));
228 vp[i] = CrossProduct(wp[i],p[i])
229 + CrossProduct(w[i],CrossProduct(w[i],p[i]))
234 vp[i] = Rt*(vp[i-1] + z0*qpp(i))
235 + 2.0*CrossProduct(w[i],Rt*z0*qp(i))
236 + CrossProduct(wp[i],p[i])
237 + CrossProduct(w[i],CrossProduct(w[i],p[i]));
239 a[i] = CrossProduct(wp[i],links[i].r)
240 + CrossProduct(w[i],CrossProduct(w[i],links[i].r))
244 for(i = dof; i >= 1; i--) {
245 F[i] = a[i] * links[i].m;
246 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i]);
249 n[i] = CrossProduct(p[i],f[i])
250 + CrossProduct(links[i].r,F[i]) + N[i] + Next;
252 f[i] = links[i+1].R*f[i+1] + F[i];
253 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i],f[i])
254 + CrossProduct(links[i].r,F[i]) + N[i];
256 if(links[i].get_joint_type() == 0)
257 temp = ((z0.t()*links[i].R)*n[i]);
259 temp = ((z0.t()*links[i].R)*f[i]);
260 ltorque(i) = temp(1,1)
261 + links[i].Im*links[i].Gr*links[i].Gr*qpp(i)
262 + links[i].Gr*(links[i].Gr*links[i].B*qp(i) + links[i].Cf*
sign(qp(i)));
265 ltorque.Release();
return ltorque;
275 ColumnVector ltorque(dof);
277 if(qpp.Nrows() != dof) error(
"qpp has wrong dimension");
280 for(i = 1; i <= dof; i++) {
282 if(links[i].get_joint_type() == 0) {
283 wp[i] = Rt*(wp[i-1] + z0*qpp(i));
284 vp[i] = CrossProduct(wp[i],p[i])
288 vp[i] = Rt*(vp[i-1] + z0*qpp(i))
289 + CrossProduct(wp[i],p[i]);
291 a[i] = CrossProduct(wp[i],links[i].r) + vp[i];
294 for(i = dof; i >= 1; i--) {
295 F[i] = a[i] * links[i].m;
296 N[i] = links[i].I*wp[i];
299 n_nv[i] = CrossProduct(p[i],f_nv[i])
300 + CrossProduct(links[i].r,F[i]) + N[i];
302 f_nv[i] = links[i+1].R*f_nv[i+1] + F[i];
303 n_nv[i] = links[i+1].R*n_nv[i+1] + CrossProduct(p[i],f_nv[i])
304 + CrossProduct(links[i].r,F[i]) + N[i];
306 if(links[i].get_joint_type() == 0)
307 temp = ((z0.t()*links[i].R)*n_nv[i]);
309 temp = ((z0.t()*links[i].R)*f_nv[i]);
310 ltorque(i) = temp(1,1) + links[i].Im*links[i].Gr*links[i].Gr*qpp(i);
314 ltorque.Release();
return ltorque;
321 ColumnVector ltorque(dof);
325 for(i = 1; i <= dof; i++) {
327 if(links[i].get_joint_type() == 0)
328 vp[i] = Rt*(vp[i-1]);
335 for(i = dof; i >= 1; i--) {
336 F[i] = a[i] * links[i].m;
339 n[i] = CrossProduct(p[i],f[i])
340 + CrossProduct(links[i].r,F[i]);
342 f[i] = links[i+1].R*f[i+1] + F[i];
343 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i],f[i])
344 + CrossProduct(links[i].r,F[i]);
346 if(links[i].get_joint_type() == 0)
347 temp = ((z0.t()*links[i].R)*n[i]);
349 temp = ((z0.t()*links[i].R)*f[i]);
350 ltorque(i) = temp(1,1);
353 ltorque.Release();
return ltorque;
360 ColumnVector ltorque(dof);
362 if(qp.Nrows() != dof) error(
"qp has wrong dimension");
365 for(i = 1; i <= dof; i++) {
367 if(links[i].get_joint_type() == 0) {
368 w[i] = Rt*(w[i-1] + z0*qp(i));
369 wp[i] = Rt*(wp[i-1] + CrossProduct(w[i-1],z0*qp(i)));
370 vp[i] = CrossProduct(wp[i],p[i])
371 + CrossProduct(w[i],CrossProduct(w[i],p[i]))
376 vp[i] = Rt*vp[i-1] + 2.0*CrossProduct(w[i],Rt*z0*qp(i))
377 + CrossProduct(wp[i],p[i])
378 + CrossProduct(w[i],CrossProduct(w[i],p[i]));
380 a[i] = CrossProduct(wp[i],links[i].r)
381 + CrossProduct(w[i],CrossProduct(w[i],links[i].r))
385 for(i = dof; i >= 1; i--) {
386 F[i] = a[i] * links[i].m;
387 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i]);
390 n[i] = CrossProduct(p[i],f[i])
391 + CrossProduct(links[i].r,F[i]) + N[i];
393 f[i] = links[i+1].R*f[i+1] + F[i];
394 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i],f[i])
395 + CrossProduct(links[i].r,F[i]) + N[i];
397 if(links[i].get_joint_type() == 0)
398 temp = ((z0.t()*links[i].R)*n[i]);
400 temp = ((z0.t()*links[i].R)*f[i]);
401 ltorque(i) = temp(1,1)
402 + links[i].Gr*(links[i].Gr*links[i].B*qp(i) + links[i].Cf*
sign(qp(i)));
405 ltorque.Release();
return ltorque;
409 const ColumnVector & qpp)
412 ColumnVector Fext(3), Next(3);
415 return torque(q, qp, qpp, Fext, Next);
419 const ColumnVector & qpp,
const ColumnVector & Fext_,
420 const ColumnVector & Next_)
485 ColumnVector ltorque(dof);
487 if(q.Nrows() != dof) error(
"q has wrong dimension");
488 if(qp.Nrows() != dof) error(
"qp has wrong dimension");
489 if(qpp.Nrows() != dof) error(
"qpp has wrong dimension");
494 for(i = 1; i <= dof; i++) {
496 if(links[i].get_joint_type() == 0) {
497 w[i] = Rt*w[i-1] + z0*qp(i);
498 wp[i] = Rt*wp[i-1] + CrossProduct(Rt*w[i-1],z0*qp(i))
500 vp[i] = Rt*(CrossProduct(wp[i-1],p[i])
501 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i]))
506 vp[i] = Rt*(vp[i-1] + CrossProduct(wp[i-1],p[i])
507 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i])))
508 + z0*qpp(i)+ 2.0*CrossProduct(w[i],z0*qp(i));
510 a[i] = CrossProduct(wp[i],links[i].r)
511 + CrossProduct(w[i],CrossProduct(w[i],links[i].r))
516 ColumnVector Fext(3), Next(3);
519 Fext = links[dof+fix].R*Fext_;
520 Next = links[dof+fix].R*Next_;
528 for(i = dof; i >= 1; i--) {
529 F[i] = a[i] * links[i].m;
530 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i]);
533 n[i] = CrossProduct(links[i].r,F[i]) + N[i] + Next;
535 f[i] = links[i+1].R*f[i+1] + F[i];
536 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i+1],links[i+1].R*f[i+1])
537 + CrossProduct(links[i].r,F[i]) + N[i];
539 if(links[i].get_joint_type() == 0)
540 temp = (z0.t()*n[i]);
542 temp = (z0.t()*f[i]);
543 ltorque(i) = temp(1,1)
544 + links[i].Im*links[i].Gr*links[i].Gr*qpp(i)
545 + links[i].Gr*(links[i].Gr*links[i].B*qp(i) + links[i].Cf*
sign(qp(i)));
548 ltorque.Release();
return ltorque;
555 ColumnVector ltorque(dof);
557 if(qpp.Ncols() != 1 || qpp.Nrows() != dof) error(
"qpp has wrong dimension");
560 for(i = 1; i <= dof; i++) {
562 if(links[i].get_joint_type() == 0) {
563 wp[i] = Rt*wp[i-1] + z0*qpp(i);
564 vp[i] = Rt*(CrossProduct(wp[i-1],p[i]) + vp[i-1]);
567 vp[i] = Rt*(vp[i-1] + CrossProduct(wp[i-1],p[i]))
570 a[i] = CrossProduct(wp[i],links[i].r) + vp[i];
573 for(i = dof; i >= 1; i--) {
574 F[i] = a[i] * links[i].m;
575 N[i] = links[i].I*wp[i];
578 n_nv[i] = CrossProduct(links[i].r,F[i]) + N[i];
580 f_nv[i] = links[i+1].R*f_nv[i+1] + F[i];
581 n_nv[i] = links[i+1].R*n_nv[i+1] + CrossProduct(p[i+1],links[i+1].R*f_nv[i+1])
582 + CrossProduct(links[i].r,F[i]) + N[i];
585 if(links[i].get_joint_type() == 0)
586 temp = (z0.t()*n_nv[i]);
588 temp = (z0.t()*f_nv[i]);
589 ltorque(i) = temp(1,1) + links[i].Im*links[i].Gr*links[i].Gr*qpp(i);
592 ltorque.Release();
return ltorque;
599 ColumnVector ltorque(dof);
603 for(i = 1; i <= dof; i++) {
605 if(links[i].get_joint_type() == 0)
612 for(i = dof; i >= 1; i--) {
613 F[i] = a[i] * links[i].m;
616 n[i] = CrossProduct(links[i].r,F[i]);
618 f[i] = links[i+1].R*f[i+1] + F[i];
619 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i+1],links[i+1].R*f[i+1])
620 + CrossProduct(links[i].r,F[i]);
622 if(links[i].get_joint_type() == 0)
623 temp = (z0.t()*n[i]);
625 temp = (z0.t()*f[i]);
626 ltorque(i) = temp(1,1);
629 ltorque.Release();
return ltorque;
636 ColumnVector ltorque(dof);
638 if(qp.Nrows() != dof) error(
"qp has wrong dimension");
641 for(i = 1; i <= dof; i++) {
643 if(links[i].get_joint_type() == 0) {
644 w[i] = Rt*w[i-1] + z0*qp(i);
645 wp[i] = Rt*wp[i-1] + CrossProduct(Rt*w[i-1],z0*qp(i));
646 vp[i] = Rt*(CrossProduct(wp[i-1],p[i])
647 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i]))
652 vp[i] = Rt*(vp[i-1] + CrossProduct(wp[i-1],p[i])
653 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i])))
654 + 2.0*CrossProduct(w[i],z0*qp(i));
656 a[i] = CrossProduct(wp[i],links[i].r)
657 + CrossProduct(w[i],CrossProduct(w[i],links[i].r))
661 for(i = dof; i >= 1; i--) {
662 F[i] = a[i] * links[i].m;
663 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i]);
666 n[i] = CrossProduct(links[i].r,F[i]) + N[i];
668 f[i] = links[i+1].R*f[i+1] + F[i];
669 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i+1],links[i+1].R*f[i+1])
670 + CrossProduct(links[i].r,F[i]) + N[i];
672 if(links[i].get_joint_type() == 0)
673 temp = (z0.t()*n[i]);
675 temp = (z0.t()*f[i]);
676 ltorque(i) = temp(1,1)
677 + links[i].Gr*(links[i].Gr*links[i].B*qp(i) + links[i].Cf*
sign(qp(i)));
680 ltorque.Release();
return ltorque;
684 const ColumnVector & qpp)
687 ColumnVector Fext(3), Next(3);
690 return torque(q, qp, qpp, Fext, Next);
694 const ColumnVector & qpp,
const ColumnVector & Fext_,
695 const ColumnVector & Next_)
706 ColumnVector ltorque(dof);
708 if(q.Nrows() != dof) error(
"q has wrong dimension");
709 if(qp.Nrows() != dof) error(
"qp has wrong dimension");
710 if(qpp.Nrows() != dof) error(
"qpp has wrong dimension");
715 for(i = 1; i <= dof; i++) {
717 if(links[i].get_joint_type() == 0)
719 w[i] = Rt*w[i-1] + z0*qp(i);
720 wp[i] = Rt*(wp[i-1] + CrossProduct(w[i-1],z0*qp(i)))
722 vp[i] = Rt*(CrossProduct(wp[i-1],p[i])
723 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i]))
730 vp[i] = Rt*(vp[i-1] + CrossProduct(wp[i-1],p[i])
731 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i])))
732 + z0*qpp(i)+ 2.0*CrossProduct(w[i],z0*qp(i));
736 ColumnVector Fext(3), Next(3);
739 Fext = links[dof+fix].R*Fext_;
740 Next = links[dof+fix].R*Next_;
748 for(i = dof; i >= 1; i--)
750 F[i] = vp[i]*links[i].m + CrossProduct(wp[i], links[i].mc) +
751 CrossProduct(w[i], CrossProduct(w[i], links[i].mc));
752 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i]) +
753 CrossProduct(-vp[i], links[i].mc);
761 f[i] = links[i+1].R*f[i+1] + F[i];
762 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i+1],links[i+1].R*f[i+1]) + N[i];
765 if(links[i].get_joint_type() == 0)
766 temp = (z0.t()*n[i]);
768 temp = (z0.t()*f[i]);
769 ltorque(i) = temp(1,1)
770 + links[i].Im*links[i].Gr*links[i].Gr*qpp(i)
771 + links[i].Gr*(links[i].Gr*links[i].B*qp(i) + links[i].Cf*
sign(qp(i)));
774 ltorque.Release();
return ltorque;
782 ColumnVector ltorque(dof);
784 if(qpp.Ncols() != 1 || qpp.Nrows() != dof) error(
"qpp has wrong dimension");
787 for(i = 1; i <= dof; i++)
790 if(links[i].get_joint_type() == 0)
792 wp[i] = Rt*wp[i-1] + z0*qpp(i);
793 vp[i] = Rt*(CrossProduct(wp[i-1],p[i]) + vp[i-1]);
798 vp[i] = Rt*(vp[i-1] + CrossProduct(wp[i-1],p[i]))
803 for(i = dof; i >= 1; i--)
805 F[i] = vp[i]*links[i].m + CrossProduct(wp[i], links[i].mc);
806 N[i] = links[i].I*wp[i] + CrossProduct(-vp[i], links[i].mc);
814 f_nv[i] = links[i+1].R*f_nv[i+1] + F[i];
815 n_nv[i] = links[i+1].R*n_nv[i+1] + CrossProduct(p[i+1],links[i+1].R*f_nv[i+1]) + N[i];
818 if(links[i].get_joint_type() == 0)
819 temp = (z0.t()*n_nv[i]);
821 temp = (z0.t()*f_nv[i]);
822 ltorque(i) = temp(1,1) + links[i].Im*links[i].Gr*links[i].Gr*qpp(i);
825 ltorque.Release();
return ltorque;
832 ColumnVector ltorque(dof);
836 for(i = 1; i <= dof; i++) {
838 if(links[i].get_joint_type() == 0)
844 for(i = dof; i >= 1; i--)
846 F[i] = vp[i]*links[i].m;
847 N[i] = CrossProduct(-vp[i], links[i].mc);
855 f[i] = links[i+1].R*f[i+1] + F[i];
856 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i+1],links[i+1].R*f[i+1]) + N[i];
859 if(links[i].get_joint_type() == 0)
860 temp = (z0.t()*n[i]);
862 temp = (z0.t()*f[i]);
863 ltorque(i) = temp(1,1);
866 ltorque.Release();
return ltorque;
873 ColumnVector ltorque(dof);
875 if(qp.Nrows() != dof) error(
"qp has wrong dimension");
879 for(i = 1; i <= dof; i++) {
881 if(links[i].get_joint_type() == 0)
883 w[i] = Rt*w[i-1] + z0*qp(i);
884 wp[i] = Rt*(wp[i-1] + CrossProduct(w[i-1],z0*qp(i)));
885 vp[i] = Rt*(CrossProduct(wp[i-1],p[i])
886 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i]))
893 vp[i] = Rt*(vp[i-1] + CrossProduct(wp[i-1],p[i])
894 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i])))
895 + 2.0*CrossProduct(w[i],z0*qp(i));
899 for(i = dof; i >= 1; i--)
901 F[i] = vp[i]*links[i].m + CrossProduct(wp[i], links[i].mc) +
902 CrossProduct(w[i], CrossProduct(w[i], links[i].mc));
903 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i]) +
904 CrossProduct(-vp[i], links[i].mc);
912 f[i] = links[i+1].R*f[i+1] + F[i];
913 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i+1],links[i+1].R*f[i+1]) + N[i];
916 if(links[i].get_joint_type() == 0)
917 temp = (z0.t()*n[i]);
919 temp = (z0.t()*f[i]);
920 ltorque(i) = temp(1,1)
921 + links[i].Gr*(links[i].Gr*links[i].B*qp(i) + links[i].Cf*
sign(qp(i)));
924 ltorque.Release();
return ltorque;