RigidBodyInertiaTests.cpp
Go to the documentation of this file.
1 //
2 // Created by jordan on 9/10/16.
3 //
4 
5 #include <gtest/gtest.h>
6 #include "UnitTestUtils.hpp"
7 
8 using namespace RobotDynamics::Math;
9 
10 class RigidBodyInertiaTests : public testing::Test
11 {
13  {
14  }
15 };
16 
18 {
19  RigidBodyInertia I(6.1, Vector3d(12.2, 5.3, 2.7), Matrix3d(4.1, 1.5, 2.3, 5.3, 4.1, 1.5, 1.1, 4.5, 5.6));
20  RigidBodyInertia I2(11.1, Vector3d(2.2, 2.3, 1.7), Matrix3d(1.1, 2.5, 3.3, 2.3, 1.1, 3.5, 2.1, 1.5, 1.6));
21 
22  I2.set(I);
23 
24  EXPECT_EQ(I2.m, I.m);
25 
26  EXPECT_EQ(I2.h[0], I.h[0]);
27  EXPECT_EQ(I2.h[1], I.h[1]);
28  EXPECT_EQ(I2.h[2], I.h[2]);
29 
30  EXPECT_EQ(I2.Ixx, I.Ixx);
31  EXPECT_EQ(I2.Iyx, I.Iyx);
32  EXPECT_EQ(I2.Izx, I.Izx);
33  EXPECT_EQ(I2.Iyy, I.Iyy);
34  EXPECT_EQ(I2.Izy, I.Izy);
35  EXPECT_EQ(I2.Izz, I.Izz);
36 }
37 
38 TEST(RigidBodyInertiaTests, testTimes3DofJointMotionSubspaceMatrix)
39 {
40  RigidBodyInertia I(6.1, Vector3d(12.2, 5.3, 2.7), Matrix3d(4.1, 1.5, 2.3, 5.3, 4.1, 1.5, 1.1, 4.5, 5.6));
41  Matrix63 m;
42  for (int i = 0; i < 6; i++)
43  {
44  for (int j = 0; j < 3; j++)
45  {
46  m(i, j) = (double)i + j + i * j;
47  }
48  }
49 
50  Matrix63 m2 = I * m;
51 
53 }
54 
55 TEST(RigidBodyInertiaTests, testSubtractSpatialMatrix)
56 {
57  RigidBodyInertia I(6.1, Vector3d(12.2, 5.3, 2.7), Matrix3d(4.1, 1.5, 2.3, 5.3, 4.1, 1.5, 1.1, 4.5, 5.6));
58  SpatialMatrix m(0.1, 0.2, 0.3, 0.3, 0.2, 0.1, 0.1, 0.2, 0.3, 0.3, 0.2, 0.1, 0.1, 0.2, 0.3, 0.3, 0.2, 0.1, 0.1, 0.2, 0.3, 0.3, 0.2, 0.1, 0.1, 0.2, 0.3, 0.3, 0.2, 0.1,
59  0.1, 0.2, 0.3, 0.3, 0.2, 0.1);
60 
62 
64 }
65 
66 TEST(SpatialAlgebraTests, testMultiplyOperator)
67 {
68  RigidBodyInertia I(6.1, Vector3d(12.2, 5.3, 2.7), Matrix3d(4.1, 1.5, 2.3, 5.3, 4.1, 1.5, 1.1, 4.5, 5.6));
69  SpatialVector v(-13.3355, 1.3318, -0.81, 0.114, 8.1, 3.1);
70 
72 }
73 
75 {
76  RigidBodyInertia I_a(1.1, Vector3d(1.2, 1.3, 1.4), Matrix3d(1.1, 0.5, 0.3, 0.5, 1.2, 0.4, 0.3, 0.4, 1.3));
77  RigidBodyInertia I_b(6.1, Vector3d(12.2, 5.3, 2.7), Matrix3d(4.1, 1.5, 2.3, 5.3, 4.1, 1.5, 1.1, 4.5, 5.6));
78 
79  SpatialMatrix I_expected = I_a.toMatrix() + I_b.toMatrix();
80 
81  RigidBodyInertia I_c = I_a + I_b;
82 
84 }
85 
86 TEST(SpatialAlgebraTests, TestSpatialTransformApplyRigidBodyInertiaFull)
87 {
88  RigidBodyInertia inertia(1.1, Vector3d(1.2, 1.3, 1.4), Matrix3d(1.1, 0.5, 0.3, 0.5, 1.2, 0.4, 0.3, 0.4, 1.3));
89  RigidBodyInertia inertia_copy = inertia;
90 
91  SpatialTransform X(Xrotz(0.5) * Xroty(0.9) * Xrotx(0.2) * Xtrans(Vector3d(1.1, 1.2, 1.3)));
92 
93  SpatialMatrix rbi_matrix_transformed = X.toMatrixAdjoint() * inertia.toMatrix() * X.inverse().toMatrix();
94  inertia.transform(X);
95  inertia_copy.transform(X);
96 
97  EXPECT_TRUE(unit_test_utils::checkSpatialMatrixEpsilonClose(rbi_matrix_transformed, inertia.toMatrix(), unit_test_utils::TEST_PREC));
99 }
100 
101 TEST(SpatialAlgebraTests, TestRigidBodyInertiaCreateFromMatrix)
102 {
103  double mass = 1.1;
104  Vector3d com(0., 0., 0.);
105  Matrix3d inertia(1.1, 0.5, 0.3, 0.5, 1.2, 0.4, 0.3, 0.4, 1.3);
106  RigidBodyInertia body_rbi(mass, com, inertia);
107 
108  SpatialMatrix spatial_inertia = body_rbi.toMatrix();
109 
110  RigidBodyInertia rbi;
111  rbi.createFromMatrix(spatial_inertia);
112 
113  EXPECT_EQ(mass, rbi.m);
114  EXPECT_TRUE(unit_test_utils::checkVector3dEq(Vector3d(mass * com), rbi.h));
115  Matrix3d rbi_I_matrix(rbi.Ixx, rbi.Iyx, rbi.Izx, rbi.Iyx, rbi.Iyy, rbi.Izy, rbi.Izx, rbi.Izy, rbi.Izz);
116  EXPECT_TRUE(unit_test_utils::checkMatrix3dEq(inertia, rbi_I_matrix));
117 }
118 
119 TEST(SpatialAlgebraTests, TestsCreateFromMassComAndInertiaAboutCom)
120 {
121  Matrix3d Ic(1., 2., 3., 2., 3., 4., 3., 4., 5.);
122  Vector3d com(-1., 3.5, -5.1);
123  double mass = 13.2;
124 
125  Matrix3d comTilde = toTildeForm(com);
126  Matrix3d mIdentity = Matrix3dIdentity * mass;
127 
128  RigidBodyInertia I_t(mass, com, Ic);
129 
130  SpatialMatrix m;
131  m.block<3, 3>(0, 0) = Ic + comTilde * comTilde.transpose() * mass;
132  m.block<3, 3>(0, 3) = toTildeForm(com) * mass;
133  m.block<3, 3>(3, 0) = mass * comTilde.transpose();
134  m.block<3, 3>(3, 3) = mIdentity;
135 
136  RigidBodyInertia Ia = createFromMassComInertiaC(mass, com, Ic);
137 
140 }
141 
142 TEST(SpatialAlgebraTests, TestSpatialTransformApplySpatialRigidBodyInertiaAdd)
143 {
144  RigidBodyInertia rbi(1.1, Vector3d(1.2, 1.3, 1.4), Matrix3d(1.1, 0.5, 0.3, 0.5, 1.2, 0.4, 0.3, 0.4, 1.3));
145 
146  SpatialMatrix rbi_matrix_added = rbi.toMatrix() + rbi.toMatrix();
147  RigidBodyInertia rbi_added = rbi + rbi;
148 
149  EXPECT_TRUE(unit_test_utils::checkSpatialMatrixEpsilonClose(rbi_matrix_added, rbi_added.toMatrix(), unit_test_utils::TEST_PREC));
150 }
151 
152 TEST(SpatialAlgebraTests, TestSpatialTransformApplySpatialRigidBodyInertiaFull)
153 {
154  RigidBodyInertia rbi(1.1, Vector3d(1.2, 1.3, 1.4), Matrix3d(1.1, 0.5, 0.3, 0.5, 1.2, 0.4, 0.3, 0.4, 1.3));
155 
156  SpatialTransform X(Xrotz(0.5) * Xroty(0.9) * Xrotx(0.2) * Xtrans(Vector3d(1.1, 1.2, 1.3)));
157 
158  RigidBodyInertia rbi_transformed = rbi.transform_copy(X);
159  SpatialMatrix rbi_matrix_transformed = X.toMatrixAdjoint() * rbi.toMatrix() * X.inverse().toMatrix();
160 
161  EXPECT_TRUE(unit_test_utils::checkSpatialMatrixEpsilonClose(rbi_matrix_transformed, rbi_transformed.toMatrix(), unit_test_utils::TEST_PREC));
162 }
163 
164 TEST(SpatialAlgebraTests, TestSpatialRigidBodyInertiaCreateFromMatrix)
165 {
166  double mass = 1.1;
167  Vector3d com(0., 0., 0.);
168  Matrix3d inertia(1.1, 0.5, 0.3, 0.5, 1.2, 0.4, 0.3, 0.4, 1.3);
169  RigidBodyInertia body_rbi(mass, com, inertia);
170 
171  SpatialMatrix spatial_inertia = body_rbi.toMatrix();
172 
173  RigidBodyInertia rbi;
174  rbi.createFromMatrix(spatial_inertia);
175 
176  EXPECT_EQ(mass, rbi.m);
177  EXPECT_TRUE(unit_test_utils::checkVector3dEq(Vector3d(mass * com), rbi.h));
178  Matrix3d rbi_I_matrix(rbi.Ixx, rbi.Iyx, rbi.Izx, rbi.Iyx, rbi.Iyy, rbi.Izy, rbi.Izx, rbi.Izy, rbi.Izz);
179  EXPECT_TRUE(unit_test_utils::checkMatrix3dEq(inertia, rbi_I_matrix));
180 }
181 
182 int main(int argc, char** argv)
183 {
184  ::testing::InitGoogleTest(&argc, argv);
185  return RUN_ALL_TESTS();
186 }
RigidBodyInertia transform_copy(const SpatialTransform &X) const
Copy, transform, and return a Math::RigidBodyInertia.
TEST(RigidBodyInertiaTests, testSet)
Matrix3d Matrix3dIdentity
SpatialTransform Xroty(const double &yrot)
Get transform with zero translation and pure rotation about y axis.
const double TEST_PREC
SpatialMatrix toMatrix() const
Return transform as 6x6 spatial matrix.
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
static Matrix3d toTildeForm(const Point3d &p)
Definition: Point3.hpp:370
void createFromMatrix(const SpatialMatrix &Ic)
Create a Math::RigidBodyInertia object from a 6x6 Math::SpatialMatrix.
void set(const RigidBodyInertia &I)
Setter.
static bool checkMatrix3dEq(const RobotDynamics::Math::Matrix3d &t1, const RobotDynamics::Math::Matrix3d &t2)
SpatialTransform Xrotz(const double &zrot)
Get transform with zero translation and pure rotation about z axis.
static bool checkVector3dEq(const RobotDynamics::Math::Vector3d &v1, const RobotDynamics::Math::Vector3d &v2)
Compact representation of spatial transformations.
This class stores a bodies mass, center of mass, and inertia information. The inertia elements are st...
SpatialTransform inverse() const
Returns inverse of transform.
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
static bool checkMatrixNdEpsilonClose(const RobotDynamics::Math::MatrixNd &t1, const RobotDynamics::Math::MatrixNd &t2, const double epsilon)
SpatialMatrix toMatrixAdjoint() const
Returns Spatial transform that transforms spatial force vectors.
SpatialMatrix subtractSpatialMatrix(const SpatialMatrix &m) const
Given Math::RigidBodyInertia ad Math::SpatialMatrix , returns Math::SpatialMatrix such that ...
static bool checkSpatialMatrixEpsilonClose(const RobotDynamics::Math::SpatialMatrix &t1, const RobotDynamics::Math::SpatialMatrix &t2, const double epsilon)
void transform(const SpatialTransform &X)
Transform a Math::RigidBodyInertia matrix.
Math types such as vectors and matrices and utility functions.
Definition: ForceVector.hpp:21
static bool checkSpatialVectorsEpsilonClose(const RobotDynamics::Math::SpatialVector &v1, const RobotDynamics::Math::SpatialVector &v2, const double epsilon)
Eigen::Matrix< double, 6, 3 > Matrix63
Definition: rdl_eigenmath.h:24
int main(int argc, char **argv)
static RigidBodyInertia createFromMassComInertiaC(double mass, const Vector3d &com, const Matrix3d &inertia_C)


rdl_dynamics
Author(s):
autogenerated on Tue Apr 20 2021 02:25:28