Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

robot/control/kinematics/KinematicsTest.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2002 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: KinematicsTest.cpp 1036 2004-02-11 20:48:55Z jungd $
00019   $Revision: 1.6 $
00020   $Date: 2004-02-11 15:48:55 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
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   // solve via Larganrian, least-norm, no constraints
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); // the correct dqs (calculated using the original IKORv2.0 code)
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   // compare the solution obtained with the Pseudo-inverse
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   // Try an impossible motion (ask for ee to move back in x while
00134   //  all joints at 0)
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) ); // check forward kinematics against x
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   // solve via FSP, Larganrian, least-norm, no constraints
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) ); // should throw
00152 }
00153 
00154 
00155 
00156 void KinematicsTest::testNoMotion()
00157 {
00158 //!!!! 
00159 return;
00160   
00161   // Ask for dx=0 and verify the solution is dq=0
00162   Vector q(dof);
00163   q = zeroVector(dof);
00164 
00165   Vector x(3);
00166 
00167   Matrix f( chain.getForwardKinematics(q) ); // calculate x from forward kinematics
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 

Generated on Thu Jul 29 15:56:33 2004 for OpenSim by doxygen 1.3.6