65 static const char rcsid[] =
"$Id: invkine.cpp,v 1.8 2006/05/16 16:11:15 gourdeau Exp $";
73 using namespace NEWMAT;
77 #ifdef USING_FLOAT //from newmat's include.h 86 bool converge =
false;
87 return inv_kin(Tobj, mj, dof, converge);
108 qPrev = get_available_q();
115 for(
int j = 1; j <=
NITMAX; j++) {
116 Ipd = (kine(endlink)).i()*Tobj;
123 A = jacobian(endlink,endlink);
131 for(
int k = 1; k<= dq.
nrows(); k++)
142 int adof=get_available_dof(endlink);
144 for(
int j = 1; j <=
NITMAX; j++) {
145 B = (Tobj-kine(endlink)).SubMatrix(1,3,1,4).
AsColumn();
147 for(
int i = 1; i<=dof && k<=adof; i++) {
148 if(links[i].immobile)
160 for(k = 1; k<=adof; k++)
184 for(
int i = 1; i <= dof; i++)
186 if(links[i].immobile)
188 if(links[i].get_joint_type() == 0) {
190 if(links[i].get_theta_min() > qout(i)) {
193 if(links[i].get_theta_max() < qout(i)) {
221 bool converge =
false;
222 return inv_kin(Tobj, mj, dof, converge);
237 return inv_kin_rhino(Tobj, converge);
240 return inv_kin_puma(Tobj, converge);
243 return inv_kin_schilling(Tobj, converge);
263 Real theta[6] , diff1, diff2, tmp,
264 angle , L=0.0 , M=0.0 ,
K=0.0 , H=0.0 , G=0.0 ;
267 theta[0] = atan2(Tobj(2,4),
270 theta[1] = atan2(-Tobj(2,4),
273 diff1 = fabs(q_actual(1)-theta[0]) ;
275 diff1 = 2*
M_PI - diff1;
277 diff2 = fabs(q_actual(1)-theta[1]);
279 diff2 = 2*
M_PI - diff2 ;
283 theta[1] = theta[0] ;
285 theta[5] = atan2(sin(theta[1])*Tobj(1,1) - cos(theta[1])*Tobj(2,1),
286 sin(theta[1])*Tobj(1,2) - cos(theta[1])*Tobj(2,2));
289 angle = atan2(-1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3),
292 L = cos(theta[1])*Tobj(1,4) +
293 sin(theta[1])*Tobj(2,4) +
294 links[5].d*sin(angle) -
295 links[4].a*cos(angle);
298 links[5].d*cos(angle) -
299 links[4].a*sin(angle);
300 K = (L*L + M*M - links[3].a*links[3].a -
301 links[2].a*links[2].a) /
302 (2 * links[3].
a * links[2].
a);
306 throw out_of_range(
"sqrt of negative number not allowed.");
308 theta[0] = atan2( sqrt(tmp) , K );
309 theta[3] = atan2( -sqrt(tmp) , K );
311 diff1 = fabs(q_actual(3)-theta[0]) ;
313 diff1 = 2*
M_PI - diff1 ;
315 diff2 = fabs(q_actual(3)-theta[3]);
317 diff2 = 2*
M_PI - diff2 ;
320 theta[3] = theta[0] ;
322 H = cos(theta[3]) * links[3].a + links[2].a;
323 G = sin(theta[3]) * links[3].a;
325 theta[2] = atan2( M , L ) - atan2( G , H );
326 theta[4] = atan2( -1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3) ,
327 -1*Tobj(3,3)) - theta[2] - theta[3] ;
337 catch(std::out_of_range & e)
360 Real theta[7] , diff1, diff2, tmp,
361 A = 0.0 , B = 0.0 , C = 0.0 , D =0.0, Ro = 0.0,
362 H = 0.0 , L = 0.0 , M = 0.0;
369 tmpd6(1)=0; tmpd6(2)=0; tmpd6(3)=links[6].d;
374 tmp = Tobj(2,4)*Tobj(2,4) + Tobj(1,4)*Tobj(1,4);
376 throw std::out_of_range(
"sqrt of negative number not allowed.");
379 D = (links[2].d+links[3].d) / Ro;
383 throw std::out_of_range(
"sqrt of negative number not allowed.");
386 theta[0] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D, sqrt(tmp));
388 theta[1] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D , -sqrt(tmp));
390 diff1 = fabs(q_actual(1)-theta[0]);
392 diff1 = 2*
M_PI - diff1;
394 diff2 = fabs(q_actual(1)-theta[1]);
396 diff2 = 2*
M_PI - diff2;
402 tmp = links[3].a*links[3].a + links[4].d*links[4].d;
404 throw std::out_of_range(
"sqrt of negative number not allowed.");
407 B = atan2(links[4].d,links[3].
a);
408 C = Tobj(1,4)*Tobj(1,4) +
409 Tobj(2,4)*Tobj(2,4) +
410 (Tobj(3,4)-links[1].d)*(Tobj(3,4)-links[1].d) -
411 (links[2].d + links[3].d)*(links[2].d + links[3].d) -
412 links[2].a*links[2].a -
413 links[3].a*links[3].a -
414 links[4].d*links[4].d;
415 A = C / (2*links[2].a);
419 throw std::out_of_range(
"sqrt of negative number not allowed.");
421 theta[0] = atan2(sqrt(tmp) , A/Ro) + B;
422 theta[3] = atan2(-sqrt(tmp) , A/Ro) + B;
424 diff1 = fabs(q_actual(3)-theta[0]);
426 diff1 = 2*
M_PI - diff1 ;
428 diff2 = fabs(q_actual(3)-theta[3]);
430 diff1 = 2*
M_PI - diff2;
436 H = cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4);
437 L = sin(theta[3])*links[4].d + cos(theta[3])*links[3].a + links[2].a;
438 M = cos(theta[3])*links[4].d - sin(theta[3])*links[3].a;
440 theta[2] = atan2( M , L ) - atan2(Tobj(3,4)-links[1].d , H );
442 theta[0] = atan2( -sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3) ,
443 cos(theta[2] + theta[3]) *
444 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
445 - (sin(theta[2]+theta[3])*Tobj(3,3)) );
447 theta[4] = atan2(-1*(-sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3)),
448 -cos(theta[2] + theta[3]) *
449 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
450 + (sin(theta[2]+theta[3])*Tobj(3,3)) );
452 diff1 = fabs(q_actual(4)-theta[0]);
454 diff1 = 2*
M_PI - diff1;
456 diff2 = fabs(q_actual(4)-theta[4]);
458 diff2 = 2*
M_PI - diff2;
464 theta[5] = atan2( cos(theta[4]) *
465 ( cos(theta[2] + theta[3]) *
466 (cos(theta[1]) * Tobj(1,3)
467 + sin(theta[1])*Tobj(2,3))
468 - (sin(theta[2]+theta[3])*Tobj(3,3)) ) +
469 sin(theta[4])*(-sin(theta[1])*Tobj(1,3)
470 + cos(theta[1])*Tobj(2,3)) ,
471 sin(theta[2]+theta[3]) * (cos(theta[1]) * Tobj(1,3)
472 + sin(theta[1])*Tobj(2,3) )
473 + (cos(theta[2]+theta[3])*Tobj(3,3)) );
475 theta[6] = atan2( -sin(theta[4])
476 * ( cos(theta[2] + theta[3]) *
477 (cos(theta[1]) * Tobj(1,1)
478 + sin(theta[1])*Tobj(2,1))
479 - (sin(theta[2]+theta[3])*Tobj(3,1))) +
480 cos(theta[4])*(-sin(theta[1])*Tobj(1,1)
481 + cos(theta[1])*Tobj(2,1)),
482 -sin(theta[4]) * ( cos(theta[2] + theta[3]) *
483 (cos(theta[1]) * Tobj(1,2)
484 + sin(theta[1])*Tobj(2,2))
485 - (sin(theta[2]+theta[3])*Tobj(3,2))) +
486 cos(theta[4])*(-sin(theta[1])*Tobj(1,2)
487 + cos(theta[1])*Tobj(2,2)) );
498 catch(std::out_of_range & e)
520 Real theta[7],
K=0.0, A=0.0, B=0.0, C=0.0, D=0.0, tmp=0.0, theta234 , diff1, diff2;
533 theta[1] = atan2(Tobj(2,4),Tobj(1,4));
535 theta[0] = atan2(-Tobj(2,4),-Tobj(1,4));
537 diff1 = fabs(q_actual(1)-theta[0]);
539 diff1 = 2*
M_PI - diff1;
541 diff2 = fabs(q_actual(1)-theta[1]);
543 diff2 = 2*
M_PI - diff2;
550 theta234 = atan2( Tobj(3,3) , cos(theta[1])*Tobj(1,3) + sin(theta[1])*Tobj(2,3) );
552 theta[5] = atan2( (cos(theta234)*(cos(theta[1])*Tobj(1,3) +
553 sin(theta[1])*Tobj(2,3)) + sin(theta234)*Tobj(3,3)),
554 (sin(theta[1])*Tobj(1,3) - cos(theta[1])*Tobj(2,3)));
556 theta[6] = atan2( (-sin(theta234)*(cos(theta[1])*Tobj(1,1) +
557 sin(theta[1])*Tobj(2,1)) + cos(theta234)*Tobj(3,1)),
558 (-sin(theta234)*(cos(theta[1])*Tobj(1,2) + sin(theta[1])*Tobj(2,2)) +
559 cos(theta234)*Tobj(3,2)));
561 A= cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4) - links[1].a -
562 links[4].a*cos(theta234);
564 B= Tobj(3,4) - links[1].d - links[4].a*sin(theta234);
567 K= ( A*A + B*B - (links[3].a*links[3].a) - (links[2].
a*links[2].
a) ) /
568 ( 2*links[2].a*links[3].a );
572 throw std::out_of_range(
"sqrt of negative number not allowed.");
574 theta[3] = atan2(sqrt(tmp),K);
575 theta[0] = atan2(-sqrt(tmp),K);
577 diff1 = fabs(q_actual(3)-theta[0]);
579 diff1 = 2*
M_PI - diff1;
581 diff2 = fabs(q_actual(3)-theta[3]);
583 diff2 = 2*
M_PI - diff2;
589 C = cos(theta[3])*links[3].a + links[2].a;
590 D = sin(theta[3])*links[3].a;
592 theta[2] = atan2(B,A) - atan2(D,C);
594 theta[4] = theta234 - theta[2] - theta[3];
604 catch(std::out_of_range & e)
620 bool converge =
false;
621 return inv_kin(Tobj, mj, dof, converge);
636 return inv_kin_rhino(Tobj, converge);
639 return inv_kin_puma(Tobj, converge);
642 return inv_kin_schilling(Tobj, converge);
662 Real theta[6] , diff1, diff2, tmp,
663 angle , L=0.0 , M=0.0 ,
K=0.0 , H=0.0 , G=0.0;
668 tmpd6(1)=0; tmpd6(2)=0; tmpd6(3)=links[6].d;
674 theta[0] = atan2(Tobj(2,4),
677 theta[1] = atan2(-Tobj(2,4),
680 diff1 = fabs(q_actual(1)-theta[0]) ;
682 diff1 = 2*
M_PI - diff1;
684 diff2 = fabs(q_actual(1)-theta[1]);
686 diff2 = 2*
M_PI - diff2 ;
690 theta[1] = theta[0] ;
692 theta[5] = atan2(sin(theta[1])*Tobj(1,1) - cos(theta[1])*Tobj(2,1),
693 sin(theta[1])*Tobj(1,2) - cos(theta[1])*Tobj(2,2));
696 angle = atan2(-1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3),
699 L = cos(theta[1])*Tobj(1,4) +
700 sin(theta[1])*Tobj(2,4) +
701 links[5].d*sin(angle) -
702 links[5].a*cos(angle);
705 links[5].d*cos(angle) -
706 links[5].a*sin(angle);
707 K = (L*L + M*M - links[4].a*links[4].a -
708 links[3].a*links[3].a) /
709 (2 * links[4].
a * links[4].
a);
713 throw std::out_of_range(
"sqrt of negative number not allowed.");
715 theta[0] = atan2( sqrt(tmp) , K );
716 theta[3] = atan2( -sqrt(tmp) , K );
718 diff1 = fabs(q_actual(3)-theta[0]) ;
720 diff1 = 2*
M_PI - diff1 ;
722 diff2 = fabs(q_actual(3)-theta[3]);
724 diff2 = 2*
M_PI - diff2 ;
727 theta[3] = theta[0] ;
729 H = cos(theta[3]) * links[4].a + links[3].a;
730 G = sin(theta[3]) * links[4].a;
732 theta[2] = atan2( M , L ) - atan2( G , H );
733 theta[4] = atan2( -1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3) ,
734 -1*Tobj(3,3)) - theta[2] - theta[3] ;
744 catch(std::out_of_range & e)
767 Real theta[7] , diff1, diff2, tmp,
768 A = 0.0 , B = 0.0 , C = 0.0 , D =0.0, Ro = 0.0,
769 H = 0.0 , L = 0.0 , M = 0.0;
776 tmpd6(1)=0; tmpd6(2)=0; tmpd6(3)=links[6].d;
781 tmp = Tobj(2,4)*Tobj(2,4) + Tobj(1,4)*Tobj(1,4);
783 throw std::out_of_range(
"sqrt of negative number not allowed.");
786 D = (links[2].d+links[3].d) / Ro;
790 throw std::out_of_range(
"sqrt of negative number not allowed.");
793 theta[0] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D, sqrt(tmp));
795 theta[1] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D , -sqrt(tmp));
797 diff1 = fabs(q_actual(1)-theta[0]);
799 diff1 = 2*
M_PI - diff1;
801 diff2 = fabs(q_actual(1)-theta[1]);
803 diff2 = 2*
M_PI - diff2;
809 tmp = links[4].a*links[4].a + links[4].d*links[4].d;
811 throw std::out_of_range(
"sqrt of negative number not allowed.");
814 B = atan2(links[4].d,links[4].
a);
815 C = Tobj(1,4)*Tobj(1,4) +
816 Tobj(2,4)*Tobj(2,4) +
817 (Tobj(3,4)-links[1].d)*(Tobj(3,4)-links[1].d) -
818 (links[2].d + links[3].d)*(links[2].d + links[3].d) -
819 links[3].a*links[3].a -
820 links[4].a*links[4].a -
821 links[4].d*links[4].d;
822 A = C / (2*links[3].a);
826 throw std::out_of_range(
"sqrt of negative number not allowed.");
828 theta[0] = atan2(sqrt(tmp) , A/Ro) + B;
829 theta[3] = atan2(-sqrt(tmp) , A/Ro) + B;
831 diff1 = fabs(q_actual(3)-theta[0]);
833 diff1 = 2*
M_PI - diff1 ;
835 diff2 = fabs(q_actual(3)-theta[3]);
837 diff2 = 2*
M_PI - diff2;
843 H = cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4);
844 L = sin(theta[3])*links[4].d + cos(theta[3])*links[4].a + links[3].a;
845 M = cos(theta[3])*links[4].d - sin(theta[3])*links[4].a;
847 theta[2] = atan2( M , L ) - atan2(Tobj(3,4)-links[1].d , H );
849 theta[0] = atan2( -sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3) ,
850 cos(theta[2] + theta[3]) *
851 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
852 - (sin(theta[2]+theta[3])*Tobj(3,3)) );
854 theta[4] = atan2(-1*(-sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3)),
855 -cos(theta[2] + theta[3]) *
856 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
857 + (sin(theta[2]+theta[3])*Tobj(3,3)) );
859 diff1 = fabs(q_actual(4)-theta[0]);
861 diff1 = 2*
M_PI - diff1;
863 diff2 = fabs(q_actual(4)-theta[4]);
865 diff2 = 2*
M_PI - diff2;
871 theta[5] = atan2( cos(theta[4]) *
872 ( cos(theta[2] + theta[3]) *
873 (cos(theta[1]) * Tobj(1,3)
874 + sin(theta[1])*Tobj(2,3))
875 - (sin(theta[2]+theta[3])*Tobj(3,3)) ) +
876 sin(theta[4])*(-sin(theta[1])*Tobj(1,3)
877 + cos(theta[1])*Tobj(2,3)) ,
878 sin(theta[2]+theta[3]) * (cos(theta[1]) * Tobj(1,3)
879 + sin(theta[1])*Tobj(2,3) )
880 + (cos(theta[2]+theta[3])*Tobj(3,3)) );
882 theta[6] = atan2( -sin(theta[4])
883 * ( cos(theta[2] + theta[3]) *
884 (cos(theta[1]) * Tobj(1,1)
885 + sin(theta[1])*Tobj(2,1))
886 - (sin(theta[2]+theta[3])*Tobj(3,1))) +
887 cos(theta[4])*(-sin(theta[1])*Tobj(1,1)
888 + cos(theta[1])*Tobj(2,1)),
889 -sin(theta[4]) * ( cos(theta[2] + theta[3]) *
890 (cos(theta[1]) * Tobj(1,2)
891 + sin(theta[1])*Tobj(2,2))
892 - (sin(theta[2]+theta[3])*Tobj(3,2))) +
893 cos(theta[4])*(-sin(theta[1])*Tobj(1,2)
894 + cos(theta[1])*Tobj(2,2)) );
905 catch(std::out_of_range & e)
927 Real theta[7],
K=0.0, A=0.0, B=0.0, C=0.0, D=0.0, tmp=0.0, theta234 , diff1, diff2;
940 theta[1] = atan2(Tobj(2,4),Tobj(1,4));
942 theta[0] = atan2(-Tobj(2,4),-Tobj(1,4));
944 diff1 = fabs(q_actual(1)-theta[0]);
946 diff1 = 2*
M_PI - diff1;
948 diff2 = fabs(q_actual(1)-theta[1]);
950 diff2 = 2*
M_PI - diff2;
957 theta234 = atan2( Tobj(3,3) , cos(theta[1])*Tobj(1,3) + sin(theta[1])*Tobj(2,3) );
959 theta[5] = atan2( (cos(theta234)*(cos(theta[1])*Tobj(1,3) +
960 sin(theta[1])*Tobj(2,3)) + sin(theta234)*Tobj(3,3)),
961 (sin(theta[1])*Tobj(1,3) - cos(theta[1])*Tobj(2,3)));
963 theta[6] = atan2( (-sin(theta234)*(cos(theta[1])*Tobj(1,1) +
964 sin(theta[1])*Tobj(2,1)) + cos(theta234)*Tobj(3,1)),
965 (-sin(theta234)*(cos(theta[1])*Tobj(1,2) + sin(theta[1])*Tobj(2,2)) +
966 cos(theta234)*Tobj(3,2)));
968 A= cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4) - links[2].a -
969 links[5].a*cos(theta234);
971 B= Tobj(3,4) - links[1].d - links[5].a*sin(theta234);
974 K= ( A*A + B*B - (links[4].a*links[4].a) - (links[3].
a*links[3].
a) ) /
975 ( 2*links[3].a*links[4].a );
979 throw std::out_of_range(
"sqrt of negative number not allowed.");
981 theta[3] = atan2(sqrt(tmp),K);
982 theta[0] = atan2(-sqrt(tmp),K);
984 diff1 = fabs(q_actual(3)-theta[0]);
986 diff1 = 2*
M_PI - diff1;
988 diff2 = fabs(q_actual(3)-theta[3]);
990 diff2 = 2*
M_PI - diff2;
996 C = cos(theta[3])*links[4].a + links[3].a;
997 D = sin(theta[3])*links[4].a;
999 theta[2] = atan2(B,A) - atan2(D,C);
1001 theta[4] = theta234 - theta[2] - theta[3];
1012 catch(std::out_of_range & e)
1026 bool converge =
false;
1027 return inv_kin(Tobj, mj, dof, converge);
1040 switch (robotType) {
1042 return inv_kin_rhino(Tobj, converge);
1045 return inv_kin_puma(Tobj, converge);
1065 Real theta[6] , diff1, diff2, tmp,
1066 angle , L=0.0 , M=0.0 ,
K=0.0 , H=0.0 , G=0.0 ;
1069 theta[0] = atan2(Tobj(2,4),
1072 theta[1] = atan2(-Tobj(2,4),
1075 diff1 = fabs(q_actual(1)-theta[0]) ;
1077 diff1 = 2*
M_PI - diff1;
1079 diff2 = fabs(q_actual(1)-theta[1]);
1081 diff2 = 2*
M_PI - diff2 ;
1085 theta[1] = theta[0] ;
1087 theta[5] = atan2(sin(theta[1])*Tobj(1,1) - cos(theta[1])*Tobj(2,1),
1088 sin(theta[1])*Tobj(1,2) - cos(theta[1])*Tobj(2,2));
1091 angle = atan2(-1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3),
1094 L = cos(theta[1])*Tobj(1,4) +
1095 sin(theta[1])*Tobj(2,4) +
1096 links[5].d*sin(angle) -
1097 links[5].a*cos(angle);
1100 links[5].d*cos(angle) -
1101 links[5].a*sin(angle);
1102 K = (L*L + M*M - links[4].a*links[4].a -
1103 links[3].a*links[3].a) /
1104 (2 * links[4].
a * links[4].
a);
1108 throw std::out_of_range(
"sqrt of negative number not allowed.");
1110 theta[0] = atan2( sqrt(tmp) , K );
1111 theta[3] = atan2( -sqrt(tmp) , K );
1113 diff1 = fabs(q_actual(3)-theta[0]) ;
1115 diff1 = 2*
M_PI - diff1 ;
1117 diff2 = fabs(q_actual(3)-theta[3]);
1119 diff2 = 2*
M_PI - diff2 ;
1122 theta[3] = theta[0] ;
1124 H = cos(theta[3]) * links[4].a + links[3].a;
1125 G = sin(theta[3]) * links[4].a;
1127 theta[2] = atan2( M , L ) - atan2( G , H );
1128 theta[4] = atan2( -1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3) ,
1129 -1*Tobj(3,3)) - theta[2] - theta[3] ;
1139 catch(std::out_of_range & e)
1162 Real theta[7] , diff1, diff2, tmp,
1163 A = 0.0 , B = 0.0 , C = 0.0 , D =0.0, Ro = 0.0,
1164 H = 0.0 , L = 0.0 , M = 0.0;
1171 tmpd6(1)=0; tmpd6(2)=0; tmpd6(3)=links[6].d;
1176 tmp = Tobj(2,4)*Tobj(2,4) + Tobj(1,4)*Tobj(1,4);
1178 throw std::out_of_range(
"sqrt of negative number not allowed.");
1181 D = (links[2].d+links[3].d) / Ro;
1185 throw std::out_of_range(
"sqrt of negative number not allowed.");
1188 theta[0] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D, sqrt(tmp));
1190 theta[1] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D , -sqrt(tmp));
1192 diff1 = fabs(q_actual(1)-theta[0]);
1194 diff1 = 2*
M_PI - diff1;
1196 diff2 = fabs(q_actual(1)-theta[1]);
1198 diff2 = 2*
M_PI - diff2;
1202 theta[1] = theta[0];
1204 tmp = links[4].a*links[4].a + links[4].d*links[4].d;
1206 throw std::out_of_range(
"sqrt of negative number not allowed.");
1209 B = atan2(links[4].
d,links[4].
a);
1210 C = Tobj(1,4)*Tobj(1,4) +
1211 Tobj(2,4)*Tobj(2,4) +
1212 (Tobj(3,4)-links[1].d)*(Tobj(3,4)-links[1].d) -
1213 (links[2].d + links[3].d)*(links[2].d + links[3].d) -
1214 links[3].a*links[3].a -
1215 links[4].a*links[4].a -
1216 links[4].d*links[4].d;
1217 A = C / (2*links[3].a);
1221 throw std::out_of_range(
"sqrt of negative number not allowed.");
1223 theta[0] = atan2(sqrt(tmp) , A/Ro) + B;
1224 theta[3] = atan2(-sqrt(tmp) , A/Ro) + B;
1226 diff1 = fabs(q_actual(3)-theta[0]);
1228 diff1 = 2*
M_PI - diff1 ;
1230 diff2 = fabs(q_actual(3)-theta[3]);
1232 diff2 = 2*
M_PI - diff2;
1236 theta[3] = theta[0];
1238 H = cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4);
1239 L = sin(theta[3])*links[4].d + cos(theta[3])*links[4].a + links[3].a;
1240 M = cos(theta[3])*links[4].d - sin(theta[3])*links[4].a;
1242 theta[2] = atan2( M , L ) - atan2(Tobj(3,4)-links[1].d , H );
1244 theta[0] = atan2( -sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3) ,
1245 cos(theta[2] + theta[3]) *
1246 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
1247 - (sin(theta[2]+theta[3])*Tobj(3,3)) );
1249 theta[4] = atan2(-1*(-sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3)),
1250 -cos(theta[2] + theta[3]) *
1251 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
1252 + (sin(theta[2]+theta[3])*Tobj(3,3)) );
1254 diff1 = fabs(q_actual(4)-theta[0]);
1256 diff1 = 2*
M_PI - diff1;
1258 diff2 = fabs(q_actual(4)-theta[4]);
1260 diff2 = 2*
M_PI - diff2;
1264 theta[4] = theta[0];
1266 theta[5] = atan2( cos(theta[4]) *
1267 ( cos(theta[2] + theta[3]) *
1268 (cos(theta[1]) * Tobj(1,3)
1269 + sin(theta[1])*Tobj(2,3))
1270 - (sin(theta[2]+theta[3])*Tobj(3,3)) ) +
1271 sin(theta[4])*(-sin(theta[1])*Tobj(1,3)
1272 + cos(theta[1])*Tobj(2,3)) ,
1273 sin(theta[2]+theta[3]) * (cos(theta[1]) * Tobj(1,3)
1274 + sin(theta[1])*Tobj(2,3) )
1275 + (cos(theta[2]+theta[3])*Tobj(3,3)) );
1277 theta[6] = atan2( -sin(theta[4])
1278 * ( cos(theta[2] + theta[3]) *
1279 (cos(theta[1]) * Tobj(1,1)
1280 + sin(theta[1])*Tobj(2,1))
1281 - (sin(theta[2]+theta[3])*Tobj(3,1))) +
1282 cos(theta[4])*(-sin(theta[1])*Tobj(1,1)
1283 + cos(theta[1])*Tobj(2,1)),
1284 -sin(theta[4]) * ( cos(theta[2] + theta[3]) *
1285 (cos(theta[1]) * Tobj(1,2)
1286 + sin(theta[1])*Tobj(2,2))
1287 - (sin(theta[2]+theta[3])*Tobj(3,2))) +
1288 cos(theta[4])*(-sin(theta[1])*Tobj(1,2)
1289 + cos(theta[1])*Tobj(2,2)) );
1300 catch(std::out_of_range & e)
1323 Real theta[7],
K=0.0, A=0.0, B=0.0, C=0.0, D=0.0, tmp=0.0, theta234 , diff1, diff2;
1331 tmpd6(3)=links[6].d;
1336 theta[1] = atan2(Tobj(2,4),Tobj(1,4));
1338 theta[0] = atan2(-Tobj(2,4),-Tobj(1,4));
1340 diff1 = fabs(q_actual(1)-theta[0]);
1342 diff1 = 2*
M_PI - diff1;
1344 diff2 = fabs(q_actual(1)-theta[1]);
1346 diff2 = 2*
M_PI - diff2;
1350 theta[1] = theta[0];
1353 theta234 = atan2( Tobj(3,3) , cos(theta[1])*Tobj(1,3) + sin(theta[1])*Tobj(2,3) );
1355 theta[5] = atan2( (cos(theta234)*(cos(theta[1])*Tobj(1,3) +
1356 sin(theta[1])*Tobj(2,3)) + sin(theta234)*Tobj(3,3)),
1357 (sin(theta[1])*Tobj(1,3) - cos(theta[1])*Tobj(2,3)));
1359 theta[6] = atan2( (-sin(theta234)*(cos(theta[1])*Tobj(1,1) +
1360 sin(theta[1])*Tobj(2,1)) + cos(theta234)*Tobj(3,1)),
1361 (-sin(theta234)*(cos(theta[1])*Tobj(1,2) + sin(theta[1])*Tobj(2,2)) +
1362 cos(theta234)*Tobj(3,2)));
1364 A= cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4) - links[2].a -
1365 links[5].a*cos(theta234);
1367 B= Tobj(3,4) - links[1].d - links[5].a*sin(theta234);
1370 K= ( A*A + B*B - (links[4].a*links[4].a) - (links[3].
a*links[3].
a) ) /
1371 ( 2*links[3].a*links[4].a );
1375 throw std::out_of_range(
"sqrt of negative number not allowed.");
1377 theta[3] = atan2(sqrt(tmp),K);
1378 theta[0] = atan2(-sqrt(tmp),K);
1380 diff1 = fabs(q_actual(3)-theta[0]);
1382 diff1 = 2*
M_PI - diff1;
1384 diff2 = fabs(q_actual(3)-theta[3]);
1386 diff2 = 2*
M_PI - diff2;
1390 theta[3] = theta[0];
1392 C = cos(theta[3])*links[4].a + links[3].a;
1393 D = sin(theta[3])*links[4].a;
1395 theta[2] = atan2(B,A) - atan2(D,C);
1397 theta[4] = theta234 - theta[2] - theta[3];
1408 catch(std::out_of_range & e)
1419 #ifdef use_namespace virtual ReturnMatrix inv_kin_schilling(const Matrix &Tobj, bool &converge)
Analytic Schilling inverse kinematics.
static const char rcsid[]
RCS/CVS version.
virtual ReturnMatrix inv_kin_rhino(const Matrix &Tobj, bool &converge)
Analytic Rhino inverse kinematics.
virtual ReturnMatrix inv_kin_puma(const Matrix &Tobj, bool &converge)
Analytic Puma inverse kinematics.
Robots class definitions.
#define ITOL
def tolerance for the end of iterations in inv_kin
virtual ReturnMatrix inv_kin_schilling(const Matrix &Tobj, bool &converge)
Analytic Schilling inverse kinematics.
ReturnMatrix inv_kin(const Matrix &Tobj, const int mj=0)
Overload inv_kin function.
Real MaximumAbsoluteValue() const
virtual ReturnMatrix inv_kin_puma(const Matrix &Tobj, bool &converge)
Analytic Puma inverse kinematics.
virtual ReturnMatrix inv_kin_puma(const Matrix &Tobj, bool &converge)
Analytic Puma inverse kinematics.
ReturnMatrix inv_kin(const Matrix &Tobj, const int mj=0)
Overload inv_kin function.
The usual rectangular matrix.
FloatVector FloatVector * a
void QRZ(Matrix &X, UpperTriangularMatrix &U)
GetSubMatrix SubMatrix(int fr, int lr, int fc, int lc) const
virtual ReturnMatrix inv_kin(const Matrix &Tobj, const int mj=0)
Numerical inverse kinematics. See inv_kin(const Matrix & Tobj, const int mj, const int endlink...
virtual ReturnMatrix inv_kin_schilling(const Matrix &Tobj, bool &converge)
Analytic Schilling inverse kinematics.
ColedMatrix AsColumn() const
#define NITMAX
def maximum number of iterations in inv_kin
ReturnMatrix inv_kin(const Matrix &Tobj, const int mj=0)
Overload inv_kin function.
virtual ReturnMatrix inv_kin_rhino(const Matrix &Tobj, bool &converge)
Analytic Rhino inverse kinematics.
virtual ReturnMatrix inv_kin_rhino(const Matrix &Tobj, bool &converge)
Analytic Rhino inverse kinematics.