1 #include <gtest/gtest.h> 20 res.block<3, 3>(3, 0) = m.block<3, 3>(0, 3);
21 res.block<3, 3>(0, 3) = m.block<3, 3>(3, 0);
28 res.block<3, 3>(0, 0) = m.block<3, 3>(0, 0).transpose();
29 res.block<3, 3>(3, 0) = m.block<3, 3>(3, 0).transpose();
30 res.block<3, 3>(0, 3) = m.block<3, 3>(0, 3).transpose();
31 res.block<3, 3>(3, 3) = m.block<3, 3>(3, 3).transpose();
37 return m.block<3, 3>(0, 0);
42 return Vector3d(-m(4, 2), m(3, 2), -m(3, 1));
49 qz(0., 0., std::sin(th / 2.), std::cos(th / 2.));
64 EXPECT_NEAR(euler[0], euler_from_quaternion[0], 1.e-10);
65 EXPECT_NEAR(euler[1], euler_from_quaternion[1], 1.e-10);
66 EXPECT_NEAR(euler[2], euler_from_quaternion[2], 1.e-10);
68 EXPECT_NEAR(euler[0], euler_from_matrix[0], 1.e-10);
69 EXPECT_NEAR(euler[1], euler_from_matrix[1], 1.e-10);
70 EXPECT_NEAR(euler[2], euler_from_matrix[2], 1.e-10);
78 EXPECT_NEAR(euler[0], euler_from_quaternion[0], 1.e-10);
79 EXPECT_NEAR(euler[1], euler_from_quaternion[1], 1.e-10);
80 EXPECT_NEAR(euler[2], euler_from_quaternion[2], 1.e-10);
82 EXPECT_NEAR(euler[0], euler_from_matrix[0], 1.e-10);
83 EXPECT_NEAR(euler[1], euler_from_matrix[1], 1.e-10);
84 EXPECT_NEAR(euler[2], euler_from_matrix[2], 1.e-10);
92 EXPECT_NEAR(euler[0], euler_from_quaternion[0], 1.e-10);
93 EXPECT_NEAR(euler[1], euler_from_quaternion[1], 1.e-10);
94 EXPECT_NEAR(euler[2], euler_from_quaternion[2], 1.e-10);
96 EXPECT_NEAR(euler[0], euler_from_matrix[0], 1.e-10);
97 EXPECT_NEAR(euler[1], euler_from_matrix[1], 1.e-10);
98 EXPECT_NEAR(euler[2], euler_from_matrix[2], 1.e-10);
105 Eigen::AngleAxisd aa(0.5, v);
106 Eigen::Quaterniond q2(aa);
118 Eigen::Quaterniond q2(m);
123 m << 0., 1., 0., 1., 0., 0., 0., 0., -1.;
128 m << -1., 0., 0., 0., 1., 0., 0., 0., -1.;
133 m << 1., 0., 0., 0., -1., 0., 0., 0., -1.;
138 m << -1., 0., 0., 0., -1., 0., 0., 0., 1.;
161 EXPECT_TRUE(a.axis().isApprox(v, 1e-12));
174 EXPECT_TRUE(a.axis().isApprox(a2.axis(), 1e-12));
175 EXPECT_NEAR(a.angle(), a2.angle(), 1e-12);
184 EXPECT_TRUE(a.axis().isApprox(q.vec(), 1e-12));
185 EXPECT_NEAR(a.angle(), M_PI, 1e-12);
191 EXPECT_NEAR(a.axis().x(), -0.195053, 1.0e-6);
192 EXPECT_NEAR(a.axis().y(), 0.547459, 1.0e-6);
193 EXPECT_NEAR(a.axis().z(), 0.813783, 1.0e-6);
199 SpatialMatrix s_matrix(1., 0., 0., 0., 0., 7., 0., 2., 0., 0., 8., 0., 0., 0., 3., 9., 0., 0., 0., 0., 6., 4., 0., 0., 0., 5., 0., 0., 5., 0., 4., 0., 0., 0., 0., 6.);
203 result = s_matrix * s_vector;
206 EXPECT_EQ (test_result, result);
211 Matrix3d m(cos(0.4), sin(0.4), 0, -sin(0.4), cos(0.4), 0, 0, 0, 1);
228 result = 3. * s_vector;
232 EXPECT_EQ (test_result, result);
238 SpatialMatrix s_matrix(1., 0., 0., 0., 0., 7., 0., 2., 0., 0., 8., 0., 0., 0., 3., 9., 0., 0., 0., 0., 6., 4., 0., 0., 0., 5., 0., 0., 5., 0., 4., 0., 0., 0., 0., 6.);
241 result = 3. * s_matrix;
243 SpatialMatrix test_result(3., 0., 0., 0., 0., 21., 0., 6., 0., 0., 24., 0., 0., 0., 9., 27., 0., 0., 0., 0., 18., 12., 0., 0., 0., 15., 0., 0., 15., 0., 12., 0., 0., 0., 0., 18.);
245 EXPECT_EQ (test_result, result);
251 SpatialMatrix s_matrix(1., 0., 0., 0., 0., 7., 0., 2., 0., 0., 8., 0., 0., 0., 3., 9., 0., 0., 0., 0., 6., 4., 0., 0., 0., 5., 0., 0., 5., 0., 4., 0., 0., 0., 0., 6.);
254 result = s_matrix * s_matrix;
256 SpatialMatrix test_result(29., 0., 0., 0., 0., 49., 0., 44., 0., 0., 56., 0., 0., 0., 63., 63., 0., 0., 0., 0., 42., 70., 0., 0., 0., 35., 0., 0., 65., 0., 28., 0., 0., 0., 0., 64.);
258 EXPECT_EQ (test_result, result);
267 SpatialMatrix s_matrix(1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36.);
271 SpatialMatrix test_result_matrix(1., 2., 3., 19., 20., 21., 7., 8., 9., 25., 26., 27., 13., 14., 15., 31., 32., 33., 4., 5., 6., 22., 23., 24., 10., 11., 12., 28., 29., 30., 16., 17., 18., 34., 35., 36.);
273 EXPECT_EQ (test_result_matrix, result);
278 SpatialMatrix s_matrix(0, 1, 2, 0, 1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 8, 6, 7, 8, 0, 1, 2, 0, 1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 8, 6, 7, 8);
280 SpatialMatrix test_inv(0, 3, 6, 0, 3, 6, 1, 4, 7, 1, 4, 7, 2, 5, 8, 2, 5, 8, 0, 3, 6, 0, 3, 6, 1, 4, 7, 1, 4, 7, 2, 5, 8, 2, 5, 8);
287 SpatialMatrix spatial_transform(1., 2., 3., 0., 0., 0., 4., 5., 6., 0., 0., 0., 7., 8., 9., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
291 Matrix3d test_result(1., 2., 3., 4., 5., 6., 7., 8., 9.);
293 EXPECT_EQ(test_result, rotation);
298 SpatialMatrix spatial_transform(0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., -3., 2., 0., 0., 0., 0., 0., -1., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
303 EXPECT_EQ(test_result, translation);
310 SpatialMatrix test_cross(0., -3., 2., 0., 0., 0., 3., 0., -1., 0., 0., 0., -2., 1., 0., 0., 0., 0., 0., -6., 5., 0., -3., 2., 6., 0., -4., 3., 0., -1., -5., 4., 0., -2., 1., 0.);
313 EXPECT_EQ (test_cross, s_vec_cross);
318 EXPECT_EQ (test_crossf, s_vec_crossf);
342 EXPECT_EQ (crossm_s_x_t, crossm_s_t);
343 EXPECT_EQ (crossf_s_x_t, crossf_s_t);
356 X_st.
E = X_66_matrix.block<3, 3>(0, 0);
381 X_st.
E = X_66_matrix.block<3, 3>(0, 0);
418 X_st.
E = X_matrix.block<3, 3>(0, 0);
436 X_st.
E = X_matrix.block<3, 3>(0, 0);
454 X_st.
E = X_matrix.block<3, 3>(0, 0);
482 X_st_1.
E = X_matrix_1.block<3, 3>(0, 0);
484 X_st_2.
E = X_matrix_2.block<3, 3>(0, 0);
510 X_st_1.
E = X_matrix_1.block<3, 3>(0, 0);
512 X_st_2.
E = X_matrix_2.block<3, 3>(0, 0);
549 int main(
int argc,
char **argv)
551 ::testing::InitGoogleTest(&argc, argv);
552 return RUN_ALL_TESTS();
static Vector3d toIntrinsicZYXAngles(const Quaternion &q, double yaw_at_pitch_singularity=0.)
Converte quaternion to intrinsic ZYX euler angles.
SpatialMatrix spatial_adjoint(const SpatialMatrix &m)
SpatialMatrix Xrotx_mat(const double &xrot)
Creates a rotational transformation around the X-axis.
static Quaternion intrinsicXYZAnglesToQuaternion(double roll, double pitch, double yaw)
Convert RPY angles to quaternion.
SpatialTransform Xroty(const double &yrot)
Get transform with zero translation and pure rotation about y axis.
SpatialMatrix crossf(const SpatialVector &v)
Get the spatial force cross matrix.
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
SpatialMatrix spatial_inverse(const SpatialMatrix &m)
SpatialMatrix Xtrans_mat(const Vector3d &displacement)
Creates a transformation of a linear displacement.
static Quaternion toQuaternion(const Vector3d &axis, double angle_rad)
Get quaternion representation of axis and angle.
TEST(SpatialAlgebraTests, euler)
static bool checkVector4dEpsilonClose(const RobotDynamics::Math::Vector4d &v1, const RobotDynamics::Math::Vector4d &v2, const double epsilon)
static Quaternion intrinsicYXZAnglesToQuaternion(double pitch, double roll, double yaw)
Convert PRY angles to quaternion.
SpatialTransform Xrotz(const double &zrot)
Get transform with zero translation and pure rotation about z axis.
Quaternion that are used for singularity free joints.
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
Matrix3d get_rotation(const SpatialMatrix &m)
SpatialMatrix Xroty_mat(const double &yrot)
Creates a rotational transformation around the Y-axis.
static bool checkSpatialMatrixEpsilonClose(const RobotDynamics::Math::SpatialMatrix &t1, const RobotDynamics::Math::SpatialMatrix &t2, const double epsilon)
Math types such as vectors and matrices and utility functions.
static bool checkSpatialVectorsEpsilonClose(const RobotDynamics::Math::SpatialVector &v1, const RobotDynamics::Math::SpatialVector &v2, const double epsilon)
Vector3d get_translation(const SpatialMatrix &m)
int main(int argc, char **argv)
SpatialTransform XeulerZYX(double yaw, double pitch, double roll)
Get transform with zero translation and intrinsic euler z/y/x rotation.
SpatialMatrix crossm(const SpatialVector &v)
Get the spatial motion cross matrix.
SpatialMatrix Xrotz_mat(const double &zrot)
Creates a rotational transformation around the Z-axis.
Eigen::AngleAxisd AxisAngle
static Quaternion intrinsicZYXAnglesToQuaternion(double yaw, double pitch, double roll)
Convert YPR angles to quaternion.
static Matrix3d toMatrix(const Quaternion &q)
Convert quaternion to rotation matrix.
Namespace for all structures of the RobotDynamics library.
static bool checkMatrix3dEpsilonClose(const RobotDynamics::Math::Matrix3d &t1, const RobotDynamics::Math::Matrix3d &t2, const double epsilon)
SpatialTransform Xrot(double angle_rad, const Vector3d &axis)
Get spatial transform from angle and axis.
static AxisAngle toAxisAngle(Quaternion q)
Get axis angle representation of a quaternion.