MotionVectorTests.cpp
Go to the documentation of this file.
1 //
2 // Created by jordan on 9/24/16.
3 //
4 
5 #include <gtest/gtest.h>
6 #include "UnitTestUtils.hpp"
7 
8 using namespace RobotDynamics::Math;
9 
10 class MotionVectorTests : public testing::Test
11 {
12  public:
14 
15  void SetUp()
16  {
17  }
18 
19  void TearDown()
20  {
21  }
22 };
23 
24 TEST_F(MotionVectorTests, TestSpatialVectorCross)
25 {
26  MotionVector s_vec(1., 2., 3., 4., 5., 6.);
27 
28  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.,
29  -2., 1., 0.);
30 
31  SpatialMatrix s_vec_cross(s_vec.crossm());
32  EXPECT_EQ(test_cross, s_vec_cross);
33 
34  SpatialMatrix s_vec_crossf(s_vec.crossf());
35  SpatialMatrix test_crossf = -1. * s_vec.crossm().transpose();
36 
37  EXPECT_TRUE(unit_test_utils::checkSpatialMatrixEpsilonClose(test_crossf, s_vec_crossf, unit_test_utils::TEST_PREC));
38 }
39 
40 TEST_F(MotionVectorTests, TestSpatialVectorCrossmCrossf)
41 {
42  MotionVector s_vec(1., 2., 3., 4., 5., 6.);
43  MotionVector t_vec(9., 8., 7., 6., 5., 4.);
44  ForceVector f_vec = t_vec;
45 
46  // by explicitly building the matrices (crossm/f with only one vector)
47  SpatialVector crossm_s_x_t = s_vec.crossm() * t_vec;
48  SpatialVector crossf_s_x_t = s_vec.crossf() * t_vec;
49 
50  // by using direct computation that avoids building of the matrix
51  SpatialVector crossm_s_t = s_vec % t_vec;
52  SpatialVector crossf_s_t = s_vec % f_vec;
53 
56 }
57 
58 TEST_F(MotionVectorTests, testMotionCross)
59 {
60  MotionVector m1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6);
61  ForceVector f1 = m1;
62  MotionVector m2(1.3, 1. - 2, 3.6, 4.44, 23.5, 4.6);
63 
65 
66  crossm.block<3, 3>(0, 0) = toTildeForm(Vector3d(m2.wx(), m2.wy(), m2.wz()));
67  crossm.block<3, 3>(3, 3) = toTildeForm(Vector3d(m2.wx(), m2.wy(), m2.wz()));
68  crossm.block<3, 3>(3, 0) = toTildeForm(Vector3d(m2.vx(), m2.vy(), m2.vz()));
69 
70  crossf.block<3, 3>(0, 0) = toTildeForm(Vector3d(m2.wx(), m2.wy(), m2.wz()));
71  crossf.block<3, 3>(3, 3) = toTildeForm(Vector3d(m2.wx(), m2.wy(), m2.wz()));
72  crossf.block<3, 3>(0, 3) = toTildeForm(Vector3d(m2.vx(), m2.vy(), m2.vz()));
73 
74  MotionVector m3 = crossm * m1;
75  MotionVector m4 = m2 % m1;
76 
78 
79  ForceVector f2 = crossf * f1;
80  ForceVector f3 = m2 % f1;
81 
83 }
84 
85 TEST_F(MotionVectorTests, testConstructorsAndAccessors)
86 {
87  MotionVector m(1.1, 2.2, 3.3, 4.4, 5.5, 6.6);
88 
89  EXPECT_EQ(m.wx(), 1.1);
90  EXPECT_EQ(m.wy(), 2.2);
91  EXPECT_EQ(m.wz(), 3.3);
92  EXPECT_EQ(m.vx(), 4.4);
93  EXPECT_EQ(m.vy(), 5.5);
94  EXPECT_EQ(m.vz(), 6.6);
95 
96  m.wx() = -1.1;
97  m.wy() = -2.2;
98  m.wz() = -3.3;
99  m.vx() = -4.4;
100  m.vy() = -5.5;
101  m.vz() = -6.6;
102 
103  EXPECT_EQ(m.wx(), -1.1);
104  EXPECT_EQ(m.wy(), -2.2);
105  EXPECT_EQ(m.wz(), -3.3);
106  EXPECT_EQ(m.vx(), -4.4);
107  EXPECT_EQ(m.vy(), -5.5);
108  EXPECT_EQ(m.vz(), -6.6);
109 }
110 
111 TEST_F(MotionVectorTests, testTransform)
112 {
113  Vector3d rot(1.1, 1.2, 1.3);
114  Vector3d trans(1.1, 1.2, 1.3);
115 
116  SpatialTransform X_st;
117  X_st.r = trans;
118 
119  SpatialMatrix X_66_matrix(SpatialMatrix::Zero(6, 6));
120  X_66_matrix = Xrotz_mat(rot[2]) * Xroty_mat(rot[1]) * Xrotx_mat(rot[0]) * Xtrans_mat(trans);
121  X_st.E = X_66_matrix.block<3, 3>(0, 0);
122 
123  SpatialVector v(1.1, 2.1, 3.1, 4.1, 5.1, 6.1);
124  MotionVector m(v);
125  MotionVector m2(v);
126  m.transform(X_st);
127  m2 = X_st * m2;
128  SpatialVector v_66_res = X_66_matrix * v;
129 
132 }
133 
134 TEST_F(MotionVectorTests, testOperatorOverloads)
135 {
136  MotionVector m1 = MotionVector(0.1, 0.2, -0.3, -0.1, 1.0, -2.);
137  MotionVector m2 = MotionVector(-0.1, -0.2, 0.3, 0.1, -1.0, 2.);
138 
139  m1 += m2;
141 }
142 
143 int main(int argc, char** argv)
144 {
145  ::testing::InitGoogleTest(&argc, argv);
146  return RUN_ALL_TESTS();
147 }
SpatialMatrix crossm()
Get the spatial motion cross matrix, .
SpatialVector SpatialVectorZero
SpatialMatrix crossf()
Get the spatial force cross matrix.
SpatialMatrix Xrotx_mat(const double &xrot)
Creates a rotational transformation around the X-axis.
int main(int argc, char **argv)
SpatialMatrix crossf(const SpatialVector &v)
Get the spatial force cross matrix.
EIGEN_STRONG_INLINE double & vz()
Get a reference to the linear-z component.
void transform(const SpatialTransform &X)
Transforms a motion vector. Performs .
const double TEST_PREC
SpatialMatrix Xtrans_mat(const Vector3d &displacement)
Creates a transformation of a linear displacement.
A ForceVector is a SpatialVector containing 3 moments and 3 linear forces.
Definition: ForceVector.hpp:27
static Matrix3d toTildeForm(const Point3d &p)
Definition: Point3.hpp:370
EIGEN_STRONG_INLINE double & wx()
Get a reference to the angular-x component.
EIGEN_STRONG_INLINE double & wy()
Get a reference to the angular-y component.
EIGEN_STRONG_INLINE double & vx()
Get a reference to the linear-x component.
Compact representation of spatial transformations.
TEST_F(MotionVectorTests, TestSpatialVectorCross)
EIGEN_STRONG_INLINE double & wz()
Get a reference to the angular-z component.
EIGEN_STRONG_INLINE double & vy()
Get a reference to the linear-y component.
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.
Definition: ForceVector.hpp:21
static bool checkSpatialVectorsEpsilonClose(const RobotDynamics::Math::SpatialVector &v1, const RobotDynamics::Math::SpatialVector &v2, const double epsilon)
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.


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