SpatialAccelerationTests.cpp
Go to the documentation of this file.
1 //
2 // Created by jordan on 10/10/16.
3 //
4 #include "UnitTestUtils.hpp"
5 #include "Fixtures.h"
6 
8 
9 using namespace RobotDynamics::Math;
10 
11 class SpatialAccelerationTests : public testing::Test
12 {
13  public:
15  {
16  }
17 
18  void SetUp()
19  {
20  }
21 
22  void TearDown()
23  {
24  }
25 };
26 
28 {
29  SpatialAcceleration a1(model->bodyFrames[1], ReferenceFrame::getWorldFrame(), ReferenceFrame::getWorldFrame(), 0.1, 0.2, 0.3, -0.1, -0.2, -0.3);
30  SpatialAcceleration a2(model->bodyFrames[2], model->bodyFrames[1], ReferenceFrame::getWorldFrame(), 0.1, 0.2, 0.3, -0.1, -0.2, -0.3);
31 
32  SpatialVector av_1 = a1;
33  SpatialVector av_2 = a2;
34 
35  SpatialAcceleration a3 = a1 + a2;
36 
38 
39  SpatialAcceleration a4 = a3 - a1;
40 
42 
43  a4 = a3 - a2;
44 
46 
47  try
48  {
49  SpatialAcceleration a5(model->bodyFrames[2], model->bodyFrames[1], ReferenceFrame::getWorldFrame(), 0.1, 0.2, 0.3, -0.1, -0.2, -0.3);
50  a5 -= a1;
51  }
52  catch (ReferenceFrameException& e)
53  {
54  EXPECT_STREQ("Reference frame mismatch during subtraction of SpatialAccelerations!", e.what());
55  }
56 }
57 
58 TEST_F(FixedBase3DoFPlanar, testChangeFrame)
59 {
60  Q[0] = -0.25;
61  Q[1] = 0.12;
62  Q[2] = 1.1;
63  QDot[0] = 0.;
64  QDot[1] = 0.;
65  QDot[2] = 0.;
66  QDDot[0] = 0.;
67  QDDot[1] = 0.;
68  QDDot[2] = 0.;
69 
70  updateKinematics(*model, Q, QDot, QDDot);
71 
72  ReferenceFramePtr newFrame = model->bodyFrames[2];
73  ReferenceFramePtr currentExpressedInFrame = ReferenceFrame::getWorldFrame();
74 
75  SpatialAcceleration a2(model->bodyFrames[2], model->bodyFrames[1], currentExpressedInFrame, 0.1, 0.2, 0.3, -0.1, -0.2, -0.3);
76  SpatialVector a2_v = a2;
77 
78  SpatialTransform X = currentExpressedInFrame->getTransformToDesiredFrame(newFrame);
79 
80  SpatialVector v_expected = X.apply(a2_v);
81  a2.changeFrame(newFrame);
82 
84 }
85 
86 TEST_F(FixedBase3DoFPlanar, testchangeFrameWithRelativeMotion)
87 {
88  Q[0] = -0.25;
89  Q[1] = 0.12;
90  Q[2] = 1.1;
91  QDot[0] = 0.1;
92  QDot[1] = 0.2;
93  QDot[2] = 0.3;
94  QDDot[0] = 0.5;
95  QDDot[1] = 0.4;
96  QDDot[2] = 0.3;
97 
98  updateKinematics(*model, Q, QDot, QDDot);
99 
100  ReferenceFramePtr newFrame = model->bodyFrames[2];
101  ReferenceFramePtr currentExpressedInFrame = ReferenceFrame::getWorldFrame();
102  ReferenceFramePtr bodyFrame = model->bodyFrames[2];
103  ReferenceFramePtr baseFrame = model->bodyFrames[1];
104 
105  SpatialAcceleration a2(bodyFrame, baseFrame, currentExpressedInFrame, 0.1, 0.2, 0.3, -0.1, -0.2, -0.3);
106  SpatialVector a2_v = a2;
107 
108  SpatialMotion m2(bodyFrame, baseFrame, currentExpressedInFrame, 0.5, -0.1, -0, .11, 0.23, 0.9);
109  SpatialMotion m1(currentExpressedInFrame, newFrame, currentExpressedInFrame, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
110 
111  SpatialMotion expected = m1 % m2;
112 
113  expected.set(expected.toMotionVector() + a2_v);
114 
115  SpatialTransform X = currentExpressedInFrame->getTransformToDesiredFrame(newFrame);
116  expected.transform(X);
117 
118  a2.changeFrameWithRelativeMotion(newFrame, m1, m2);
119  EXPECT_TRUE(a2.getReferenceFrame() == newFrame);
120 
122 }
123 
124 TEST_F(FixedBase3DoFPlanar, testchangeFrameWithRelativeMotionSameFrame)
125 {
126  Q[0] = -0.25;
127  Q[1] = 0.12;
128  Q[2] = 1.1;
129  QDot[0] = 0.1;
130  QDot[1] = -0.2;
131  QDot[2] = -0.3;
132  QDDot[0] = 1.;
133  QDDot[1] = 2.;
134  QDDot[2] = 3.;
135 
136  updateKinematics(*model, Q, QDot, QDDot);
137 
138  ReferenceFramePtr newFrame = model->bodyFrames[2];
139  ReferenceFramePtr currentExpressedInFrame = ReferenceFrame::getWorldFrame();
140 
141  SpatialAcceleration a2(model->bodyFrames[2], model->bodyFrames[1], currentExpressedInFrame, 0.1, 0.2, 0.3, -0.1, -0.2, -0.3);
142 
143  SpatialMotion m2(currentExpressedInFrame, newFrame, currentExpressedInFrame, 0.5, -0.1, -0, .11, 0.23, 0.9);
144  SpatialMotion m1(model->bodyFrames[2], model->bodyFrames[1], currentExpressedInFrame, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
145 
146  SpatialAcceleration expected = a2;
148 
150 }
151 
152 int main(int argc, char** argv)
153 {
154  ::testing::InitGoogleTest(&argc, argv);
155  return RUN_ALL_TESTS();
156 }
ReferenceFramePtr getReferenceFrame() const
Get a pointer to the reference frame this FrameObject is expressed in.
Definition: FrameObject.hpp:52
VectorNd QDDot
A custom exception for frame operations.
MotionVector toMotionVector() const
Get a copy of this SpatialMotion as type MotionVector.
VectorNd QDot
void transform(const SpatialTransform &X)
Transforms a motion vector. Performs .
TEST_F(FixedBase3DoFPlanar, testAdd)
const double TEST_PREC
VectorNd Q
static ReferenceFramePtr getWorldFrame()
Get a pointer to the world frame.
virtual const char * what() const
EIGEN_STRONG_INLINE void set(const MotionVector &v)
Setter.
int main(int argc, char **argv)
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
Compact representation of spatial transformations.
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
Definition: FrameObject.cpp:12
SpatialVector apply(const SpatialVector &v_sp) const
Transform a spatial vector. Same as .
A SpatialMotion vector is a MotionVector with a RobotDynamics::ReferenceFrame it is expressed in...
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
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)
SpatialAcceleration. For clarity, the ReferenceFrames are stated as follows. A spatial acceleration i...
void changeFrameWithRelativeMotion(ReferenceFramePtr newFrame, SpatialMotion twistOfCurrentFrameWithRespectToNewFrame, const SpatialMotion &twistOfBodyWrtBaseExpressedInCurrent)
Use this method to change the ReferenceFrame::expressedInFrame of a SpatialAcceleration if there is r...


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