SpatialMomentumTests.cpp
Go to the documentation of this file.
1 //
2 // Created by jordan on 9/28/16.
3 //
4 
5 #include <gtest/gtest.h>
6 
7 #include "Fixtures.h"
11 #include "UnitTestUtils.hpp"
12 
13 using namespace RobotDynamics::Math;
14 
15 class SpatialMomentumTests : public testing::Test
16 {
17  public:
19  {
20  }
21 
22  void SetUp()
23  {
24  }
25 
26  void TearDown()
27  {
28  }
29 };
30 
31 TEST_F(SpatialMomentumTests, testKineticEnergyFrameAssertion)
32 {
33  Vector3d rot(1.1, 1.2, 1.3);
34  Vector3d trans(1.1, 1.2, 1.3);
35 
36  SpatialTransform X_st;
37  X_st.r = trans;
38 
39  SpatialMatrix X_66_matrix(SpatialMatrix::Zero(6, 6));
40  X_66_matrix = Xrotz_mat(rot[2]) * Xroty_mat(rot[1]) * Xrotx_mat(rot[0]) * Xtrans_mat(trans);
41  X_st.E = X_66_matrix.block<3, 3>(0, 0);
42 
43  ReferenceFramePtr frameA(new ReferenceFrame("frameA", ReferenceFrame::getWorldFrame(), X_st, 0, 0));
44 
45  SpatialMotion v(frameA, ReferenceFrame::getWorldFrame(), frameA, 1., 2., 3., 4., 5., 6.);
46  SpatialMomentum p(ReferenceFrame::getWorldFrame(), -1., -2., -3., -4., -5., 6.);
47 
48  try
49  {
50  // compute kinetic energy
51  p* v;
52  }
53  catch (ReferenceFrameException& e)
54  {
55  EXPECT_STREQ("Reference frames do not match!", e.what());
56  }
57 
58  ForceVector f(0.1, -0.1, 0.2, -0.2, 0.3, -0.3);
59  SpatialMomentum sm(frameA, f);
60 
61  SpatialMomentum sm2;
62  sm2.setIncludingFrame(frameA, f);
63 
65 }
66 
67 TEST_F(FixedBase3DoFPlanar, testSetWithMomentum)
68 {
69  SpatialMotion v(model->bodyFrames[1], ReferenceFrame::getWorldFrame(), model->bodyFrames[1], 1., 2., 3., 4., 5., 6.);
70  SpatialInertia I(model->bodyFrames[1], 1., Vector3d(0.1, 1.1, 2.1), 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
71 
72  SpatialMomentum m(I, v);
73  Momentum f = I * v;
74 
76 
77  SpatialMomentum m2;
78 
79  SpatialMomentum f_s = I * v;
80 
81  m2.setIncludingFrame(I.getReferenceFrame(), I * v);
82 
84 }
85 
86 TEST_F(FixedBase3DoFPlanar, testKineticEnergy)
87 {
88  Q[0] = 0.;
89  Q[1] = 0.;
90  Q[2] = 0.;
91  QDot[0] = 2.;
92  QDot[1] = -1.;
93  QDot[2] = 3.;
94  QDDot[0] = 0.;
95  QDDot[1] = 0.;
96  QDDot[2] = 0.;
97 
98  updateKinematics(*model, Q, QDot, QDDot);
99 
100  for (size_t i = 1; i < model->mBodies.size(); i++)
101  {
102  ReferenceFramePtr bodyFrame = model->bodyFrames[i];
103  ReferenceFramePtr parentBodyFrame = model->bodyFrames[model->lambda[i]];
104  SpatialMotion m(bodyFrame, parentBodyFrame, bodyFrame, model->v[i]);
105 
106  SpatialMatrix inertia = model->Ic[i].toMatrix();
107  SpatialInertia I(bodyFrame, inertia(3, 3), Vector3d(inertia(2, 4), inertia(0, 5), inertia(1, 3)), inertia(0, 0), inertia(0, 1), inertia(1, 1), inertia(0, 2),
108  inertia(1, 2), inertia(2, 2));
110  SpatialMomentum momentum(I, m);
111  EXPECT_EQ(momentum * m, 0.5 * model->v[i].transpose() * (model->Ic[i] * model->v[i]));
112  }
113 }
114 
115 TEST_F(SpatialMomentumTests, testChangeFrame)
116 {
117  Vector3d rot(1.1, 1.2, 1.3);
118  Vector3d trans(1.1, 1.2, 1.3);
119 
120  SpatialTransform X_st;
121  X_st.r = trans;
122 
123  SpatialMatrix X_66_matrix(SpatialMatrix::Zero(6, 6));
124  X_66_matrix = Xrotz_mat(rot[2]) * Xroty_mat(rot[1]) * Xrotx_mat(rot[0]) * Xtrans_mat(trans);
125  X_st.E = X_66_matrix.block<3, 3>(0, 0);
126 
127  std::shared_ptr<ReferenceFrame> frameA(new ReferenceFrame("frameA", ReferenceFrame::getWorldFrame(), X_st, 0, 0));
128 
129  Momentum v(1.1, 2.1, 3.1, 4.1, 5.1, 6.1);
130 
131  SpatialMomentum m(frameA, v);
132 
133  v.transform(X_st.inverse());
134 
136 
138 }
139 
140 int main(int argc, char** argv)
141 {
142  ::testing::InitGoogleTest(&argc, argv);
143  return RUN_ALL_TESTS();
144 }
ReferenceFramePtr getReferenceFrame() const
Get a pointer to the reference frame this FrameObject is expressed in.
Definition: FrameObject.hpp:52
SpatialMatrix Xrotx_mat(const double &xrot)
Creates a rotational transformation around the X-axis.
VectorNd QDDot
A custom exception for frame operations.
VectorNd QDot
const double TEST_PREC
VectorNd Q
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 ReferenceFramePtr getWorldFrame()
Get a pointer to the world frame.
virtual const char * what() const
void transform(const SpatialTransform &X)
Performs the following in place transform .
A SpatialMomentum is a Momentum expressed in a RobotDynamics::ReferenceFrame. The angular portion of ...
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
Compact representation of spatial transformations.
Momentum is mass/inertia multiplied by velocity.
Definition: Momentum.hpp:27
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
Definition: FrameObject.cpp:12
SpatialTransform inverse() const
Returns inverse of transform.
A SpatialMotion vector is a MotionVector with a RobotDynamics::ReferenceFrame it is expressed in...
int main(int argc, char **argv)
ReferenceFrame object used to tell what frame objects are expressed in. Every ReferenceFrame has a po...
A Math::SpatialInertia is a RigidBodyInertia explicitly expressed in a RobotDynamics::ReferenceFrame...
void updateKinematics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot)
Updates and computes velocities and accelerations of the bodies.
Definition: Kinematics.cc:25
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)
TEST_F(SpatialMomentumTests, testKineticEnergyFrameAssertion)
void setIncludingFrame(ReferenceFramePtr referenceFrame, const RigidBodyInertia &inertia, const MotionVector &vector)
Set a momentum by multiplying the supplied motion vector by the supplied inertia. Set the stored Robo...
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:28