69 using namespace NEWMAT;
73 #ifdef USING_FLOAT //from newmat's include.h
82 bool converge =
false;
83 return inv_kin(Tobj, mj, dof, converge);
100 ColumnVector qPrev, qout, dq, q_tmp;
102 UpperTriangularMatrix U;
104 qPrev = get_available_q();
110 Matrix Ipd, A, B(6,1);
111 for(
int j = 1; j <=
NITMAX; j++) {
112 Ipd = (kine(endlink)).i()*Tobj;
119 A = jacobian(endlink,endlink);
124 while(dq.MaximumAbsoluteValue() > 1)
127 for(
int k = 1; k<= dq.nrows(); k++)
131 if (dq.MaximumAbsoluteValue() <
ITOL)
138 int adof=get_available_dof(endlink);
140 for(
int j = 1; j <=
NITMAX; j++) {
141 B = (Tobj-kine(endlink)).SubMatrix(1,3,1,4).AsColumn();
143 for(
int i = 1; i<=dof && k<=adof; i++) {
144 if(links[i].immobile)
146 A.SubMatrix(1,12,k,k) = dTdqi(i).SubMatrix(1,3,1,4).AsColumn();
153 while(dq.MaximumAbsoluteValue() > 1)
156 for(k = 1; k<=adof; k++)
159 if (dq.MaximumAbsoluteValue() <
ITOL)
171 for(
int i = 1; i <= dof; i++)
173 if(links[i].immobile)
175 if(links[i].get_joint_type() == 0) {
177 qout(iNotImm) = fmod(qout(iNotImm), 2*M_PI);
197 bool converge =
false;
198 return inv_kin(Tobj, mj, dof, converge);
202 ReturnMatrix
Robot::inv_kin(
const Matrix & Tobj,
const int mj,
const int endlink,
bool & converge)
213 return inv_kin_rhino(Tobj, converge);
216 return inv_kin_puma(Tobj, converge);
219 return inv_kin_schilling(Tobj, converge);
234 ColumnVector qout(5), q_actual;
239 Real theta[6] , diff1, diff2, tmp,
240 angle , L=0.0 , M=0.0 , K=0.0 , H=0.0 , G=0.0 ;
243 theta[0] = atan2(Tobj(2,4),
246 theta[1] = atan2(-Tobj(2,4),
249 diff1 = fabs(q_actual(1)-theta[0]) ;
251 diff1 = 2*M_PI - diff1;
253 diff2 = fabs(q_actual(1)-theta[1]);
255 diff2 = 2*M_PI - diff2 ;
259 theta[1] = theta[0] ;
261 theta[5] = atan2(sin(theta[1])*Tobj(1,1) - cos(theta[1])*Tobj(2,1),
262 sin(theta[1])*Tobj(1,2) - cos(theta[1])*Tobj(2,2));
265 angle = atan2(-1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3),
268 L = cos(theta[1])*Tobj(1,4) +
269 sin(theta[1])*Tobj(2,4) +
270 links[5].d*sin(angle) -
271 links[4].a*cos(angle);
274 links[5].d*cos(angle) -
275 links[4].a*sin(angle);
276 K = (L*L + M*M - links[3].a*links[3].a -
277 links[2].a*links[2].a) /
278 (2 * links[3].a * links[2].a);
282 throw out_of_range(
"sqrt of negative number not allowed.");
284 theta[0] = atan2( sqrt(tmp) , K );
285 theta[3] = atan2( -sqrt(tmp) , K );
287 diff1 = fabs(q_actual(3)-theta[0]) ;
289 diff1 = 2*M_PI - diff1 ;
291 diff2 = fabs(q_actual(3)-theta[3]);
293 diff2 = 2*M_PI - diff2 ;
296 theta[3] = theta[0] ;
298 H = cos(theta[3]) * links[3].a + links[2].a;
299 G = sin(theta[3]) * links[3].a;
301 theta[2] = atan2( M , L ) - atan2( G , H );
302 theta[4] = atan2( -1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3) ,
303 -1*Tobj(3,3)) - theta[2] - theta[3] ;
313 catch(std::out_of_range & e)
331 ColumnVector qout(6), q_actual;
336 Real theta[7] , diff1, diff2, tmp,
337 A = 0.0 , B = 0.0 , C = 0.0 , D =0.0, Ro = 0.0,
338 H = 0.0 , L = 0.0 , M = 0.0;
344 ColumnVector tmpd6(3); Matrix tmp;
345 tmpd6(1)=0; tmpd6(2)=0; tmpd6(3)=links[6].d;
346 tmpd6 = Tobj.SubMatrix(1,3,1,3)*tmpd6;
347 Tobj.SubMatrix(1,3,4,4) = Tobj.SubMatrix(1,3,4,4) - tmpd6;
350 tmp = Tobj(2,4)*Tobj(2,4) + Tobj(1,4)*Tobj(1,4);
352 throw std::out_of_range(
"sqrt of negative number not allowed.");
355 D = (links[2].d+links[3].d) / Ro;
359 throw std::out_of_range(
"sqrt of negative number not allowed.");
362 theta[0] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D, sqrt(tmp));
364 theta[1] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D , -sqrt(tmp));
366 diff1 = fabs(q_actual(1)-theta[0]);
368 diff1 = 2*M_PI - diff1;
370 diff2 = fabs(q_actual(1)-theta[1]);
372 diff2 = 2*M_PI - diff2;
378 tmp = links[3].a*links[3].a + links[4].d*links[4].d;
380 throw std::out_of_range(
"sqrt of negative number not allowed.");
383 B = atan2(links[4].d,links[3].a);
384 C = Tobj(1,4)*Tobj(1,4) +
385 Tobj(2,4)*Tobj(2,4) +
386 (Tobj(3,4)-links[1].d)*(Tobj(3,4)-links[1].d) -
387 (links[2].d + links[3].d)*(links[2].d + links[3].d) -
388 links[2].a*links[2].a -
389 links[3].a*links[3].a -
390 links[4].d*links[4].d;
391 A = C / (2*links[2].a);
395 throw std::out_of_range(
"sqrt of negative number not allowed.");
397 theta[0] = atan2(sqrt(tmp) , A/Ro) + B;
398 theta[3] = atan2(-sqrt(tmp) , A/Ro) + B;
400 diff1 = fabs(q_actual(3)-theta[0]);
402 diff1 = 2*M_PI - diff1 ;
404 diff2 = fabs(q_actual(3)-theta[3]);
406 diff1 = 2*M_PI - diff2;
412 H = cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4);
413 L = sin(theta[3])*links[4].d + cos(theta[3])*links[3].a + links[2].a;
414 M = cos(theta[3])*links[4].d - sin(theta[3])*links[3].a;
416 theta[2] = atan2( M , L ) - atan2(Tobj(3,4)-links[1].d , H );
418 theta[0] = atan2( -sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3) ,
419 cos(theta[2] + theta[3]) *
420 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
421 - (sin(theta[2]+theta[3])*Tobj(3,3)) );
423 theta[4] = atan2(-1*(-sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3)),
424 -cos(theta[2] + theta[3]) *
425 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
426 + (sin(theta[2]+theta[3])*Tobj(3,3)) );
428 diff1 = fabs(q_actual(4)-theta[0]);
430 diff1 = 2*M_PI - diff1;
432 diff2 = fabs(q_actual(4)-theta[4]);
434 diff2 = 2*M_PI - diff2;
440 theta[5] = atan2( cos(theta[4]) *
441 ( cos(theta[2] + theta[3]) *
442 (cos(theta[1]) * Tobj(1,3)
443 + sin(theta[1])*Tobj(2,3))
444 - (sin(theta[2]+theta[3])*Tobj(3,3)) ) +
445 sin(theta[4])*(-sin(theta[1])*Tobj(1,3)
446 + cos(theta[1])*Tobj(2,3)) ,
447 sin(theta[2]+theta[3]) * (cos(theta[1]) * Tobj(1,3)
448 + sin(theta[1])*Tobj(2,3) )
449 + (cos(theta[2]+theta[3])*Tobj(3,3)) );
451 theta[6] = atan2( -sin(theta[4])
452 * ( cos(theta[2] + theta[3]) *
453 (cos(theta[1]) * Tobj(1,1)
454 + sin(theta[1])*Tobj(2,1))
455 - (sin(theta[2]+theta[3])*Tobj(3,1))) +
456 cos(theta[4])*(-sin(theta[1])*Tobj(1,1)
457 + cos(theta[1])*Tobj(2,1)),
458 -sin(theta[4]) * ( cos(theta[2] + theta[3]) *
459 (cos(theta[1]) * Tobj(1,2)
460 + sin(theta[1])*Tobj(2,2))
461 - (sin(theta[2]+theta[3])*Tobj(3,2))) +
462 cos(theta[4])*(-sin(theta[1])*Tobj(1,2)
463 + cos(theta[1])*Tobj(2,2)) );
474 catch(std::out_of_range & e)
491 ColumnVector qout(6), q_actual;
496 Real theta[7], K=0.0, A=0.0, B=0.0, C=0.0, D=0.0, tmp=0.0, theta234 , diff1, diff2;
500 ColumnVector tmpd6(3);
505 tmpd6 = Tobj.SubMatrix(1,3,1,3)*tmpd6;
506 Tobj.SubMatrix(1,3,4,4) = Tobj.SubMatrix(1,3,4,4) - tmpd6;
509 theta[1] = atan2(Tobj(2,4),Tobj(1,4));
511 theta[0] = atan2(-Tobj(2,4),-Tobj(1,4));
513 diff1 = fabs(q_actual(1)-theta[0]);
515 diff1 = 2*M_PI - diff1;
517 diff2 = fabs(q_actual(1)-theta[1]);
519 diff2 = 2*M_PI - diff2;
526 theta234 = atan2( Tobj(3,3) , cos(theta[1])*Tobj(1,3) + sin(theta[1])*Tobj(2,3) );
528 theta[5] = atan2( (cos(theta234)*(cos(theta[1])*Tobj(1,3) +
529 sin(theta[1])*Tobj(2,3)) + sin(theta234)*Tobj(3,3)),
530 (sin(theta[1])*Tobj(1,3) - cos(theta[1])*Tobj(2,3)));
532 theta[6] = atan2( (-sin(theta234)*(cos(theta[1])*Tobj(1,1) +
533 sin(theta[1])*Tobj(2,1)) + cos(theta234)*Tobj(3,1)),
534 (-sin(theta234)*(cos(theta[1])*Tobj(1,2) + sin(theta[1])*Tobj(2,2)) +
535 cos(theta234)*Tobj(3,2)));
537 A= cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4) - links[1].a -
538 links[4].a*cos(theta234);
540 B= Tobj(3,4) - links[1].d - links[4].a*sin(theta234);
543 K= ( A*A + B*B - (links[3].a*links[3].a) - (links[2].a*links[2].a) ) /
544 ( 2*links[2].a*links[3].a );
548 throw std::out_of_range(
"sqrt of negative number not allowed.");
550 theta[3] = atan2(sqrt(tmp),K);
551 theta[0] = atan2(-sqrt(tmp),K);
553 diff1 = fabs(q_actual(3)-theta[0]);
555 diff1 = 2*M_PI - diff1;
557 diff2 = fabs(q_actual(3)-theta[3]);
559 diff2 = 2*M_PI - diff2;
565 C = cos(theta[3])*links[3].a + links[2].a;
566 D = sin(theta[3])*links[3].a;
568 theta[2] = atan2(B,A) - atan2(D,C);
570 theta[4] = theta234 - theta[2] - theta[3];
580 catch(std::out_of_range & e)
596 bool converge =
false;
597 return inv_kin(Tobj, mj, dof, converge);
601 ReturnMatrix
mRobot::inv_kin(
const Matrix & Tobj,
const int mj,
const int endlink,
bool & converge)
612 return inv_kin_rhino(Tobj, converge);
615 return inv_kin_puma(Tobj, converge);
618 return inv_kin_schilling(Tobj, converge);
633 ColumnVector qout(5), q_actual;
638 Real theta[6] , diff1, diff2, tmp,
639 angle , L=0.0 , M=0.0 , K=0.0 , H=0.0 , G=0.0;
643 ColumnVector tmpd6(3);
644 tmpd6(1)=0; tmpd6(2)=0; tmpd6(3)=links[6].d;
645 tmpd6 = Tobj.SubMatrix(1,3,1,3)*tmpd6;
646 Tobj.SubMatrix(1,3,4,4) = Tobj.SubMatrix(1,3,4,4) - tmpd6;
650 theta[0] = atan2(Tobj(2,4),
653 theta[1] = atan2(-Tobj(2,4),
656 diff1 = fabs(q_actual(1)-theta[0]) ;
658 diff1 = 2*M_PI - diff1;
660 diff2 = fabs(q_actual(1)-theta[1]);
662 diff2 = 2*M_PI - diff2 ;
666 theta[1] = theta[0] ;
668 theta[5] = atan2(sin(theta[1])*Tobj(1,1) - cos(theta[1])*Tobj(2,1),
669 sin(theta[1])*Tobj(1,2) - cos(theta[1])*Tobj(2,2));
672 angle = atan2(-1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3),
675 L = cos(theta[1])*Tobj(1,4) +
676 sin(theta[1])*Tobj(2,4) +
677 links[5].d*sin(angle) -
678 links[5].a*cos(angle);
681 links[5].d*cos(angle) -
682 links[5].a*sin(angle);
683 K = (L*L + M*M - links[4].a*links[4].a -
684 links[3].a*links[3].a) /
685 (2 * links[4].a * links[4].a);
689 throw std::out_of_range(
"sqrt of negative number not allowed.");
691 theta[0] = atan2( sqrt(tmp) , K );
692 theta[3] = atan2( -sqrt(tmp) , K );
694 diff1 = fabs(q_actual(3)-theta[0]) ;
696 diff1 = 2*M_PI - diff1 ;
698 diff2 = fabs(q_actual(3)-theta[3]);
700 diff2 = 2*M_PI - diff2 ;
703 theta[3] = theta[0] ;
705 H = cos(theta[3]) * links[4].a + links[3].a;
706 G = sin(theta[3]) * links[4].a;
708 theta[2] = atan2( M , L ) - atan2( G , H );
709 theta[4] = atan2( -1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3) ,
710 -1*Tobj(3,3)) - theta[2] - theta[3] ;
720 catch(std::out_of_range & e)
738 ColumnVector qout(6), q_actual;
743 Real theta[7] , diff1, diff2, tmp,
744 A = 0.0 , B = 0.0 , C = 0.0 , D =0.0, Ro = 0.0,
745 H = 0.0 , L = 0.0 , M = 0.0;
751 ColumnVector tmpd6(3); Matrix tmp;
752 tmpd6(1)=0; tmpd6(2)=0; tmpd6(3)=links[6].d;
753 tmpd6 = Tobj.SubMatrix(1,3,1,3)*tmpd6;
754 Tobj.SubMatrix(1,3,4,4) = Tobj.SubMatrix(1,3,4,4) - tmpd6;
757 tmp = Tobj(2,4)*Tobj(2,4) + Tobj(1,4)*Tobj(1,4);
759 throw std::out_of_range(
"sqrt of negative number not allowed.");
762 D = (links[2].d+links[3].d) / Ro;
766 throw std::out_of_range(
"sqrt of negative number not allowed.");
769 theta[0] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D, sqrt(tmp));
771 theta[1] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D , -sqrt(tmp));
773 diff1 = fabs(q_actual(1)-theta[0]);
775 diff1 = 2*M_PI - diff1;
777 diff2 = fabs(q_actual(1)-theta[1]);
779 diff2 = 2*M_PI - diff2;
785 tmp = links[4].a*links[4].a + links[4].d*links[4].d;
787 throw std::out_of_range(
"sqrt of negative number not allowed.");
790 B = atan2(links[4].d,links[4].a);
791 C = Tobj(1,4)*Tobj(1,4) +
792 Tobj(2,4)*Tobj(2,4) +
793 (Tobj(3,4)-links[1].d)*(Tobj(3,4)-links[1].d) -
794 (links[2].d + links[3].d)*(links[2].d + links[3].d) -
795 links[3].a*links[3].a -
796 links[4].a*links[4].a -
797 links[4].d*links[4].d;
798 A = C / (2*links[3].a);
802 throw std::out_of_range(
"sqrt of negative number not allowed.");
804 theta[0] = atan2(sqrt(tmp) , A/Ro) + B;
805 theta[3] = atan2(-sqrt(tmp) , A/Ro) + B;
807 diff1 = fabs(q_actual(3)-theta[0]);
809 diff1 = 2*M_PI - diff1 ;
811 diff2 = fabs(q_actual(3)-theta[3]);
813 diff2 = 2*M_PI - diff2;
819 H = cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4);
820 L = sin(theta[3])*links[4].d + cos(theta[3])*links[4].a + links[3].a;
821 M = cos(theta[3])*links[4].d - sin(theta[3])*links[4].a;
823 theta[2] = atan2( M , L ) - atan2(Tobj(3,4)-links[1].d , H );
825 theta[0] = atan2( -sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3) ,
826 cos(theta[2] + theta[3]) *
827 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
828 - (sin(theta[2]+theta[3])*Tobj(3,3)) );
830 theta[4] = atan2(-1*(-sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3)),
831 -cos(theta[2] + theta[3]) *
832 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
833 + (sin(theta[2]+theta[3])*Tobj(3,3)) );
835 diff1 = fabs(q_actual(4)-theta[0]);
837 diff1 = 2*M_PI - diff1;
839 diff2 = fabs(q_actual(4)-theta[4]);
841 diff2 = 2*M_PI - diff2;
847 theta[5] = atan2( cos(theta[4]) *
848 ( cos(theta[2] + theta[3]) *
849 (cos(theta[1]) * Tobj(1,3)
850 + sin(theta[1])*Tobj(2,3))
851 - (sin(theta[2]+theta[3])*Tobj(3,3)) ) +
852 sin(theta[4])*(-sin(theta[1])*Tobj(1,3)
853 + cos(theta[1])*Tobj(2,3)) ,
854 sin(theta[2]+theta[3]) * (cos(theta[1]) * Tobj(1,3)
855 + sin(theta[1])*Tobj(2,3) )
856 + (cos(theta[2]+theta[3])*Tobj(3,3)) );
858 theta[6] = atan2( -sin(theta[4])
859 * ( cos(theta[2] + theta[3]) *
860 (cos(theta[1]) * Tobj(1,1)
861 + sin(theta[1])*Tobj(2,1))
862 - (sin(theta[2]+theta[3])*Tobj(3,1))) +
863 cos(theta[4])*(-sin(theta[1])*Tobj(1,1)
864 + cos(theta[1])*Tobj(2,1)),
865 -sin(theta[4]) * ( cos(theta[2] + theta[3]) *
866 (cos(theta[1]) * Tobj(1,2)
867 + sin(theta[1])*Tobj(2,2))
868 - (sin(theta[2]+theta[3])*Tobj(3,2))) +
869 cos(theta[4])*(-sin(theta[1])*Tobj(1,2)
870 + cos(theta[1])*Tobj(2,2)) );
881 catch(std::out_of_range & e)
898 ColumnVector qout(6), q_actual;
903 Real theta[7], K=0.0, A=0.0, B=0.0, C=0.0, D=0.0, tmp=0.0, theta234 , diff1, diff2;
907 ColumnVector tmpd6(3);
912 tmpd6 = Tobj.SubMatrix(1,3,1,3)*tmpd6;
913 Tobj.SubMatrix(1,3,4,4) = Tobj.SubMatrix(1,3,4,4) - tmpd6;
916 theta[1] = atan2(Tobj(2,4),Tobj(1,4));
918 theta[0] = atan2(-Tobj(2,4),-Tobj(1,4));
920 diff1 = fabs(q_actual(1)-theta[0]);
922 diff1 = 2*M_PI - diff1;
924 diff2 = fabs(q_actual(1)-theta[1]);
926 diff2 = 2*M_PI - diff2;
933 theta234 = atan2( Tobj(3,3) , cos(theta[1])*Tobj(1,3) + sin(theta[1])*Tobj(2,3) );
935 theta[5] = atan2( (cos(theta234)*(cos(theta[1])*Tobj(1,3) +
936 sin(theta[1])*Tobj(2,3)) + sin(theta234)*Tobj(3,3)),
937 (sin(theta[1])*Tobj(1,3) - cos(theta[1])*Tobj(2,3)));
939 theta[6] = atan2( (-sin(theta234)*(cos(theta[1])*Tobj(1,1) +
940 sin(theta[1])*Tobj(2,1)) + cos(theta234)*Tobj(3,1)),
941 (-sin(theta234)*(cos(theta[1])*Tobj(1,2) + sin(theta[1])*Tobj(2,2)) +
942 cos(theta234)*Tobj(3,2)));
944 A= cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4) - links[2].a -
945 links[5].a*cos(theta234);
947 B= Tobj(3,4) - links[1].d - links[5].a*sin(theta234);
950 K= ( A*A + B*B - (links[4].a*links[4].a) - (links[3].a*links[3].a) ) /
951 ( 2*links[3].a*links[4].a );
955 throw std::out_of_range(
"sqrt of negative number not allowed.");
957 theta[3] = atan2(sqrt(tmp),K);
958 theta[0] = atan2(-sqrt(tmp),K);
960 diff1 = fabs(q_actual(3)-theta[0]);
962 diff1 = 2*M_PI - diff1;
964 diff2 = fabs(q_actual(3)-theta[3]);
966 diff2 = 2*M_PI - diff2;
972 C = cos(theta[3])*links[4].a + links[3].a;
973 D = sin(theta[3])*links[4].a;
975 theta[2] = atan2(B,A) - atan2(D,C);
977 theta[4] = theta234 - theta[2] - theta[3];
988 catch(std::out_of_range & e)
1002 bool converge =
false;
1003 return inv_kin(Tobj, mj, dof, converge);
1016 switch (robotType) {
1018 return inv_kin_rhino(Tobj, converge);
1021 return inv_kin_puma(Tobj, converge);
1036 ColumnVector qout(5), q_actual;
1041 Real theta[6] , diff1, diff2, tmp,
1042 angle , L=0.0 , M=0.0 , K=0.0 , H=0.0 , G=0.0 ;
1045 theta[0] = atan2(Tobj(2,4),
1048 theta[1] = atan2(-Tobj(2,4),
1051 diff1 = fabs(q_actual(1)-theta[0]) ;
1053 diff1 = 2*M_PI - diff1;
1055 diff2 = fabs(q_actual(1)-theta[1]);
1057 diff2 = 2*M_PI - diff2 ;
1061 theta[1] = theta[0] ;
1063 theta[5] = atan2(sin(theta[1])*Tobj(1,1) - cos(theta[1])*Tobj(2,1),
1064 sin(theta[1])*Tobj(1,2) - cos(theta[1])*Tobj(2,2));
1067 angle = atan2(-1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3),
1070 L = cos(theta[1])*Tobj(1,4) +
1071 sin(theta[1])*Tobj(2,4) +
1072 links[5].d*sin(angle) -
1073 links[5].a*cos(angle);
1076 links[5].d*cos(angle) -
1077 links[5].a*sin(angle);
1078 K = (L*L + M*M - links[4].a*links[4].a -
1079 links[3].a*links[3].a) /
1080 (2 * links[4].a * links[4].a);
1084 throw std::out_of_range(
"sqrt of negative number not allowed.");
1086 theta[0] = atan2( sqrt(tmp) , K );
1087 theta[3] = atan2( -sqrt(tmp) , K );
1089 diff1 = fabs(q_actual(3)-theta[0]) ;
1091 diff1 = 2*M_PI - diff1 ;
1093 diff2 = fabs(q_actual(3)-theta[3]);
1095 diff2 = 2*M_PI - diff2 ;
1098 theta[3] = theta[0] ;
1100 H = cos(theta[3]) * links[4].a + links[3].a;
1101 G = sin(theta[3]) * links[4].a;
1103 theta[2] = atan2( M , L ) - atan2( G , H );
1104 theta[4] = atan2( -1*cos(theta[1])*Tobj(1,3) - sin(theta[1])*Tobj(2,3) ,
1105 -1*Tobj(3,3)) - theta[2] - theta[3] ;
1115 catch(std::out_of_range & e)
1133 ColumnVector qout(6), q_actual;
1138 Real theta[7] , diff1, diff2, tmp,
1139 A = 0.0 , B = 0.0 , C = 0.0 , D =0.0, Ro = 0.0,
1140 H = 0.0 , L = 0.0 , M = 0.0;
1146 ColumnVector tmpd6(3); Matrix tmp;
1147 tmpd6(1)=0; tmpd6(2)=0; tmpd6(3)=links[6].d;
1148 tmpd6 = Tobj.SubMatrix(1,3,1,3)*tmpd6;
1149 Tobj.SubMatrix(1,3,4,4) = Tobj.SubMatrix(1,3,4,4) - tmpd6;
1152 tmp = Tobj(2,4)*Tobj(2,4) + Tobj(1,4)*Tobj(1,4);
1154 throw std::out_of_range(
"sqrt of negative number not allowed.");
1157 D = (links[2].d+links[3].d) / Ro;
1161 throw std::out_of_range(
"sqrt of negative number not allowed.");
1164 theta[0] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D, sqrt(tmp));
1166 theta[1] = atan2(Tobj(2,4),Tobj(1,4)) - atan2(D , -sqrt(tmp));
1168 diff1 = fabs(q_actual(1)-theta[0]);
1170 diff1 = 2*M_PI - diff1;
1172 diff2 = fabs(q_actual(1)-theta[1]);
1174 diff2 = 2*M_PI - diff2;
1178 theta[1] = theta[0];
1180 tmp = links[4].a*links[4].a + links[4].d*links[4].d;
1182 throw std::out_of_range(
"sqrt of negative number not allowed.");
1185 B = atan2(links[4].d,links[4].a);
1186 C = Tobj(1,4)*Tobj(1,4) +
1187 Tobj(2,4)*Tobj(2,4) +
1188 (Tobj(3,4)-links[1].d)*(Tobj(3,4)-links[1].d) -
1189 (links[2].d + links[3].d)*(links[2].d + links[3].d) -
1190 links[3].a*links[3].a -
1191 links[4].a*links[4].a -
1192 links[4].d*links[4].d;
1193 A = C / (2*links[3].a);
1197 throw std::out_of_range(
"sqrt of negative number not allowed.");
1199 theta[0] = atan2(sqrt(tmp) , A/Ro) + B;
1200 theta[3] = atan2(-sqrt(tmp) , A/Ro) + B;
1202 diff1 = fabs(q_actual(3)-theta[0]);
1204 diff1 = 2*M_PI - diff1 ;
1206 diff2 = fabs(q_actual(3)-theta[3]);
1208 diff2 = 2*M_PI - diff2;
1212 theta[3] = theta[0];
1214 H = cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4);
1215 L = sin(theta[3])*links[4].d + cos(theta[3])*links[4].a + links[3].a;
1216 M = cos(theta[3])*links[4].d - sin(theta[3])*links[4].a;
1218 theta[2] = atan2( M , L ) - atan2(Tobj(3,4)-links[1].d , H );
1220 theta[0] = atan2( -sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3) ,
1221 cos(theta[2] + theta[3]) *
1222 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
1223 - (sin(theta[2]+theta[3])*Tobj(3,3)) );
1225 theta[4] = atan2(-1*(-sin(theta[1])*Tobj(1,3) + cos(theta[1])*Tobj(2,3)),
1226 -cos(theta[2] + theta[3]) *
1227 (cos(theta[1]) * Tobj(1,3) + sin(theta[1])*Tobj(2,3))
1228 + (sin(theta[2]+theta[3])*Tobj(3,3)) );
1230 diff1 = fabs(q_actual(4)-theta[0]);
1232 diff1 = 2*M_PI - diff1;
1234 diff2 = fabs(q_actual(4)-theta[4]);
1236 diff2 = 2*M_PI - diff2;
1240 theta[4] = theta[0];
1242 theta[5] = atan2( cos(theta[4]) *
1243 ( cos(theta[2] + theta[3]) *
1244 (cos(theta[1]) * Tobj(1,3)
1245 + sin(theta[1])*Tobj(2,3))
1246 - (sin(theta[2]+theta[3])*Tobj(3,3)) ) +
1247 sin(theta[4])*(-sin(theta[1])*Tobj(1,3)
1248 + cos(theta[1])*Tobj(2,3)) ,
1249 sin(theta[2]+theta[3]) * (cos(theta[1]) * Tobj(1,3)
1250 + sin(theta[1])*Tobj(2,3) )
1251 + (cos(theta[2]+theta[3])*Tobj(3,3)) );
1253 theta[6] = atan2( -sin(theta[4])
1254 * ( cos(theta[2] + theta[3]) *
1255 (cos(theta[1]) * Tobj(1,1)
1256 + sin(theta[1])*Tobj(2,1))
1257 - (sin(theta[2]+theta[3])*Tobj(3,1))) +
1258 cos(theta[4])*(-sin(theta[1])*Tobj(1,1)
1259 + cos(theta[1])*Tobj(2,1)),
1260 -sin(theta[4]) * ( cos(theta[2] + theta[3]) *
1261 (cos(theta[1]) * Tobj(1,2)
1262 + sin(theta[1])*Tobj(2,2))
1263 - (sin(theta[2]+theta[3])*Tobj(3,2))) +
1264 cos(theta[4])*(-sin(theta[1])*Tobj(1,2)
1265 + cos(theta[1])*Tobj(2,2)) );
1276 catch(std::out_of_range & e)
1294 ColumnVector qout(6), q_actual;
1299 Real theta[7], K=0.0, A=0.0, B=0.0, C=0.0, D=0.0, tmp=0.0, theta234 , diff1, diff2;
1303 ColumnVector tmpd6(3);
1307 tmpd6(3)=links[6].d;
1308 tmpd6 = Tobj.SubMatrix(1,3,1,3)*tmpd6;
1309 Tobj.SubMatrix(1,3,4,4) = Tobj.SubMatrix(1,3,4,4) - tmpd6;
1312 theta[1] = atan2(Tobj(2,4),Tobj(1,4));
1314 theta[0] = atan2(-Tobj(2,4),-Tobj(1,4));
1316 diff1 = fabs(q_actual(1)-theta[0]);
1318 diff1 = 2*M_PI - diff1;
1320 diff2 = fabs(q_actual(1)-theta[1]);
1322 diff2 = 2*M_PI - diff2;
1326 theta[1] = theta[0];
1329 theta234 = atan2( Tobj(3,3) , cos(theta[1])*Tobj(1,3) + sin(theta[1])*Tobj(2,3) );
1331 theta[5] = atan2( (cos(theta234)*(cos(theta[1])*Tobj(1,3) +
1332 sin(theta[1])*Tobj(2,3)) + sin(theta234)*Tobj(3,3)),
1333 (sin(theta[1])*Tobj(1,3) - cos(theta[1])*Tobj(2,3)));
1335 theta[6] = atan2( (-sin(theta234)*(cos(theta[1])*Tobj(1,1) +
1336 sin(theta[1])*Tobj(2,1)) + cos(theta234)*Tobj(3,1)),
1337 (-sin(theta234)*(cos(theta[1])*Tobj(1,2) + sin(theta[1])*Tobj(2,2)) +
1338 cos(theta234)*Tobj(3,2)));
1340 A= cos(theta[1])*Tobj(1,4) + sin(theta[1])*Tobj(2,4) - links[2].a -
1341 links[5].a*cos(theta234);
1343 B= Tobj(3,4) - links[1].d - links[5].a*sin(theta234);
1346 K= ( A*A + B*B - (links[4].a*links[4].a) - (links[3].a*links[3].a) ) /
1347 ( 2*links[3].a*links[4].a );
1351 throw std::out_of_range(
"sqrt of negative number not allowed.");
1353 theta[3] = atan2(sqrt(tmp),K);
1354 theta[0] = atan2(-sqrt(tmp),K);
1356 diff1 = fabs(q_actual(3)-theta[0]);
1358 diff1 = 2*M_PI - diff1;
1360 diff2 = fabs(q_actual(3)-theta[3]);
1362 diff2 = 2*M_PI - diff2;
1366 theta[3] = theta[0];
1368 C = cos(theta[3])*links[4].a + links[3].a;
1369 D = sin(theta[3])*links[4].a;
1371 theta[2] = atan2(B,A) - atan2(D,C);
1373 theta[4] = theta234 - theta[2] - theta[3];
1384 catch(std::out_of_range & e)
1395 #ifdef use_namespace