00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <robot/control/kinematics/KinematicsTest>
00026
00027 using robot::control::kinematics::KinematicsTest;
00028
00029
00030 using robot::TestRobot;
00031
00032 using base::equals;
00033
00034
00035
00036 KinematicsTest::KinematicsTest()
00037 {
00038 }
00039
00040
00041 void KinematicsTest::setUp()
00042 {
00043 jt.resize(dof);
00044 alpha.resize(dof);
00045 a.resize(dof);
00046 d.resize(dof);
00047 theta.resize(dof);
00048
00049 for(Int j=0; j<dof; j++) {
00050 jt[j] = TestRobot::Revolute;
00051 alpha[j] = Math::degToRad(20);
00052 a[j] = 0.2;
00053 d[j] = 0;
00054 theta[j] = 0;
00055 }
00056
00057 jt2.resize(dof2);
00058 alpha2.resize(dof2);
00059 a2.resize(dof2);
00060 d2.resize(dof2);
00061 theta2.resize(dof2);
00062
00063 for(Int j=0; j<dof2; j++) {
00064 jt2[j] = TestRobot::Revolute;
00065 alpha2[j] = 0;
00066 a2[j] = 0.4;
00067 d2[j] = 0;
00068 theta2[j] = 0;
00069 }
00070 d2[1] = 0.5;
00071
00072
00073
00074 robot = ref<TestRobot>(NewObj TestRobot(jt, alpha, a, d, theta));
00075 robot2 = ref<TestRobot>(NewObj TestRobot(jt2, alpha2, a2, d2, theta2));
00076
00077 chain = robot->getRobotDescription()->manipulators()[0]->getKinematicChain();
00078 chain2 = robot2->getRobotDescription()->manipulators()[0]->getKinematicChain();
00079
00080 lnsolver = ref<LeastNormIKSolver>(NewObj LeastNormIKSolver());
00081
00082
00083 }
00084
00085
00086 void KinematicsTest::tearDown()
00087 {
00088 }
00089
00090
00091 void KinematicsTest::testLeastNormCriteria()
00092 {
00093
00094 Vector q(dof);
00095 for(Int j=0; j<dof; j++)
00096 q[j] = Math::degToRad(15);
00097
00098 Vector x(3);
00099 x = zeroVector(3);
00100
00101 Vector dx(3);
00102 dx[0] = -0.01; dx[1] = 0; dx[2] = 0.01;
00103
00104
00105
00106
00107 ikor = ref<IKOR>(NewObj IKOR(chain));
00108
00109 Matrix J( chain.getJacobian(q, false) );
00110 Vector dq ( ikor->solve(dx, x, q, J,
00111 IKOR::Lagrangian, IKOR::LeastNorm, 0) );
00112 CPPUNIT_ASSERT( dq.size() == dof );
00113
00114 Vector cdq(6);
00115 cdq[0] = -0.0267338; cdq[1] = 0.0209276; cdq[2] = 0.025021;
00116 cdq[3] = 0.00535535; cdq[4] = -0.0153997; cdq[5] = -0.0194938;
00117
00118 CPPUNIT_ASSERT( equals(dq,cdq,0.0000001) );
00119
00120
00121 Vector dq2 ( lnsolver->solve(dx, x, q, J,
00122 LeastNormIKSolver::DefaultMethod, LeastNormIKSolver::LeastNorm, 0) );
00123
00124 CPPUNIT_ASSERT( equals(dq2, dq, 0.0000000001) );
00125
00126
00127 }
00128
00129
00130
00131 void KinematicsTest::testImpossibleMotion()
00132 {
00133
00134
00135
00136 Vector q(dof2);
00137 q = zeroVector(dof2);
00138 Vector x(3);
00139 x[0] = 2.0; x[1] = 0; x[2]=0.5;
00140
00141 Matrix f2( chain2.getForwardKinematics(q) );
00142 CPPUNIT_ASSERT( equals(Vector(vectorRange(Vector(matrixColumn(f2,3)), Range(0,3))),x) );
00143
00144 Vector dx(3);
00145 dx[0] = -0.01; dx[1] = 0; dx[2] = 0.0;
00146
00147
00148 ikor = ref<IKOR>(NewObj IKOR(chain2));
00149 Matrix J2(chain2.getJacobian(q,false));
00150 Vector dq ( ikor->solve(dx, x, q, J2,
00151 IKOR::Lagrangian, IKOR::LeastNorm, 0) );
00152 }
00153
00154
00155
00156 void KinematicsTest::testNoMotion()
00157 {
00158
00159 return;
00160
00161
00162 Vector q(dof);
00163 q = zeroVector(dof);
00164
00165 Vector x(3);
00166
00167 Matrix f( chain.getForwardKinematics(q) );
00168 x = vectorRange(Vector(matrixColumn(f,3)), Range(0,3));
00169
00170 Vector dx(3); dx = zeroVector(3);
00171
00172 ikor = ref<IKOR>(NewObj IKOR(chain));
00173 Matrix J(chain.getJacobian(q,false));
00174 Vector dq ( ikor->solve(dx, x, q, J,
00175 IKOR::Lagrangian, IKOR::LeastNorm, 0) );
00176
00177 CPPUNIT_ASSERT( equals(dq, zeroVector(dof), 0.0000000001) );
00178 }
00179
00180
00181
00182
00183
00184
00185
00186 #ifdef DEBUG
00187 CPPUNIT_TEST_SUITE_REGISTRATION( KinematicsTest );
00188 #endif
00189