125 using namespace NEWMAT;
129 Real
fourbyfourident[] = {1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0};
146 Link::Link(
const int jt,
const Real it,
const Real
id,
const Real ia,
const Real ial,
147 const Real it_min,
const Real it_max,
const Real it_off,
const Real mass,
148 const Real cmx,
const Real cmy,
const Real cmz,
const Real ixx,
const Real ixy,
149 const Real ixz,
const Real iyy,
const Real iyz,
const Real izz,
const Real iIm,
150 const Real iGr,
const Real iB,
const Real iCf,
const bool dh,
151 const bool min_inertial_parameters,
const bool immobile_):
160 joint_offset(it_off),
162 min_para(min_inertial_parameters),
219 mc = ColumnVector(3);
233 I(1,2) =
I(2,1) = ixy;
234 I(1,3) =
I(3,1) = ixz;
236 I(2,3) =
I(3,2) = iyz;
315 cerr <<
"Link::set_r: wrong size in input vector." << endl;
324 cerr <<
"Link::set_mc: wrong size in input vector." << endl;
333 if( (I_.Nrows() == 3) && (I_.Ncols() == 3) )
336 cerr <<
"Link::set_r: wrong size in input vector." << endl;
340 const bool min_inertial_para)
356 z0 = ColumnVector(3);
357 z0(1) =
z0(2) = 0.0;
z0(3) = 1.0;
359 for(i = 1; i <= dhinit.Nrows(); i++)
362 if (i == dhinit.Nrows())
365 error(
"Fix link can only be on the last one");
371 error(
"Number of degree of freedom must be greater or equal to 1");
379 w =
new ColumnVector[
dof+1];
380 wp =
new ColumnVector[
dof+1];
381 vp =
new ColumnVector[
dof+
fix+1];
382 a =
new ColumnVector[
dof+1];
383 f =
new ColumnVector[
dof+1];
384 f_nv =
new ColumnVector[
dof+1];
385 n =
new ColumnVector[
dof+1];
386 n_nv =
new ColumnVector[
dof+1];
387 F =
new ColumnVector[
dof+1];
388 N =
new ColumnVector[
dof+1];
389 p =
new ColumnVector[
dof+
fix+1];
390 pp =
new ColumnVector[
dof+
fix+1];
391 dw =
new ColumnVector[
dof+1];
392 dwp =
new ColumnVector[
dof+1];
393 dvp =
new ColumnVector[
dof+1];
394 da =
new ColumnVector[
dof+1];
395 df =
new ColumnVector[
dof+1];
396 dn =
new ColumnVector[
dof+1];
397 dF =
new ColumnVector[
dof+1];
398 dN =
new ColumnVector[
dof+1];
399 dp =
new ColumnVector[
dof+1];
404 cerr <<
"Robot_basic constructor : new ran out of memory" << endl;
409 for(i = 0; i <=
dof; i++)
411 w[i] = ColumnVector(3);
413 wp[i] = ColumnVector(3);
415 vp[i] = ColumnVector(3);
416 dw[i] = ColumnVector(3);
418 dwp[i] = ColumnVector(3);
420 dvp[i] = ColumnVector(3);
423 for(i = 0; i <=
dof+
fix; i++)
427 p[i] = ColumnVector(3);
432 if(dhinit.Ncols() == 23)
434 for(i = 1; i <=
dof+
fix; i++)
435 links[i] =
Link((
int) dhinit(i,1), dhinit(i,2), dhinit(i,3),
436 dhinit(i,4), dhinit(i,5), dhinit(i,6), dhinit(i,7),
437 dhinit(i,8), dhinit(i,9), dhinit(i,10), dhinit(i,11),
438 dhinit(i,12), dhinit(i,13), dhinit(i,14), dhinit(i,15),
439 dhinit(i,16), dhinit(i,17), dhinit(i,18), dhinit(i,19),
440 dhinit(i,20), dhinit(i,21), dhinit(i,22),
441 dh_parameter, min_inertial_para, dhinit(i,23));
444 error(
"Initialisation Matrix does not have 23 columns.");
448 const bool dh_parameter,
const bool min_inertial_para)
465 z0 = ColumnVector(3);
466 z0(1) =
z0(2) = 0.0;
z0(3) = 1.0;
469 for(i = 1; i <= initrobot.Nrows(); i++)
470 if(initrobot(i,1) == 2)
472 if (i == initrobot.Nrows())
475 error(
"Fix link can only be on the last one");
481 error(
"Number of degree of freedom must be greater or equal to 1");
488 w =
new ColumnVector[
dof+1];
489 wp =
new ColumnVector[
dof+1];
490 vp =
new ColumnVector[
dof+
fix+1];
491 a =
new ColumnVector[
dof+1];
492 f =
new ColumnVector[
dof+1];
493 f_nv =
new ColumnVector[
dof+1];
494 n =
new ColumnVector[
dof+1];
495 n_nv =
new ColumnVector[
dof+1];
496 F =
new ColumnVector[
dof+1];
497 N =
new ColumnVector[
dof+1];
498 p =
new ColumnVector[
dof+
fix+1];
499 pp =
new ColumnVector[
dof+
fix+1];
500 dw =
new ColumnVector[
dof+1];
501 dwp =
new ColumnVector[
dof+1];
502 dvp =
new ColumnVector[
dof+1];
503 da =
new ColumnVector[
dof+1];
504 df =
new ColumnVector[
dof+1];
505 dn =
new ColumnVector[
dof+1];
506 dF =
new ColumnVector[
dof+1];
507 dN =
new ColumnVector[
dof+1];
508 dp =
new ColumnVector[
dof+1];
513 cerr <<
"Robot_basic constructor : new ran out of memory" << endl;
518 for(i = 0; i <=
dof; i++)
520 w[i] = ColumnVector(3);
522 wp[i] = ColumnVector(3);
524 vp[i] = ColumnVector(3);
525 dw[i] = ColumnVector(3);
527 dwp[i] = ColumnVector(3);
529 dvp[i] = ColumnVector(3);
532 for(i = 0; i <=
dof+
fix; i++)
536 p[i] = ColumnVector(3);
541 if ( initrobot.Nrows() == initmotor.Nrows() )
543 if(initmotor.Ncols() == 4)
545 if(initrobot.Ncols() == 19)
547 for(i = 1; i <=
dof+
fix; i++)
548 links[i] =
Link((
int) initrobot(i,1), initrobot(i,2), initrobot(i,3),
549 initrobot(i,4), initrobot(i,5), initrobot(i,6),
550 initrobot(i,7), initrobot(i,8), initrobot(i,9),
551 initrobot(i,10),initrobot(i,11), initrobot(i,12),
552 initrobot(i,13),initrobot(i,14), initrobot(i,15),
553 initrobot(i,16),initrobot(i,17), initrobot(i,18),
554 initmotor(i,1), initmotor(i,2), initmotor(i,3),
555 initmotor(i,4), dh_parameter, min_inertial_para,
559 error(
"Initialisation robot Matrix does not have 19 columns.");
562 error(
"Initialisation robot motor Matrix does not have 4 columns.");
566 error(
"Initialisation robot and motor matrix does not have same numbers of Rows.");
570 const bool min_inertial_para)
585 z0 = ColumnVector(3);
586 z0(1) =
z0(2) = 0.0;
z0(3) = 1.0;
594 w =
new ColumnVector[
dof+1];
595 wp =
new ColumnVector[
dof+1];
596 vp =
new ColumnVector[
dof+1];
597 a =
new ColumnVector[
dof+1];
598 f =
new ColumnVector[
dof+1];
599 f_nv =
new ColumnVector[
dof+1];
600 n =
new ColumnVector[
dof+1];
601 n_nv =
new ColumnVector[
dof+1];
602 F =
new ColumnVector[
dof+1];
603 N =
new ColumnVector[
dof+1];
604 p =
new ColumnVector[
dof+1];
605 pp =
new ColumnVector[
dof+
fix+1];
606 dw =
new ColumnVector[
dof+1];
607 dwp =
new ColumnVector[
dof+1];
608 dvp =
new ColumnVector[
dof+1];
609 da =
new ColumnVector[
dof+1];
610 df =
new ColumnVector[
dof+1];
611 dn =
new ColumnVector[
dof+1];
612 dF =
new ColumnVector[
dof+1];
613 dN =
new ColumnVector[
dof+1];
614 dp =
new ColumnVector[
dof+1];
615 R =
new Matrix[
dof+1];
619 cerr <<
"Robot_basic constructor : new ran out of memory" << endl;
623 for(i = 0; i <=
dof; i++)
625 w[i] = ColumnVector(3);
627 wp[i] = ColumnVector(3);
629 vp[i] = ColumnVector(3);
630 dw[i] = ColumnVector(3);
632 dwp[i] = ColumnVector(3);
634 dvp[i] = ColumnVector(3);
637 for(i = 0; i <=
dof+
fix; i++)
641 p[i] = ColumnVector(3);
660 w =
new ColumnVector[
dof+1];
661 wp =
new ColumnVector[
dof+1];
662 vp =
new ColumnVector[
dof+1];
663 a =
new ColumnVector[
dof+1];
664 f =
new ColumnVector[
dof+1];
665 f_nv =
new ColumnVector[
dof+1];
666 n =
new ColumnVector[
dof+1];
667 n_nv =
new ColumnVector[
dof+1];
668 F =
new ColumnVector[
dof+1];
669 N =
new ColumnVector[
dof+1];
670 p =
new ColumnVector[
dof+
fix+1];
671 pp =
new ColumnVector[
dof+
fix+1];
672 dw =
new ColumnVector[
dof+1];
673 dwp =
new ColumnVector[
dof+1];
674 dvp =
new ColumnVector[
dof+1];
675 da =
new ColumnVector[
dof+1];
676 df =
new ColumnVector[
dof+1];
677 dn =
new ColumnVector[
dof+1];
678 dF =
new ColumnVector[
dof+1];
679 dN =
new ColumnVector[
dof+1];
680 dp =
new ColumnVector[
dof+1];
685 cerr <<
"Robot_basic constructor : new ran out of memory" << endl;
689 for(i = 0; i <=
dof; i++)
691 w[i] = ColumnVector(3);
693 wp[i] = ColumnVector(3);
695 vp[i] = ColumnVector(3);
696 dw[i] = ColumnVector(3);
698 dwp[i] = ColumnVector(3);
700 dvp[i] = ColumnVector(3);
703 for(i = 0; i <=
dof+
fix; i++)
707 p[i] = ColumnVector(3);
712 for(i = 1; i <=
dof+
fix; i++)
717 const bool dh_parameter,
const bool min_inertial_para)
732 z0 = ColumnVector(3);
733 z0(1) =
z0(2) = 0.0;
z0(3) = 1.0;
736 ifstream inconffile(filename.c_str(), std::ios::in);
737 if (robData.read_conf(inconffile))
739 error(
"Robot_basic::Robot_basic: unable to read input config file.");
742 bool motor =
false, angle_in_degree =
false;
744 if(robData.select(robotName,
"dof",
dof))
747 error(
"Robot_basic::Robot_basic: dof is less then one.");
750 error(
"Robot_basic::Robot_basic: error in extracting dof from conf file.");
753 robData.select(robotName,
"Fix",
fix);
754 robData.select(robotName,
"Motor", motor);
755 robData.select(robotName,
"angle_in_degree", angle_in_degree);
761 w =
new ColumnVector[
dof+1];
762 wp =
new ColumnVector[
dof+1];
763 vp =
new ColumnVector[
dof+
fix+1];
764 a =
new ColumnVector[
dof+1];
765 f =
new ColumnVector[
dof+1];
766 f_nv =
new ColumnVector[
dof+1];
767 n =
new ColumnVector[
dof+1];
768 n_nv =
new ColumnVector[
dof+1];
769 F =
new ColumnVector[
dof+1];
770 N =
new ColumnVector[
dof+1];
771 p =
new ColumnVector[
dof+
fix+1];
772 pp =
new ColumnVector[
dof+
fix+1];
773 dw =
new ColumnVector[
dof+1];
774 dwp =
new ColumnVector[
dof+1];
775 dvp =
new ColumnVector[
dof+1];
776 da =
new ColumnVector[
dof+1];
777 df =
new ColumnVector[
dof+1];
778 dn =
new ColumnVector[
dof+1];
779 dF =
new ColumnVector[
dof+1];
780 dN =
new ColumnVector[
dof+1];
781 dp =
new ColumnVector[
dof+1];
786 cerr <<
"Robot_basic constructor : new ran out of memory" << endl;
790 for(i = 0; i <=
dof; i++)
792 w[i] = ColumnVector(3);
794 wp[i] = ColumnVector(3);
796 vp[i] = ColumnVector(3);
797 dw[i] = ColumnVector(3);
799 dwp[i] = ColumnVector(3);
801 dvp[i] = ColumnVector(3);
804 for(i = 0; i <=
dof+
fix; i++)
808 p[i] = ColumnVector(3);
813 for(
int j = 1; j <=
dof+
fix; j++)
816 double theta=0, d=0, a=0, alpha=0, theta_min=0, theta_max=0, joint_offset=0,
817 m=0, cx=0, cy=0, cz=0, Ixx=0, Ixy=0, Ixz=0, Iyy=0, Iyz=0, Izz=0,
818 Im=0, Gr=0, B=0, Cf=0;
821 string robotName_link;
823 ostr << robotName <<
"_LINK" << j;
824 robotName_link = ostr.str();
826 robData.select(robotName_link,
"joint_type", joint_type);
827 robData.select(robotName_link,
"theta", theta);
828 robData.select(robotName_link,
"d", d);
829 robData.select(robotName_link,
"a", a);
830 robData.select(robotName_link,
"alpha", alpha);
831 robData.select(robotName_link,
"theta_max", theta_max);
832 robData.select(robotName_link,
"theta_min", theta_min);
833 robData.select(robotName_link,
"joint_offset", joint_offset);
834 robData.select(robotName_link,
"m", m);
835 robData.select(robotName_link,
"cx", cx);
836 robData.select(robotName_link,
"cy", cy);
837 robData.select(robotName_link,
"cz", cz);
838 robData.select(robotName_link,
"Ixx", Ixx);
839 robData.select(robotName_link,
"Ixy", Ixy);
840 robData.select(robotName_link,
"Ixz", Ixz);
841 robData.select(robotName_link,
"Iyy", Iyy);
842 robData.select(robotName_link,
"Iyz", Iyz);
843 robData.select(robotName_link,
"Izz", Izz);
844 robData.select(robotName_link,
"immobile", immobile);
848 theta = deg2rad(theta);
849 theta_max = deg2rad(theta_max);
850 theta_min = deg2rad(theta_min);
851 alpha = deg2rad(alpha);
852 joint_offset = deg2rad(joint_offset);
857 robData.select(robotName_link,
"Im", Im);
858 robData.select(robotName_link,
"Gr", Gr);
859 robData.select(robotName_link,
"B", B);
860 robData.select(robotName_link,
"Cf", Cf);
863 links[j] =
Link(joint_type, theta, d, a, alpha, theta_min, theta_max,
864 joint_offset, m, cx, cy, cz, Ixx, Ixy, Ixz, Iyy, Iyz,
865 Izz, Im, Gr, B, Cf, dh_parameter, min_inertial_para);
870 links[
dof+
fix] =
Link(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
871 0, 0, 0, 0, 0, 0, 0, 0, 0, dh_parameter, min_inertial_para);
926 w =
new ColumnVector[
dof+1];
927 wp =
new ColumnVector[
dof+1];
928 vp =
new ColumnVector[
dof+fix+1];
929 a =
new ColumnVector[
dof+1];
930 f =
new ColumnVector[
dof+1];
931 f_nv =
new ColumnVector[
dof+1];
932 n =
new ColumnVector[
dof+1];
933 n_nv =
new ColumnVector[
dof+1];
934 F =
new ColumnVector[
dof+1];
935 N =
new ColumnVector[
dof+1];
936 p =
new ColumnVector[
dof+fix+1];
937 pp =
new ColumnVector[
dof+fix+1];
938 dw =
new ColumnVector[
dof+1];
939 dwp =
new ColumnVector[
dof+1];
940 dvp =
new ColumnVector[
dof+1];
941 da =
new ColumnVector[
dof+1];
942 df =
new ColumnVector[
dof+1];
943 dn =
new ColumnVector[
dof+1];
944 dF =
new ColumnVector[
dof+1];
945 dN =
new ColumnVector[
dof+1];
946 dp =
new ColumnVector[
dof+1];
947 R =
new Matrix[
dof+fix+1];
951 cerr <<
"Robot_basic::operator= : new ran out of memory" << endl;
955 for(i = 0; i <=
dof; i++)
957 w[i] = ColumnVector(3);
959 wp[i] = ColumnVector(3);
961 vp[i] = ColumnVector(3);
962 dw[i] = ColumnVector(3);
964 dwp[i] = ColumnVector(3);
966 dvp[i] = ColumnVector(3);
969 for(i = 0; i <=
dof+
fix; i++)
973 p[i] = ColumnVector(3);
977 for(i = 1; i <=
dof+
fix; i++)
986 cerr << endl <<
"Robot error: " << msg1.c_str() << endl;
994 for(
int i=1; i<=endlink; i++)
995 if(!links[i].immobile)
1003 ColumnVector q(
dof);
1005 for(
int i = 1; i <=
dof; i++)
1007 q.Release();
return q;
1013 ColumnVector qp(
dof);
1015 for(
int i = 1; i <=
dof; i++)
1017 qp.Release();
return qp;
1023 ColumnVector qpp(
dof);
1025 for(
int i = 1; i <=
dof; i++)
1027 qpp.Release();
return qpp;
1033 ColumnVector q(get_available_dof(endlink));
1036 for(
int i = 1; i <= endlink; i++)
1037 if(!links[i].immobile)
1038 q(j++) = links[i].get_q();
1039 q.Release();
return q;
1045 ColumnVector qp(get_available_dof(endlink));
1048 for(
int i = 1; i <= endlink; i++)
1049 if(!links[i].immobile)
1050 qp(j++) = links[i].qp;
1051 qp.Release();
return qp;
1057 ColumnVector qpp(get_available_dof(endlink));
1060 for(
int i = 1; i <= endlink; i++)
1061 if(!links[i].immobile)
1062 qpp(j) = links[i].qpp;
1063 qpp.Release();
return qpp;
1076 if(q.Nrows() ==
dof && q.Ncols() == 1) {
1077 for(
int i = 1; i <=
dof; i++)
1082 p[i](1) =
links[i].get_a();
1089 }
else if(q.Nrows() == 1 && q.Ncols() ==
dof) {
1090 for(
int i = 1; i <=
dof; i++)
1095 p[i](1) =
links[i].get_a();
1102 }
else if(q.Nrows() == adof && q.Ncols() == 1) {
1104 for(
int i = 1; i <=
dof; i++)
1105 if(!
links[i].immobile) {
1109 p[i](1) =
links[i].get_a();
1116 }
else if(q.Nrows() == 1 && q.Ncols() == adof) {
1118 for(
int i = 1; i <=
dof; i++)
1119 if(!
links[i].immobile) {
1123 p[i](1) =
links[i].get_a();
1130 }
else error(
"q has the wrong dimension in set_q()");
1142 if(q.Nrows() ==
dof) {
1143 for(
int i = 1; i <=
dof; i++)
1148 p[i](1) =
links[i].get_a();
1157 for(
int i = 1; i <=
dof; i++)
1158 if(!
links[i].immobile) {
1162 p[i](1) =
links[i].get_a();
1169 }
else error(
"q has the wrong dimension in set_q()");
1175 if(qp.Nrows() ==
dof)
1176 for(
int i = 1; i <=
dof; i++)
1177 links[i].qp = qp(i);
1180 for(
int i = 1; i <=
dof; i++)
1181 if(!
links[i].immobile)
1184 error(
"qp has the wrong dimension in set_qp()");
1190 if(qpp.Nrows() ==
dof)
1191 for(
int i = 1; i <=
dof; i++)
1192 links[i].qpp = qpp(i);
1194 error(
"qpp has the wrong dimension in set_qpp()");
1266 Robot::Robot(
const string & filename,
const string & robotName):
1335 mRobot::mRobot(
const string & filename,
const string & robotName):
1452 if( (f < 0) || (f > 1) )
1454 cerr <<
"perturb_robot: f is not between 0 and 1" << endl;
1462 fact = (2.0*rand()/RAND_MAX - 1)*f + 1;
1464 fact = (2.0*rand()/RAND_MAX - 1)*f + 1;
1466 fact = (2.0*rand()/RAND_MAX - 1)*f + 1;
1468 fact = (2.0*rand()/RAND_MAX - 1)*f + 1;
1472 fact = (2.0*rand()/RAND_MAX - 1)*f + 1;
1490 double a[6], d[6], alpha[6];
1491 for (
int j = 1; j <= 5; j++)
1502 if ( isZero(a[1]) && isZero(a[5]) && isZero(d[2]) && isZero(d[3]) &&
1503 isZero(d[4]) && isZero(alpha[2]) && isZero(alpha[3]) && isZero(alpha[5]))
1523 double a[7], d[7], alpha[7];
1524 for (
int j = 1; j <= 6; j++)
1536 if( isZero(a[1]) && a[2] && a[3] && isZero(a[4]) && isZero(a[5]) && isZero(a[6]) &&
1537 isZero(d[5]) && isZero(alpha[2]) && isZero(alpha[6]))
1556 double a[7], d[7], alpha[7];
1557 for (
int j = 1; j <= 6; j++)
1567 if( isZero(a[5]) && isZero(a[6]) && isZero(d[2]) && isZero(d[3]) &&
1568 isZero(d[4]) && isZero(d[5]) && isZero(alpha[2]) && isZero(alpha[3]) &&
1590 double a[6], d[6], alpha[6];
1591 for (
int j = 1; j <= 5; j++)
1602 if ( isZero(a[1]) && isZero(a[2]) && isZero(d[2]) && isZero(d[3]) &&
1603 isZero(d[4]) && isZero(alpha[1]) && isZero(alpha[3]) && isZero(alpha[4]))
1622 double a[7], d[7], alpha[7];
1623 for (
int j = 1; j <= 6; j++)
1636 if ( isZero(a[1]) && isZero(a[2]) && isZero(a[5]) && isZero(a[6]) &&
1637 isZero(d[5]) && isZero(alpha[1]) && isZero(alpha[3]))
1656 double a[7], d[7], alpha[7];
1657 for (
int j = 1; j <= 6; j++)
1669 if ( isZero(a[1]) && isZero(a[6]) && isZero(d[2]) && isZero(d[3]) && isZero(d[4]) &&
1670 isZero(d[5]) && isZero(alpha[1]) && isZero(alpha[3]) && isZero(alpha[4]))
1678 #ifdef use_namespace