MomentumTests.cpp
Go to the documentation of this file.
1 
2 #include <gtest/gtest.h>
4 #include "UnitTestUtils.hpp"
5 
6 using namespace RobotDynamics::Math;
7 
8 class MomentumTests : public testing::Test
9 {
10  public:
12 
13  void SetUp()
14  {
15  }
16 
17  void TearDown()
18  {
19  }
20 };
21 
22 TEST_F(MomentumTests, testComparisonSpatialVectorCross)
23 {
24  SpatialVector v(-1., 0.11, 0.9, 2., 0.56, -0.33);
25  MotionVector m_v(v);
26  RigidBodyInertia I(1.2, Vector3d(0.2, 0.3, 1.), 1., 2., 3., 4., 5., 6.);
27  RigidBodyInertia I_r(1.2, Vector3d(0.2, 0.3, 1.), 1., 2., 3., 4., 5., 6.);
28  Momentum m(I_r, m_v);
29  MotionVector expected = m_v % m;
30  SpatialVector v_sp_exp = crossf(v, m);
31 
32  SpatialVector v_out;
33  v_out.setAngularPart(toTildeForm(v.getAngularPart()) * m.getAngularPart() + toTildeForm(v.getLinearPart()) * m.getLinearPart()); // crossf(v,I * v);
35 
39 
40  MotionVector m_2(0.1, -0.2, 0.3, -0.4, -05, -0.6);
41 
42  expected = m % m_2;
43 
44  v_sp_exp = crossm(m, m_2);
45 
46  v_out.setAngularPart(toTildeForm(m.getAngularPart()) * m_2.getAngularPart());
47  v_out.setLinearPart(toTildeForm(m.getLinearPart()) * m_2.getAngularPart() + toTildeForm(m.getAngularPart()) * m_2.getLinearPart());
48 
52 }
53 
54 TEST_F(MomentumTests, testConstructorsAndCompute)
55 {
56  MotionVector v(1., 2., 3., 4., 5., 6.);
57  RigidBodyInertia I(1., Vector3d(0.1, 1.1, 2.1), 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
58 
59  Momentum m = I * v;
60 
61  SpatialVector m_v = I.toMatrix() * v;
62 
64 
65  SpatialVector sv(-1.2, 2.2, 3.3, 4.1, 6.2, -0.8);
66 
67  Momentum mv(sv);
68 
70 
71  MotionVector mv2(sv);
72 
73  double kineticEnergy = m * mv2;
74 
75  EXPECT_EQ(kineticEnergy, m.dot(mv2) / 2.);
76 }
77 
78 int main(int argc, char** argv)
79 {
80  ::testing::InitGoogleTest(&argc, argv);
81  return RUN_ALL_TESTS();
82 }
void setAngularPart(const Vector3d &v)
SpatialMatrix crossf(const SpatialVector &v)
Get the spatial force cross matrix.
const double TEST_PREC
void setLinearPart(const Vector3d &v)
static Matrix3d toTildeForm(const Point3d &p)
Definition: Point3.hpp:370
Momentum is mass/inertia multiplied by velocity.
Definition: Momentum.hpp:27
This class stores a bodies mass, center of mass, and inertia information. The inertia elements are st...
TEST_F(MomentumTests, testComparisonSpatialVectorCross)
EIGEN_STRONG_INLINE Vector3d getAngularPart() const
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_STRONG_INLINE Vector3d getLinearPart() const
SpatialMatrix crossm(const SpatialVector &v)
Get the spatial motion cross matrix.
int main(int argc, char **argv)


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