8 #pragma GCC diagnostic push 9 #pragma GCC diagnostic ignored "-Wunused-parameter" 10 #pragma GCC diagnostic ignored "-Wunused-value" 12 #pragma GCC diagnostic pop 22 template <
typename SCALAR>
23 Eigen::Matrix<SCALAR, 3, 1>
testFunction(
const Eigen::Matrix<SCALAR, 3, 1>& x)
25 kindr::EulerAnglesXyz<SCALAR> anglesIn(x);
26 kindr::EulerAnglesXyz<SCALAR> anglesTemp;
28 anglesTemp.setX(3 * anglesIn.x() + 2 * anglesIn.x() * anglesIn.x() - anglesIn.y() * anglesIn.z());
29 anglesTemp.setY(anglesIn.z() + anglesIn.y() + 3);
30 anglesTemp.setZ(anglesIn.z());
32 kindr::EulerAnglesXyz<SCALAR> anglesOut(anglesTemp);
34 return anglesOut.toImplementation();
43 template <
typename SCALAR>
44 Eigen::Matrix<SCALAR, 3, 3>
jacobianCheck(
const Eigen::Matrix<SCALAR, 3, 1>& x)
46 Eigen::Matrix<SCALAR, 3, 3> jac;
48 jac << 3 + 4 * x(0), -x(2), -x(1), 0, 1, 1, 0, 0, 1;
58 TEST(KindrJitTest, EulerAnglesTest)
66 typename derivativesCppadJIT::FUN_TYPE_CG f = testFunction<derivativesCppadJIT::CG_SCALAR>;
67 typename derivativesCppad::FUN_TYPE_AD f_ad = testFunction<derivativesCppad::AD_SCALAR>;
73 DerivativesCppadSettings settings;
74 settings.createJacobian_ =
true;
77 jacCG.compileJIT(settings,
"eulerAnglesTestLib");
80 Eigen::Matrix<double, 3, 1> angles;
82 for (
size_t i = 0;
i < 10;
i++)
88 ASSERT_LT((jacCG.jacobian(angles) -
jacobianCheck(angles)).array().abs().maxCoeff(), 1e-10);
89 ASSERT_LT((jacAd.jacobian(angles) -
jacobianCheck(angles)).array().abs().maxCoeff(), 1e-10);
91 }
catch (std::exception& e)
93 std::cout <<
"Kindr Euler angle test failed: " << e.what() << std::endl;
100 template <
typename SCALAR>
103 kindr::EulerAnglesXyz<SCALAR> angles(x);
106 kindr::Position<SCALAR, 3> pos;
107 pos.toImplementation()(0) = 1;
108 pos.toImplementation()(1) = 1;
109 pos.toImplementation()(2) = 1;
111 return angles.rotate(pos).toImplementation();
113 TEST(KindrJitTest, EulerRotateTest)
119 typename derivativesCppadJIT::FUN_TYPE_CG f = rotateTestFunction<derivativesCppadJIT::CG_SCALAR>;
124 DerivativesCppadSettings settings;
125 settings.createJacobian_ =
true;
128 jacCG.compileJIT(settings,
"EulerRotateTest");
130 }
catch (std::exception& e)
132 std::cout <<
"Kindr rotate test failed: " << e.what() << std::endl;
139 template <
typename SCALAR>
142 kindr::EulerAnglesXyz<SCALAR> angles(x);
145 Eigen::Matrix<SCALAR, 3, 1> pos;
150 Eigen::Matrix<SCALAR, 3, 3> someMatrix;
151 someMatrix.setIdentity();
157 kindr::RotationMatrix<SCALAR> rotMat(someMatrix);
159 return rotMat.toImplementation() * pos;
161 TEST(KindrJitTest, RotationMatrixTest)
168 typename derivativesCppadJIT::FUN_TYPE_CG f = kindrRotationMatrixTestFunction<derivativesCppadJIT::CG_SCALAR>;
173 DerivativesCppadSettings settings;
174 settings.createJacobian_ =
true;
175 settings.createForwardZero_ =
true;
178 jacCG.compileJIT(settings,
"rotationMatrixTestLib");
180 }
catch (std::exception& e)
182 std::cout <<
"Kindr rotation matrix test failed: " << e.what() << std::endl;
189 template <
typename SCALAR>
192 Eigen::Matrix<SCALAR, 3, 3> someMatrix;
193 someMatrix.setIdentity();
199 kindr::RotationMatrix<SCALAR> rotMat(someMatrix);
201 kindr::EulerAnglesXyz<SCALAR> euler(rotMat);
203 return euler.toImplementation();
205 TEST(KindrJitTest, DISABLED_KindrRotationMatrixToEulerAnglesXyzTest)
212 typename derivativesCppadJIT::FUN_TYPE_CG f =
213 convertRotationMatrixToKindrEulerTestFunction<derivativesCppadJIT::CG_SCALAR>;
218 DerivativesCppadSettings settings;
219 settings.createJacobian_ =
true;
220 settings.createForwardZero_ =
true;
223 jacCG.compileJIT(settings,
"rotationMatrixToEulerTestLib");
225 }
catch (std::exception& e)
227 std::cout <<
"KindrRotationMatrixToEulerXyzTest test failed: " << e.what() << std::endl;
234 template <
typename SCALAR>
237 Eigen::Matrix<SCALAR, 3, 3> someMatrix(3, 3);
238 someMatrix.setIdentity();
244 Eigen::Matrix<SCALAR, 3, 1> eigenEulerAngles = someMatrix.eulerAngles(0, 1, 2);
246 return eigenEulerAngles;
248 TEST(KindrJitTest, DISABLED_EigenRotationMatrixToEigenEulerAnglesTest)
255 typename derivativesCppadJIT::FUN_TYPE_CG f =
256 convertRotationMatrixToEigenEulerTestFunction<derivativesCppadJIT::CG_SCALAR>;
261 DerivativesCppadSettings settings;
262 settings.createJacobian_ =
true;
263 settings.createForwardZero_ =
true;
268 jacCG.compileJIT(settings,
"EigenRotationMatrixToEigenEulerAnglesTest");
270 }
catch (std::exception& e)
272 std::cout <<
"EigenRotationMatrixToEigenEulerAnglesTest test failed: " << e.what() << std::endl;
324 template <
typename SCALAR>
327 Eigen::Matrix<SCALAR, 3, 3> someMatrix(3, 3);
328 someMatrix.setIdentity();
334 Eigen::Matrix<SCALAR, 1, 1> someData;
335 someData(0, 0) = someMatrix.norm();
338 TEST(KindrJitTest, FrobeniusNormTest)
345 typename derivativesCppadJIT::FUN_TYPE_CG f = frobeniusNormTestFunction<derivativesCppadJIT::CG_SCALAR>;
350 DerivativesCppadSettings settings;
351 settings.createJacobian_ =
true;
354 jacCG.compileJIT(settings,
"FrobeniusNormTest");
356 }
catch (std::exception& e)
358 std::cout <<
"FrobeniusNormTest test failed: " << e.what() << std::endl;
365 template <
typename SCALAR>
368 Eigen::Matrix<SCALAR, 3, 3> someMatrix;
369 someMatrix.setIdentity();
376 kindr::RotationMatrix<SCALAR> rotMat(someMatrix);
379 kindr::RotationQuaternion<SCALAR> quat(rotMat);
381 Eigen::Matrix<SCALAR, 4, 1> someData;
382 someData << quat.w(), quat.x(), quat.y(), quat.z();
386 TEST(KindrJitTest, DISABLED_RotationMatrixToKindrRotationQuatTest)
393 typename derivativesCppadJIT::FUN_TYPE_CG f =
394 convertRotationMatrixToKindrQuatTestFunction<derivativesCppadJIT::CG_SCALAR>;
399 DerivativesCppadSettings settings;
400 settings.createJacobian_ =
true;
401 settings.createForwardZero_ =
true;
404 jacCG.compileJIT(settings,
"convertRotationMatrixToQuatTestFunction");
406 }
catch (std::exception& e)
408 std::cout <<
"convertRotationMatrixToQuatTestFunction test failed: " << e.what() << std::endl;
415 template <
typename SCALAR>
418 Eigen::Matrix<SCALAR, 3, 3> someMatrix;
419 someMatrix.setIdentity();
425 kindr::RotationMatrix<SCALAR> rotMat(someMatrix);
428 Eigen::Quaternion<SCALAR> quat(someMatrix);
430 Eigen::Matrix<SCALAR, 4, 1> someData;
431 someData << quat.w(), quat.x(), quat.y(), quat.z();
435 TEST(KindrJitTest, DISABLED_KindrRotationMatrixToEigenRotationQuatTest)
442 typename derivativesCppadJIT::FUN_TYPE_CG f =
443 convertKindrRotationMatrixToEigenQuatTestFunction<derivativesCppadJIT::CG_SCALAR>;
448 DerivativesCppadSettings settings;
449 settings.createJacobian_ =
true;
450 settings.createForwardZero_ =
true;
453 jacCG.compileJIT(settings,
"RotationMatrixToEigenRotationQuatTest");
455 }
catch (std::exception& e)
457 std::cout <<
"RotationMatrixToEigenQuatTest test failed: " << e.what() << std::endl;
464 template <
typename SCALAR>
467 Eigen::Transform<SCALAR, 3, Eigen::Affine>
t;
468 t = Eigen::Translation<SCALAR, 3>(x);
469 t.rotate(Eigen::AngleAxis<SCALAR>(x(0), Eigen::Matrix<SCALAR, 3, 1>::UnitX()));
470 t.rotate(Eigen::AngleAxis<SCALAR>(x(1), Eigen::Matrix<SCALAR, 3, 1>::UnitY()));
471 t.rotate(Eigen::AngleAxis<SCALAR>(x(2), Eigen::Matrix<SCALAR, 3, 1>::UnitZ()));
474 return (t.matrix()).
template topLeftCorner<3, 1>();
476 TEST(KindrJitTest, EigenTransformTest)
483 typename derivativesCppadJIT::FUN_TYPE_CG f = eigenTransformTestFunction<derivativesCppadJIT::CG_SCALAR>;
488 DerivativesCppadSettings settings;
489 settings.createJacobian_ =
true;
492 jacCG.compileJIT(settings,
"eigenTransformTestLib");
494 }
catch (std::exception& e)
496 std::cout <<
"Eigen transform test failed: " << e.what() << std::endl;
503 template <
typename SCALAR>
506 Eigen::Quaternion<SCALAR> q;
507 q = Eigen::AngleAxis<SCALAR>(x(0), Eigen::Matrix<SCALAR, 3, 1>::UnitX()) *
508 Eigen::AngleAxis<SCALAR>(x(1), Eigen::Matrix<SCALAR, 3, 1>::UnitY()) *
509 Eigen::AngleAxis<SCALAR>(x(2), Eigen::Matrix<SCALAR, 3, 1>::UnitZ());
512 return q.toRotationMatrix().template topRightCorner<3, 1>();
514 TEST(KindrJitTest, EigenQuaternionTest)
521 typename derivativesCppadJIT::FUN_TYPE_CG f = eigenQuaternionTestFunction<derivativesCppadJIT::CG_SCALAR>;
526 DerivativesCppadSettings settings;
527 settings.createJacobian_ =
true;
530 jacCG.compileJIT(settings,
"EigenQuaternionTest");
532 }
catch (std::exception& e)
534 std::cout <<
"Eigen transform test failed: " << e.what() << std::endl;
541 template <
typename SCALAR>
544 Eigen::Quaternion<SCALAR> q;
545 q = Eigen::AngleAxis<SCALAR>(x(0), Eigen::Matrix<SCALAR, 3, 1>::UnitX()) *
546 Eigen::AngleAxis<SCALAR>(x(1), Eigen::Matrix<SCALAR, 3, 1>::UnitY()) *
547 Eigen::AngleAxis<SCALAR>(x(2), Eigen::Matrix<SCALAR, 3, 1>::UnitZ());
549 kindr::RotationQuaternion<SCALAR> kindr_quat(q);
551 Eigen::Matrix<SCALAR, 4, 1> someData;
552 someData << kindr_quat.w(), kindr_quat.x(), kindr_quat.y(), kindr_quat.z();
556 TEST(KindrJitTest, EigenQuatToKindrRotationQuatTest)
563 typename derivativesCppadJIT::FUN_TYPE_CG f =
564 eigenQuatToKindrRotationQuatFunction<derivativesCppadJIT::CG_SCALAR>;
569 DerivativesCppadSettings settings;
570 settings.createJacobian_ =
true;
573 jacCG.compileJIT(settings,
"EigenQuatToKindrRotationQuatTest");
575 }
catch (std::exception& e)
577 std::cout <<
"Eigen transform test failed: " << e.what() << std::endl;
584 template <
typename SCALAR>
587 kindr::Quaternion<SCALAR> q(x(0), x(1), x(2), x(2));
589 Eigen::Matrix<SCALAR, 4, 1> res;
590 res << q.w(), q.x(), q.y(), q.z();
594 TEST(KindrJitTest, kindrQuaternionTest)
601 typename derivativesCppadJIT::FUN_TYPE_CG f = kindrQuaternionTestFunction<derivativesCppadJIT::CG_SCALAR>;
606 DerivativesCppadSettings settings;
607 settings.createJacobian_ =
true;
610 jacCG.compileJIT(settings,
"kindrQuaternionTestTestLib");
612 }
catch (std::exception& e)
614 std::cout <<
"Eigen transform test failed: " << e.what() << std::endl;
621 template <
typename SCALAR>
624 Eigen::Quaternion<SCALAR> q_init;
625 q_init = Eigen::AngleAxis<SCALAR>(x(0), Eigen::Matrix<SCALAR, 3, 1>::UnitX()) *
626 Eigen::AngleAxis<SCALAR>(x(1), Eigen::Matrix<SCALAR, 3, 1>::UnitY()) *
627 Eigen::AngleAxis<SCALAR>(x(2), Eigen::Matrix<SCALAR, 3, 1>::UnitZ());
630 kindr::UnitQuaternion<SCALAR> q(q_init);
632 Eigen::Matrix<SCALAR, 4, 1> res;
633 res << q.w(), q.x(), q.y(), q.z();
637 TEST(KindrJitTest, kindrUnitQuaternionTest)
644 typename derivativesCppadJIT::FUN_TYPE_CG f = kindrUnitQuaternionTestFunction<derivativesCppadJIT::CG_SCALAR>;
649 DerivativesCppadSettings settings;
650 settings.createJacobian_ =
true;
653 jacCG.compileJIT(settings,
"kindrUnitQuaternionTestLib");
655 }
catch (std::exception& e)
657 std::cout <<
"Eigen transform test failed: " << e.what() << std::endl;
666 template <
typename SCALAR>
669 kindr::RotationQuaternion<SCALAR> q(x(0), x(1), x(2), x(2));
671 Eigen::Matrix<SCALAR, 4, 1> res;
672 res << q.w(), q.x(), q.y(), q.z();
676 TEST(KindrJitTest, kindrRotationQuaternionTest)
683 typename derivativesCppadJIT::FUN_TYPE_CG f =
684 kindrRotationQuaternionTestFunction<derivativesCppadJIT::CG_SCALAR>;
689 DerivativesCppadSettings settings;
690 settings.createJacobian_ =
true;
693 jacCG.compileJIT(settings,
"kindrRotationQuaternionTest");
695 }
catch (std::exception& e)
697 std::cout <<
"Eigen transform test failed: " << e.what() << std::endl;
static Scalar sin(const Scalar &x)
Eigen::Matrix< SCALAR, 4, 1 > kindrQuaternionTestFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
test the JIT compatibility of kindr Quaternions
Definition: kindrJITtest.h:585
Eigen::Matrix< SCALAR, 3, 1 > eigenQuaternionTestFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
test the JIT compatibility of Eigen quaternions
Definition: kindrJITtest.h:504
Eigen::Matrix< SCALAR, 3, 1 > kindrRotationMatrixTestFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
test the kindr RotationMatrix constructor
Definition: kindrJITtest.h:140
Eigen::Matrix< SCALAR, 3, 1 > convertRotationMatrixToKindrEulerTestFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
test the behaviour of transcribing a kindr rotation matrix into Euler Angles
Definition: kindrJITtest.h:190
DerivativesCppad< inDim, outDim > derivativesCppad
TEST(KindrJitTest, EulerAnglesTest)
Definition: kindrJITtest.h:58
Eigen::Matrix< SCALAR, 4, 1 > kindrRotationQuaternionTestFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
Definition: kindrJITtest.h:667
Eigen::Matrix< SCALAR, 4, 1 > convertKindrRotationMatrixToEigenQuatTestFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
check conversion from kindr rotation matrix to an eigen quaternion
Definition: kindrJITtest.h:416
clear all close all load ct GNMSLog0 mat reformat t
Eigen::Matrix< SCALAR, -1, 1 > frobeniusNormTestFunction(const Eigen::Matrix< SCALAR, -1, 1 > &x)
test the Frobenius norm on an EigenMatrix
Definition: kindrJITtest.h:325
static Scalar cos(const Scalar &x)
DerivativesCppadJIT< inDim, outDim > derivativesCppadJIT
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Eigen::Matrix< SCALAR, 3, 1 > rotateTestFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
test the kindr rotate method on euler angles
Definition: kindrJITtest.h:101
Eigen::Matrix< SCALAR, 3, 1 > testFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
Definition: kindrJITtest.h:23
Eigen::Matrix< SCALAR, 4, 1 > convertRotationMatrixToKindrQuatTestFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
test the behaviour of transcribing a rotation matrix into a kindr RotationQuaternion ...
Definition: kindrJITtest.h:366
Eigen::Matrix< SCALAR, 4, 1 > kindrUnitQuaternionTestFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
test the JIT compatibility of kindr UnitQuaternions
Definition: kindrJITtest.h:622
Eigen::Matrix< SCALAR, 3, 1 > eigenTransformTestFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
test the JIT compatibility of Eigen Transforms
Definition: kindrJITtest.h:465
Eigen::Matrix< SCALAR, 4, 1 > eigenQuatToKindrRotationQuatFunction(const Eigen::Matrix< SCALAR, 3, 1 > &x)
check the conversion between an Eigen Quaternion and an kindr RotationQuaternion. ...
Definition: kindrJITtest.h:542
Eigen::Matrix< SCALAR, 3, 3 > jacobianCheck(const Eigen::Matrix< SCALAR, 3, 1 > &x)
Definition: kindrJITtest.h:44
Eigen::Matrix< SCALAR, 3, 1 > convertRotationMatrixToEigenEulerTestFunction(const Eigen::Matrix< SCALAR, -1, 1 > &x)
test the behaviour of transcribing an Eigen rotation matrix into Eigen Euler Angles ...
Definition: kindrJITtest.h:235