14 srand( (
unsigned)time( NULL ));
102 chaindyn.addSegment(segment1);
103 chaindyn.addSegment(segment2);
126 static const double scale=1;
127 static const double offset=0;
128 static const double inertiamotorA=5.0;
129 static const double inertiamotorB=3.0;
130 static const double inertiamotorC=1.0;
131 static const double damping=0;
132 static const double stiffness=0;
199 unsigned int nr_of_constraints = 4;
202 JntArray q_in(chain2.getNrOfJoints());
203 JntArray q_in2(chain2.getNrOfJoints());
205 for(
unsigned int i=0; i<chain2.getNrOfJoints(); i++)
210 JntArray q_out(chain2.getNrOfJoints());
211 JntArray q_out2(chain2.getNrOfJoints());
212 Jacobian jac(chain2.getNrOfJoints());
216 Wrenches wrenches(chain2.getNrOfSegments());
217 JntSpaceInertiaMatrix m(chain2.getNrOfJoints());
219 Jacobian alpha(nr_of_constraints - 1);
220 JntArray beta(nr_of_constraints - 1);
222 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_OUT_OF_RANGE,fksolvervel.
JntToCart(q_in3, T2, chain2.getNrOfSegments()+1));
223 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_OUT_OF_RANGE, jacsolver1.
JntToJac(q_in, jac, chain2.getNrOfSegments()+1));
224 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_OUT_OF_RANGE, jacdotsolver1.
JntToJacDot(q_in3, t, chain2.getNrOfSegments()+1));
225 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_OUT_OF_RANGE, jacdotsolver1.
JntToJacDot(q_in3, jac, chain2.getNrOfSegments()+1));
229 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, jacdotsolver1.
JntToJacDot(q_in3, jac, chain2.getNrOfSegments()));
230 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, jacdotsolver1.
JntToJacDot(q_in3, t, chain2.getNrOfSegments()));
231 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, iksolver2.
CartToJnt(q_in,t,q_out));
232 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, iksolver_pinv_givens2.
CartToJnt(q_in,t,q_out));
233 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, iksolver_pinv_nso.
CartToJnt(q_in,t,q_out));
234 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, iksolver_wdls.
CartToJnt(q_in,t,q_out));
235 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, iksolverpos.
CartToJnt(q_in,T,q_out));
236 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, iksolverpos2.
CartToJnt(q_in,T,q_out));
237 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, iksolverpos3.
CartToJnt(q_in,T,q_out));
238 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, idsolver1.
CartToJnt(q_in,q_in2,q_out,wrenches,q_out2));
239 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, idsolver2.
CartToJnt(q_in,q_in2,q_out,alpha,beta,wrenches,q_out2));
240 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, dynparam.
JntToCoriolis(q_in, q_in2, q_out));
241 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, dynparam.
JntToGravity(q_in, q_out));
242 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOT_UP_TO_DATE, dynparam.
JntToMass(q_in, m));
258 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH,fksolvervel.
JntToCart(q_in3, T2, chain2.getNrOfSegments()));
259 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, jacsolver1.
JntToJac(q_in, jac, chain2.getNrOfSegments()));
260 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, jacdotsolver1.
JntToJacDot(q_in3, t, chain2.getNrOfSegments()));
261 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, jacdotsolver1.
JntToJacDot(q_in3, jac, chain2.getNrOfSegments()));
262 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolver2.
CartToJnt(q_in,t,q_out));
263 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolver_pinv_givens2.
CartToJnt(q_in,t,q_out));
264 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolver_pinv_nso.
CartToJnt(q_in,t,q_out));
265 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolver_wdls.
CartToJnt(q_in,t,q_out));
266 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolverpos.
CartToJnt(q_in,T,q_out));
267 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolverpos2.
CartToJnt(q_in,T,q_out));
268 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolverpos3.
CartToJnt(q_in,T,q_out));
269 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver1.
CartToJnt(q_in,q_in2,q_out,wrenches,q_out2));
270 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver2.
CartToJnt(q_in,q_in2,q_out,alpha,beta,wrenches,q_out2));
271 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, dynparam.
JntToCoriolis(q_in, q_in2, q_out));
272 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, dynparam.
JntToGravity(q_in, q_out));
273 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, dynparam.
JntToMass(q_in, m));
275 q_in.resize(chain2.getNrOfJoints());
276 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, jacsolver1.
JntToJac(q_in, jac, chain2.getNrOfSegments()));
277 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolver2.
CartToJnt(q_in,t,q_out));
278 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolver_pinv_givens2.
CartToJnt(q_in,t,q_out));
279 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolver_pinv_nso.
CartToJnt(q_in,t,q_out));
280 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolver_wdls.
CartToJnt(q_in,t,q_out));
281 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolverpos.
CartToJnt(q_in,T,q_out));
282 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolverpos2.
CartToJnt(q_in,T,q_out));
283 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolverpos3.
CartToJnt(q_in,T,q_out));
284 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolverpos2.
CartToJnt(q_in,T,q_out));
285 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, iksolverpos3.
CartToJnt(q_in,T,q_out));
286 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver1.
CartToJnt(q_in,q_in2,q_out,wrenches,q_out2));
287 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver2.
CartToJnt(q_in,q_in2,q_out,alpha,beta,wrenches,q_out2));
288 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, dynparam.
JntToCoriolis(q_in, q_in2, q_out));
289 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, dynparam.
JntToGravity(q_in, q_out));
290 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, dynparam.
JntToMass(q_in, m));
291 q_in2.resize(chain2.getNrOfJoints());
292 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, dynparam.
JntToCoriolis(q_in, q_in2, q_out));
293 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver1.
CartToJnt(q_in,q_in2,q_out,wrenches,q_out2));
294 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver2.
CartToJnt(q_in,q_in2,q_out,alpha,beta,wrenches,q_out2));
295 wrenches.resize(chain2.getNrOfSegments());
296 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver1.
CartToJnt(q_in,q_in2,q_out,wrenches,q_out2));
297 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver2.
CartToJnt(q_in,q_in2,q_out,alpha,beta,wrenches,q_out2));
298 q_out2.resize(chain2.getNrOfSegments());
299 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver1.
CartToJnt(q_in,q_in2,q_out,wrenches,q_out2));
300 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver2.
CartToJnt(q_in,q_in2,q_out,alpha,beta,wrenches,q_out2));
301 alpha.resize(nr_of_constraints);
302 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver2.
CartToJnt(q_in,q_in2,q_out,alpha,beta,wrenches,q_out2));
303 beta.
resize(nr_of_constraints);
304 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, idsolver2.
CartToJnt(q_in,q_in2,q_out,alpha,beta,wrenches,q_out2));
305 jac.resize(chain2.getNrOfJoints());
306 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_SIZE_MISMATCH, jacdotsolver1.
JntToJacDot(q_in3, jac, chain2.getNrOfSegments()));
307 q_out.resize(chain2.getNrOfJoints());
308 q_in3.resize(chain2.getNrOfJoints());
309 m.resize(chain2.getNrOfJoints());
311 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR,fksolvervel.
JntToCart(q_in3, T2, chain2.getNrOfSegments()));
312 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR, jacsolver1.
JntToJac(q_in, jac, chain2.getNrOfSegments()));
313 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR, jacdotsolver1.
JntToJacDot(q_in3, jac, chain2.getNrOfSegments()));
314 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR, jacdotsolver1.
JntToJacDot(q_in3, t, chain2.getNrOfSegments()));
315 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= iksolver2.
CartToJnt(q_in,t,q_out));
316 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= iksolver_pinv_givens2.
CartToJnt(q_in,t,q_out));
317 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= iksolver_pinv_nso.
CartToJnt(q_in,t,q_out));
318 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= iksolver_wdls.
CartToJnt(q_in,t,q_out));
319 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= iksolverpos.
CartToJnt(q_in,T,q_out));
320 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= iksolverpos2.
CartToJnt(q_in,T,q_out));
321 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= iksolverpos3.
CartToJnt(q_in,T,q_out));
322 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= iksolverpos2.
CartToJnt(q_in,T,q_out));
323 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= iksolverpos3.
CartToJnt(q_in,T,q_out));
324 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= idsolver1.
CartToJnt(q_in,q_in2,q_out,wrenches,q_out2));
325 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= idsolver2.
CartToJnt(q_in,q_in2,q_out,alpha,beta,wrenches,q_out2));
326 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= dynparam.
JntToCoriolis(q_in, q_in2, q_out));
327 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= dynparam.
JntToGravity(q_in, q_out));
328 CPPUNIT_ASSERT((
int)SolverI::E_NOERROR <= dynparam.
JntToMass(q_in, m));
334 FkPosAndJacLocal(chain1,fksolver1,jacsolver1);
337 FkPosAndJacLocal(chain2,fksolver2,jacsolver2);
340 FkPosAndJacLocal(chain3,fksolver3,jacsolver3);
343 FkPosAndJacLocal(chain4,fksolver4,jacsolver4);
350 FkVelAndJacLocal(chain1,fksolver1,jacsolver1);
353 FkVelAndJacLocal(chain2,fksolver2,jacsolver2);
356 FkVelAndJacLocal(chain3,fksolver3,jacsolver3);
359 FkVelAndJacLocal(chain4,fksolver4,jacsolver4);
365 std::cout<<
"square problem"<<std::endl;
369 std::cout<<
"KDL-SVD-HouseHolder"<<std::endl;
370 FkVelAndIkVelLocal(chain1,fksolver1,iksolver1);
371 std::cout<<
"KDL-SVD-Givens"<<std::endl;
372 FkVelAndIkVelLocal(chain1,fksolver1,iksolver_pinv_givens1);
375 std::cout<<
"underdetermined problem"<<std::endl;
379 std::cout<<
"KDL-SVD-HouseHolder"<<std::endl;
380 FkVelAndIkVelLocal(chain2,fksolver2,iksolver2);
381 std::cout<<
"KDL-SVD-Givens"<<std::endl;
382 FkVelAndIkVelLocal(chain2,fksolver2,iksolver_pinv_givens2);
385 std::cout<<
"overdetermined problem"<<std::endl;
389 std::cout<<
"KDL-SVD-HouseHolder"<<std::endl;
390 FkVelAndIkVelLocal(chain3,fksolver3,iksolver3);
391 std::cout<<
"KDL-SVD-Givens"<<std::endl;
392 FkVelAndIkVelLocal(chain3,fksolver3,iksolver_pinv_givens3);
395 std::cout<<
"overdetermined problem"<<std::endl;
399 std::cout<<
"KDL-SVD-HouseHolder"<<std::endl;
400 FkVelAndIkVelLocal(chain4,fksolver4,iksolver4);
401 std::cout<<
"KDL-SVD-Givens"<<std::endl;
402 FkVelAndIkVelLocal(chain4,fksolver4,iksolver_pinv_givens4);
407 std::cout<<
"square problem"<<std::endl;
414 std::cout<<
"KDL-SVD-HouseHolder"<<std::endl;
415 FkPosAndIkPosLocal(chain1,fksolver1,iksolver1);
416 std::cout<<
"KDL-SVD-Givens"<<std::endl;
417 FkPosAndIkPosLocal(chain1,fksolver1,iksolver1_givens);
419 std::cout<<
"underdetermined problem"<<std::endl;
426 std::cout<<
"KDL-SVD-HouseHolder"<<std::endl;
427 FkPosAndIkPosLocal(chain2,fksolver2,iksolver2);
428 std::cout<<
"KDL-SVD-Givens"<<std::endl;
429 FkPosAndIkPosLocal(chain2,fksolver2,iksolver2_givens);
431 std::cout<<
"overdetermined problem"<<std::endl;
438 std::cout<<
"KDL-SVD-HouseHolder"<<std::endl;
439 FkPosAndIkPosLocal(chain3,fksolver3,iksolver3);
440 std::cout<<
"KDL-SVD-Givens"<<std::endl;
441 FkPosAndIkPosLocal(chain3,fksolver3,iksolver3_givens);
443 std::cout<<
"underdetermined problem with WGs segment constructor"<<std::endl;
450 std::cout<<
"KDL-SVD-HouseHolder"<<std::endl;
451 FkPosAndIkPosLocal(chain4,fksolver4,iksolver4);
452 std::cout<<
"KDL-SVD-Givens"<<std::endl;
453 FkPosAndIkPosLocal(chain4,fksolver4,iksolver4_givens);
458 unsigned int maxiter = 30;
460 int maxiter_vel = 30;
461 double eps_vel = 0.1 ;
462 Frame F, dF, F_des,F_solved;
465 std::cout<<
"KDL-IK Solver Tests for Near Zero SVs"<<std::endl;
470 unsigned int nj = motomansia10.getNrOfJoints();
474 std::cout<<
"norminal case: convergence"<<std::endl;
487 CPPUNIT_ASSERT_EQUAL(0, fksolver.
JntToCart(q,F));
491 iksolver1.
CartToJnt(q, F_des, q_solved));
492 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR,
494 CPPUNIT_ASSERT_EQUAL((
unsigned int)1,
497 CPPUNIT_ASSERT_EQUAL(0, fksolver.
JntToCart(q_solved,F_solved));
499 CPPUNIT_ASSERT_EQUAL(F_des,F_solved);
501 std::cout<<
"nonconvergence: pseudoinverse singular"<<std::endl;
514 CPPUNIT_ASSERT_EQUAL(0, fksolver.
JntToCart(q,F));
521 CPPUNIT_ASSERT_EQUAL((
unsigned int)2,
524 std::cout<<
"nonconvergence: large displacement, low iterations"<<std::endl;
542 CPPUNIT_ASSERT_EQUAL(0, fksolver.
JntToCart(q,F));
545 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_MAX_ITERATIONS_EXCEEDED,
547 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR,
549 CPPUNIT_ASSERT_EQUAL((
unsigned int)1,
552 std::cout<<
"nonconvergence: fully singular"<<std::endl;
565 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR, fksolver.
JntToCart(q,F));
568 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_MAX_ITERATIONS_EXCEEDED,
570 CPPUNIT_ASSERT_EQUAL((
int)ChainIkSolverVel_pinv::E_CONVERGE_PINV_SINGULAR,
572 CPPUNIT_ASSERT_EQUAL((
unsigned int)3,
581 double lambda = 0.1 ;
583 std::cout<<
"KDL-IK WDLS Vel Solver Tests for Near Zero SVs"<<std::endl;
587 unsigned int nj = motomansia10.getNrOfJoints();
593 std::cout<<
"smallest singular value is above threshold (no WDLS)"<<std::endl;
608 std::cout<<
"smallest singular value is below threshold (lambda is scaled)"<<std::endl;
618 std::cout<<
"smallest singular value is zero (lambda_scaled=lambda)"<<std::endl;
622 CPPUNIT_ASSERT_EQUAL((
int)ChainIkSolverVel_wdls::E_CONVERGE_PINV_SINGULAR,
631 CPPUNIT_ASSERT_EQUAL((
int)ChainIkSolverVel_wdls::E_CONVERGE_PINV_SINGULAR,
640 double deltaq = 1E-4;
654 for (
unsigned int i=0; i< q.rows() ; i++)
661 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR, fksolverpos.
JntToCart(q,F1));
666 Vector(jac(3,i),jac(4,i),jac(5,i)));
669 CPPUNIT_ASSERT_EQUAL(Jcol1,Jcol2);
692 CPPUNIT_ASSERT_EQUAL(cart.deriv(),t);
713 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR, iksolvervel.
CartToJnt(qvel.
q,cart.deriv(),qdot_solved));
715 qvel.
deriv()=qdot_solved;
718 CPPUNIT_ASSERT(
Equal(qvel.
qdot,qdot_solved,1e-5));
722 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR,fksolvervel.
JntToCart(qvel,cart_solved));
723 CPPUNIT_ASSERT(
Equal(cart.deriv(),cart_solved.
deriv(),1e-5));
740 q_init(i)=q(i)+0.1*tmp;
747 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR, iksolverpos.
CartToJnt(q_init,F1,q_solved));
748 CPPUNIT_ASSERT_EQUAL((
int)SolverI::E_NOERROR, fksolverpos.
JntToCart(q_solved,F2));
750 CPPUNIT_ASSERT_EQUAL(F1,F2);
759 Vector constrainXLinear(1.0, 0.0, 0.0);
760 Vector constrainXAngular(0.0, 0.0, 0.0);
761 Vector constrainYLinear(0.0, 0.0, 0.0);
762 Vector constrainYAngular(0.0, 0.0, 0.0);
765 Twist constraintForcesX(constrainXLinear, constrainXAngular);
766 Twist constraintForcesY(constrainYLinear, constrainYAngular);
780 Vector linearAcc(0.0, 10, 0.0);
781 Vector angularAcc(0.0, 0.0, 0.0);
782 Twist twist1(linearAcc, angularAcc);
785 Vector externalForce1(0.0, 0.0, 0.0);
786 Vector externalTorque1(0.0, 0.0, 0.0);
787 Vector externalForce2(0.0, 0.0, 0.0);
788 Vector externalTorque2(0.0, 0.0, 0.0);
789 Wrench externalNetForce1(externalForce1, externalTorque1);
790 Wrench externalNetForce2(externalForce2, externalTorque2);
792 externalNetForce.push_back(externalNetForce1);
793 externalNetForce.push_back(externalNetForce2);
800 int numberOfConstraints = 1;
813 for (
int i = 0; i < k; i++)
815 JntArray jointValues(chaindyn.getNrOfJoints());
816 jointPoses[i] = jointValues;
817 jointRates[i] = jointValues;
818 jointAccelerations[i] = jointValues;
819 jointTorques[i] = jointValues;
823 JntArray jointInitialPose(chaindyn.getNrOfJoints());
824 jointInitialPose(0) = 0.0;
825 jointInitialPose(1) = M_PI/6.0;
830 jointPoses[0](0) = jointInitialPose(0);
831 jointPoses[0](1) = jointInitialPose(1);
840 double taskTimeConstant = 0.1;
841 double simulationTime = 1*taskTimeConstant;
842 double timeDelta = 0.01;
844 const std::string msg =
"Assertion failed, check matrix and array sizes";
846 for (
double t = 0.0; t <=simulationTime; t = t + timeDelta)
848 CPPUNIT_ASSERT_EQUAL((
int)
SolverI::E_NOERROR, constraintSolver.
CartToJnt(jointPoses[0], jointRates[0], jointAccelerations[0], alpha, betha, externalNetForce, jointTorques[0]));
851 jointRates[0](0) = jointRates[0](0) + jointAccelerations[0](0) * timeDelta;
852 jointPoses[0](0) = jointPoses[0](0) + (jointRates[0](0) - jointAccelerations[0](0) * timeDelta / 2.0) * timeDelta;
853 jointRates[0](1) = jointRates[0](1) + jointAccelerations[0](1) * timeDelta;
854 jointPoses[0](1) = jointPoses[0](1) + (jointRates[0](1) - jointAccelerations[0](1) * timeDelta / 2.0) * timeDelta;
856 printf(
"%f %f %f %f %f %f %f %f %f\n", t, jointPoses[0](0), jointPoses[0](1), jointRates[0](0), jointRates[0](1), jointAccelerations[0](0), jointAccelerations[0](1), jointTorques[0](0), jointTorques[0](1));
863 std::vector<Frame> v_out(chain1.getNrOfSegments());
866 JntArray qdot(chain1.getNrOfJoints());
868 for(
unsigned int i=0; i<chain1.getNrOfJoints(); i++)
877 CPPUNIT_ASSERT(
Equal(v_out[chain1.getNrOfSegments()-1],f_out,1e-5));
883 std::vector<FrameVel> v_out(chain1.getNrOfSegments());
886 JntArray qdot(chain1.getNrOfJoints());
888 for(
unsigned int i=0; i<chain1.getNrOfJoints(); i++)
898 CPPUNIT_ASSERT(
Equal(v_out[chain1.getNrOfSegments()-1],f_out,1e-5));
906 std::cout<<
"KDL FD Solver Development Test for Motoman SIA10"<<std::endl;
912 Vector gravity(0.0, 0.0, -9.81);
915 unsigned int nj = motomansia10dyn.getNrOfJoints();
916 unsigned int ns = motomansia10dyn.getNrOfSegments();
944 CPPUNIT_ASSERT(
Equal(-0.547, f_out.
p(0), eps));
945 CPPUNIT_ASSERT(
Equal(-0.301, f_out.
p(1), eps));
946 CPPUNIT_ASSERT(
Equal(0.924, f_out.
p(2), eps));
947 CPPUNIT_ASSERT(
Equal(0.503, f_out.
M(0,0), eps));
948 CPPUNIT_ASSERT(
Equal(0.286, f_out.
M(0,1), eps));
949 CPPUNIT_ASSERT(
Equal(-0.816, f_out.
M(0,2), eps));
950 CPPUNIT_ASSERT(
Equal(-0.859, f_out.
M(1,0), eps));
951 CPPUNIT_ASSERT(
Equal(0.269, f_out.
M(1,1), eps));
952 CPPUNIT_ASSERT(
Equal(-0.436, f_out.
M(1,2), eps));
953 CPPUNIT_ASSERT(
Equal(0.095, f_out.
M(2,0), eps));
954 CPPUNIT_ASSERT(
Equal(0.920, f_out.
M(2,1), eps));
955 CPPUNIT_ASSERT(
Equal(0.381, f_out.
M(2,2), eps));
962 {{0.301,-0.553,0.185,0.019,0.007,-0.086,0.},
963 {-0.547,-0.112,-0.139,-0.376,-0.037,0.063,0.},
964 {0.,-0.596,0.105,-0.342,-0.026,-0.113,0.},
965 {0.,0.199,-0.553,0.788,-0.615,0.162,-0.816},
966 {0.,-0.980,-0.112,-0.392,-0.536,-0.803,-0.436},
967 {1.,0.,0.825,0.475,0.578,-0.573,0.381}};
968 for (
int i=0; i<6; i++ ) {
969 for (
int j=0; j<nj; j++ ) {
970 CPPUNIT_ASSERT(
Equal(jac(i,j), Jac[i][j], eps));
977 JntSpaceInertiaMatrix H(nj), Heff(nj);
981 if (ret < 0) std::cout <<
"KDL: inverse dynamics ERROR: " << ret << std::endl;
982 CPPUNIT_ASSERT(
Equal(0.000, taugrav(0), eps));
983 CPPUNIT_ASSERT(
Equal(-36.672, taugrav(1), eps));
984 CPPUNIT_ASSERT(
Equal(4.315, taugrav(2), eps));
985 CPPUNIT_ASSERT(
Equal(-11.205, taugrav(3), eps));
986 CPPUNIT_ASSERT(
Equal(0.757, taugrav(4), eps));
987 CPPUNIT_ASSERT(
Equal(1.780, taugrav(5), eps));
988 CPPUNIT_ASSERT(
Equal(0.000, taugrav(6), eps));
991 if (ret < 0) std::cout <<
"KDL: inverse dynamics ERROR: " << ret << std::endl;
992 CPPUNIT_ASSERT(
Equal(-15.523, taucor(0), eps));
993 CPPUNIT_ASSERT(
Equal(24.250, taucor(1), eps));
994 CPPUNIT_ASSERT(
Equal(-6.862, taucor(2), eps));
995 CPPUNIT_ASSERT(
Equal(6.303, taucor(3), eps));
996 CPPUNIT_ASSERT(
Equal(0.110, taucor(4), eps));
997 CPPUNIT_ASSERT(
Equal(-4.898, taucor(5), eps));
998 CPPUNIT_ASSERT(
Equal(-0.249, taucor(6), eps));
1001 if (ret < 0) std::cout <<
"KDL: inverse dynamics ERROR: " << ret << std::endl;
1003 {{6.8687,-0.4333,0.4599,0.6892,0.0638,-0.0054,0.0381},
1004 {-0.4333,8.8324,-0.5922,0.7905,0.0003,-0.0242,0.0265},
1005 {0.4599,-0.5922,3.3496,-0.0253,0.1150,-0.0243,0.0814},
1006 {0.6892,0.7905,-0.0253,3.9623,-0.0201,0.0087,-0.0291},
1007 {0.0638,0.0003,0.1150,-0.0201,1.1234,0.0029,0.0955},
1008 {-0.0054,-0.0242,-0.0243,0.0087,0.0029,1.1425,0},
1009 {0.0381,0.0265,0.0814,-0.0291,0.0955,0,1.1000}};
1010 for (
int i=0; i<nj; i++ ) {
1011 for (
int j=0; j<nj; j++ ) {
1012 CPPUNIT_ASSERT(
Equal(H(i,j), Hexp[i][j], eps));
1030 for(
int i=0;i<ns;i++){
1038 IdSolver.
CartToJnt(q, qd, jntarraynull, f_ext, Tnoninertial);
1039 CPPUNIT_ASSERT(
Equal(-21.252, Tnoninertial(0), eps));
1040 CPPUNIT_ASSERT(
Equal(-37.933, Tnoninertial(1), eps));
1041 CPPUNIT_ASSERT(
Equal(-2.497, Tnoninertial(2), eps));
1042 CPPUNIT_ASSERT(
Equal(-15.289, Tnoninertial(3), eps));
1043 CPPUNIT_ASSERT(
Equal(-4.646, Tnoninertial(4), eps));
1044 CPPUNIT_ASSERT(
Equal(-9.201, Tnoninertial(5), eps));
1045 CPPUNIT_ASSERT(
Equal(-5.249, Tnoninertial(6), eps));
1048 Eigen::MatrixXd H_eig(nj,nj), L(nj,nj);
1049 Eigen::VectorXd Tnon_eig(nj), D(nj), r(nj), acc_eig(nj);
1050 for(
int i=0;i<nj;i++){
1051 Tnon_eig(i) = -Tnoninertial(i);
1052 for(
int j=0;j<nj;j++){
1053 H_eig(i,j) = H(i,j);
1057 for(
int i=0;i<nj;i++){
1058 qdd(i) = acc_eig(i);
1060 CPPUNIT_ASSERT(
Equal(2.998, qdd(0), eps));
1061 CPPUNIT_ASSERT(
Equal(4.289, qdd(1), eps));
1062 CPPUNIT_ASSERT(
Equal(0.946, qdd(2), eps));
1063 CPPUNIT_ASSERT(
Equal(2.518, qdd(3), eps));
1064 CPPUNIT_ASSERT(
Equal(3.530, qdd(4), eps));
1065 CPPUNIT_ASSERT(
Equal(8.150, qdd(5), eps));
1066 CPPUNIT_ASSERT(
Equal(4.254, qdd(6), eps));
1074 std::cout<<
"KDL FD Solver Consistency Test for Motoman SIA10"<<std::endl;
1079 Vector gravity(0.0, 0.0, -9.81);
1082 unsigned int nj = motomansia10dyn.getNrOfJoints();
1083 unsigned int ns = motomansia10dyn.getNrOfSegments();
1122 for(
int i=0;i<ns;i++){
1128 ret = FdSolver.
CartToJnt(q, qd, tau, f_ext, qdd);
1129 if (ret < 0) std::cout <<
"KDL: forward dynamics ERROR: " << ret << std::endl;
1130 CPPUNIT_ASSERT(
Equal(9.486, qdd(0), eps));
1131 CPPUNIT_ASSERT(
Equal(1.830, qdd(1), eps));
1132 CPPUNIT_ASSERT(
Equal(4.726, qdd(2), eps));
1133 CPPUNIT_ASSERT(
Equal(11.665, qdd(3), eps));
1134 CPPUNIT_ASSERT(
Equal(-50.108, qdd(4), eps));
1135 CPPUNIT_ASSERT(
Equal(21.403, qdd(5), eps));
1136 CPPUNIT_ASSERT(
Equal(-0.381, qdd(6), eps));
1141 IdSolver.
CartToJnt(q, qd, qdd, f_ext, torque);
1142 for (
int i=0; i<nj; i++ )
1144 CPPUNIT_ASSERT(
Equal(torque(i), tau(i), eps));
1152 std::cout<<
"LDL Solver Test"<<std::endl;
1157 Eigen::MatrixXd A(3,3), Aout(3,3);
1158 Eigen::VectorXd b(3);
1159 Eigen::MatrixXd L(3,3), Lout(3,3);
1160 Eigen::VectorXd d(3), dout(3);
1161 Eigen::VectorXd x(3), xout(3);
1162 Eigen::VectorXd r(3);
1163 Eigen::MatrixXd Dout(3,3);
1179 for(
int i=0;i<3;i++){
1180 for(
int j=0;j<3;j++){
1181 CPPUNIT_ASSERT(
Equal(L(i,j), Lout(i,j), eps));
1186 for(
int i=0;i<3;i++){
1187 Dout(i,i) = dout(i);
1191 for(
int i=0;i<3;i++){
1192 CPPUNIT_ASSERT(
Equal(xout(i), x(i), eps));
1196 Aout = Lout * Dout * Lout.transpose();
1197 for(
int i=0;i<3;i++){
1198 for(
int j=0;j<3;j++){
1199 CPPUNIT_ASSERT(
Equal(A(i,j), Aout(i,j), eps));
double getLambdaScaled() const
This abstract class encapsulates the inverse position solver for a KDL::Chain.
virtual void updateInternalDataStructures()
virtual int JntToCart(const JntArray &q_in, Frame &p_out, int segmentNr=-1)
virtual int getError() const
Return the latest error.
This class encapsulates a simple segment, that is a "rigid body" (i.e., a frame and a rigid body...
virtual int CartToJnt(const JntArray &q_init, const Frame &p_in, JntArray &q_out)=0
Computes the Jacobian time derivative (Jdot) by calculating the partial derivatives regarding to a jo...
void IkVelSolverWDLSTest()
This class encapsulates a serial kinematic interconnection structure. It is built out of segments...
virtual int CartToJnt(const JntArray &q_in, const Twist &v_in, JntArray &qdot_out)
virtual int CartToJnt(const JntArray &q_init, const Frame &p_in, JntArray &q_out)
IMETHOD Vector diff(const Vector &p_w_a, const Vector &p_w_b, double dt=1)
void MultiplyJacobian(const Jacobian &jac, const JntArray &src, Twist &dest)
Maximum number of iterations exceeded.
This class represents an fixed size array containing joint values of a KDL::Chain.
6D Inertia of a rigid body
virtual void updateInternalDataStructures()
virtual int CartToJnt(const JntArray &q_in, const Twist &v_in, JntArray &qdot_out)
int ldl_solver_eigen(const Eigen::MatrixXd &A, const Eigen::VectorXd &v, Eigen::MatrixXd &L, Eigen::VectorXd &D, Eigen::VectorXd &vtmp, Eigen::VectorXd &q)
Solves the system of equations Aq = v for q via LDL decomposition, where A is a square positive defin...
Input size does not match internal state.
unsigned int getNrZeroSigmas() const
void FkVelAndJacLocal(Chain &chain, ChainFkSolverVel &fksolvervel, ChainJntToJacSolver &jacsolver)
Recursive newton euler forward dynamics solver.
static const int E_CONVERGE_PINV_SINGULAR
solution converged but (pseudo)inverse is singular
virtual int CartToJnt(const JntArray &q_in, const Twist &v_in, JntArray &qdot_out)=0
int CartToJnt(const JntArray &q, const JntArray &q_dot, const JntArray &torques, const Wrenches &f_ext, JntArray &q_dotdot)
Rotation M
Orientation of the Frame.
virtual int CartToJnt(const JntArray &q_in, const Twist &v_in, JntArray &qdot_out)
Class to calculate the jacobian of a general KDL::Chain, it is used by other solvers. It should not be used outside of KDL.
void setInertia(const RigidBodyInertia &Iin)
virtual void updateInternalDataStructures()
represents both translational and rotational velocities.
IMETHOD void SetToZero(Vector &v)
virtual void updateInternalDataStructures()
static Frame DH_Craig1989(double a, double alpha, double d, double theta)
IMETHOD bool Equal(const FrameAcc &r1, const FrameAcc &r2, double eps=epsilon)
static const int E_CONVERGE_PINV_SINGULAR
solution converged but (pseudo)inverse is singular
int CartToJnt(const JntArray &q, const JntArray &q_dot, JntArray &q_dotdot, const Jacobian &alfa, const JntArray &beta, const Wrenches &f_ext, JntArray &torques)
virtual int JntToCart(const JntArray &q_in, Frame &p_out, int segmentNr=-1)=0
virtual int JntToJac(const JntArray &q_in, Jacobian &jac, int segmentNR=-1)
A concrete implementation of a 3 dimensional vector class.
static Rotation RPY(double roll, double pitch, double yaw)
Solver for the inverse position kinematics that uses Levenberg-Marquardt.
static Frame DH(double a, double alpha, double d, double theta)
virtual void updateInternalDataStructures()
void FkPosAndJacLocal(Chain &chain, ChainFkSolverPos &fksolverpos, ChainJntToJacSolver &jacsolver)
Requested index out of range.
virtual int JntToCart(const JntArrayVel &q_in, FrameVel &out, int segmentNr=-1)=0
void setColumn(unsigned int i, const Twist &t)
Recursive newton euler inverse dynamics solver.
static Rotation Identity()
Gives back an identity rotaton matrix.
Vector p
origine of the Frame
int CartToJnt(const JntArray &q, const JntArray &q_dot, const JntArray &q_dotdot, const Wrenches &f_ext, JntArray &torques)
unsigned int getNrOfJoints() const
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
void IkSingularValueTest()
void updateInternalDataStructures()
void FdSolverConsistencyTest()
virtual int JntToCoriolis(const JntArray &q, const JntArray &q_dot, JntArray &coriolis)
void resize(unsigned int newSize)
std::vector< Wrench > Wrenches
void setLambda(const double lambda)
virtual int JntToCart(const JntArrayVel &q_in, FrameVel &out, int segmentNr=-1)
virtual int JntToJacDot(const KDL::JntArrayVel &q_in, KDL::Twist &jac_dot_q_dot, int seg_nr=-1)
Computes .
void FdSolverDevelopmentTest()
represents a frame transformation in 3D space (rotation + translation)
virtual void updateInternalDataStructures()
This class encapsulates a simple joint, that is with one parameterized degree of freedom and with sca...
unsigned int getNrZeroSigmas() const
represents both translational and rotational acceleration.
virtual int CartToJnt(const KDL::JntArray &q_init, const KDL::Frame &T_base_goal, KDL::JntArray &q_out)
computes the inverse position kinematics.
CPPUNIT_TEST_SUITE_REGISTRATION(SolverTest)
virtual void updateInternalDataStructures()
void FkVelAndIkVelLocal(Chain &chain, ChainFkSolverVel &fksolvervel, ChainIkSolverVel &iksolvervel)
double getSigmaMin() const
virtual void updateInternalDataStructures()
virtual int JntToMass(const JntArray &q, JntSpaceInertiaMatrix &H)
void FkPosAndIkPosLocal(Chain &chain, ChainFkSolverPos &fksolverpos, ChainIkSolverPos &iksolverpos)
virtual void updateInternalDataStructures()
Dynamics calculations by constraints based on Vereshchagin 1989. for a chain. This class creates inst...
IMETHOD void random(Vector &a)
addDelta operator for displacement rotational velocity.
virtual void updateInternalDataStructures()
This abstract class encapsulates a solver for the forward velocity kinematics for a KDL::Chain...
virtual int CartToJnt(const JntArray &q_init, const Frame &p_in, JntArray &q_out)
virtual int JntToGravity(const JntArray &q, JntArray &gravity)
virtual void updateInternalDataStructures()
virtual int CartToJnt(const JntArray &q_in, const Twist &v_in, JntArray &qdot_out)
This abstract class encapsulates the inverse velocity solver for a KDL::Chain.
This abstract class encapsulates a solver for the forward position kinematics for a KDL::Chain...