RdlKinematicsTests.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include "Fixtures.h"
4 #include "Human36Fixture.h"
8 #include "rdl_dynamics/Model.h"
9 #include "UnitTestUtils.hpp"
10 
11 using namespace std;
12 using namespace RobotDynamics;
13 using namespace RobotDynamics::Math;
14 
15 const double TEST_PREC = 1.0e-12;
16 
17 struct RdlKinematicsFixture : public testing::Test
18 {
19  void SetUp()
20  {
21  srand(time(NULL));
22  }
23 
24  void TearDown()
25  {
26  }
27 
29  {
30  for (int i = 0; i < q.rows(); i++)
31  {
32  q[i] = 0.4 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
33  }
34 
35  for (int i = 0; i < qdot.rows(); i++)
36  {
37  qdot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
38  tau[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
39  qddot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
40  }
41  }
42 
44 };
45 
46 struct RdlKinematicsSingleChainFixture : public testing::Test
47 {
49  {
50  srand(time(NULL));
51  }
52 
53  void SetUp()
54  {
55  model = new Model;
56 
57  /* Basically a model like this, where X are the Center of Masses
58  * and the CoM of the last (3rd) body comes out of the Y=X=0 plane.
59  *
60  * X
61  * *
62  * _/
63  * _/ (-Z)
64  * Z /
65  * *---*
66  * |
67  * |
68  * Z |
69  * O---*
70  * Y
71  */
72 
73  body_a = Body(1., Vector3d(1., 0., 0.), Vector3d(1., 1., 1.));
74  joint_a = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
75 
76  body_a_id = model->addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_a, body_a, "body_a");
77 
78  body_b = Body(1., Vector3d(0., 1., 0.), Vector3d(1., 1., 1.));
79  joint_b = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
80 
81  body_b_id = model->addBody(body_a_id, Xtrans(Vector3d(1., 0., 0.)), joint_b, body_b, "body_b");
82 
83  body_c = Body(1., Vector3d(0., 0., 1.), Vector3d(1., 1., 1.));
84  joint_c = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
85 
86  body_c_id = model->addBody(body_b_id, Xtrans(Vector3d(0., 1., 0.)), joint_c, body_c, "body_c");
87 
88  body_d = Body(1., Vector3d(1., 0., 0.), Vector3d(1., 1., 1.));
89  joint_d = Joint(SpatialVector(1., 0., 0., 0., 0., 0.));
90 
91  body_d_id = model->addBody(body_c_id, Xtrans(Vector3d(0., 0., -1.)), joint_d, body_d, "body_d");
92 
93  Q = VectorNd::Constant((size_t)model->dof_count, 0.);
94  QDot = VectorNd::Constant((size_t)model->dof_count, 0.);
95  QDDot = VectorNd::Constant((size_t)model->dof_count, 0.);
96  Tau = VectorNd::Constant((size_t)model->dof_count, 0.);
97  }
98 
100  {
101  for (int i = 0; i < Q.size(); i++)
102  {
103  Q[i] = 0.4 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
104  QDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
105  Tau[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
106  QDDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
107  }
108  }
109 
110  void TearDown()
111  {
113  delete model;
114  }
115 
117 
118  unsigned int body_a_id, body_b_id, body_c_id, body_d_id;
119  Body body_a, body_b, body_c, body_d;
120  Joint joint_a, joint_b, joint_c, joint_d;
121 
126 };
127 
128 struct RdlKinematicsSingleChainFixture6DoF : public testing::Test
129 {
131  {
132  }
133 
134  void SetUp()
135  {
136  model = new Model;
137 
138  model->gravity = SpatialVector(0., 0., 0., 0., -9.81, 0.);
139 
140  /*
141  *
142  * X Contact point (ref child)
143  * |
144  * Base |
145  * / body |
146  * O-------*
147  * \
148  * Child body
149  */
150 
151  // base body (3 DoF)
152  base = Body(1., Vector3d(0.5, 0., 0.), Vector3d(1., 1., 1.));
153  joint_rotzyx = Joint(SpatialVector(0., 0., 1., 0., 0., 0.), SpatialVector(0., 1., 0., 0., 0., 0.), SpatialVector(1., 0., 0., 0., 0., 0.));
154  base_id = model->addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_rotzyx, base);
155 
156  // child body (3 DoF)
157  child = Body(1., Vector3d(0., 0.5, 0.), Vector3d(1., 1., 1.));
158  child_id = model->addBody(base_id, Xtrans(Vector3d(1., 0., 0.)), joint_rotzyx, child);
159 
160  Q = VectorNd::Constant(model->mBodies.size() - 1, 0.);
161  QDot = VectorNd::Constant(model->mBodies.size() - 1, 0.);
162  QDDot = VectorNd::Constant(model->mBodies.size() - 1, 0.);
163  Tau = VectorNd::Constant(model->mBodies.size() - 1, 0.);
164  }
165 
166  void TearDown()
167  {
169  delete model;
170  }
171 
173 
174  unsigned int base_id, child_id;
175  Body base, child;
177 
182 };
183 
184 TEST_F(RdlKinematicsFixture, parallelKinematics)
185 {
186  RobotDynamics::ModelPtr model_parallel(new RobotDynamics::Model());
188  RobotDynamics::Body b(1., Vector3d(0.5, 0., 0.), Vector3d(1., 1., 1.));
190 
191  unsigned int b1_id_p = model_parallel->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b1");
192  unsigned int b2_id_p = model_parallel->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b2");
193  unsigned int b3_id_p = model_parallel->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b3");
194  unsigned int b4_id_p = model_parallel->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b4");
195 
196  unsigned int b5_id_p = model_parallel->addBody(0, RobotDynamics::Math::SpatialTransform(), j, b, "b5");
197  unsigned int b6_id_p = model_parallel->addBody(b5_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b6");
198  unsigned int b7_id_p = model_parallel->addBody(b6_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b7");
199  unsigned int b8_id_p = model_parallel->addBody(b7_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b8");
200 
201  // // Mixing these up intentionally
202  unsigned int b9_id_p = model_parallel->addBody(b5_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b9");
203  unsigned int b13_id_p = model_parallel->addBody(b5_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b13");
204 
205  unsigned int b10_id_p = model_parallel->addBody(b9_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b10");
206  unsigned int b14_id_p = model_parallel->addBody(b13_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b14");
207 
208  unsigned int b11_id_p = model_parallel->addBody(b10_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b11");
209  unsigned int b15_id_p = model_parallel->addBody(b14_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b15");
210 
211  unsigned int b12_id_p = model_parallel->addBody(b11_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b12");
212  unsigned int b16_id_p = model_parallel->addBody(b15_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b16");
213 
214  unsigned int b1_id = model->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b1");
215  unsigned int b2_id = model->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b2");
216  unsigned int b3_id = model->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b3");
217  unsigned int b4_id = model->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b4");
218 
219  unsigned int b5_id = model->addBody(0, RobotDynamics::Math::SpatialTransform(), j, b, "b5");
220  unsigned int b6_id = model->addBody(b5_id, RobotDynamics::Math::SpatialTransform(), j, b, "b6");
221  unsigned int b7_id = model->addBody(b6_id, RobotDynamics::Math::SpatialTransform(), j, b, "b7");
222  unsigned int b8_id = model->addBody(b7_id, RobotDynamics::Math::SpatialTransform(), j, b, "b8");
223 
224  // // Mixing these up intentionally
225  unsigned int b9_id = model->addBody(b5_id, RobotDynamics::Math::SpatialTransform(), j, b, "b9");
226  unsigned int b13_id = model->addBody(b5_id, RobotDynamics::Math::SpatialTransform(), j, b, "b13");
227 
228  unsigned int b10_id = model->addBody(b9_id, RobotDynamics::Math::SpatialTransform(), j, b, "b10");
229  unsigned int b14_id = model->addBody(b13_id, RobotDynamics::Math::SpatialTransform(), j, b, "b14");
230 
231  unsigned int b11_id = model->addBody(b10_id, RobotDynamics::Math::SpatialTransform(), j, b, "b11");
232  unsigned int b15_id = model->addBody(b14_id, RobotDynamics::Math::SpatialTransform(), j, b, "b15");
233 
234  unsigned int b12_id = model->addBody(b11_id, RobotDynamics::Math::SpatialTransform(), j, b, "b12");
235  unsigned int b16_id = model->addBody(b15_id, RobotDynamics::Math::SpatialTransform(), j, b, "b16");
236  q = RobotDynamics::Math::VectorNd::Zero(model->q_size);
237  qdot = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
238  qddot = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
239  tau = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
240  randomizeStates();
241 
242  updateKinematics(*model, q, qdot, qddot);
243  updateKinematicsParallel(*model_parallel, q, qdot, qddot);
244 
245  for (std::pair<std::string, RobotDynamics::ReferenceFramePtr> pair : model->referenceFrameMap)
246  {
247  EXPECT_TRUE(unit_test_utils::checkMatrix3dEpsilonClose(pair.second->getTransformToRoot().E, model_parallel->referenceFrameMap[pair.first]->getTransformToRoot().E,
248  1.e-12));
249  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(pair.second->getTransformToRoot().r, model_parallel->referenceFrameMap[pair.first]->getTransformToRoot().r,
250  1.e-12));
251  }
252 
253  for (unsigned int i = 0; i < model->v.size(); ++i)
254  {
255  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(model->v[i], model_parallel->v[i], 1.e-12));
256  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(model->a[i], model_parallel->a[i], 1.e-12));
257  }
258 }
259 
260 TEST_F(RdlKinematicsFixture, parallelKinematicsCustom)
261 {
262  RobotDynamics::ModelPtr model_parallel(new RobotDynamics::Model());
264  RobotDynamics::Body b(1., Vector3d(0.5, 0., 0.), Vector3d(1., 1., 1.));
266 
267  unsigned int b1_id_p = model_parallel->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b1");
268  unsigned int b2_id_p = model_parallel->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b2");
269  unsigned int b3_id_p = model_parallel->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b3");
270  unsigned int b4_id_p = model_parallel->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b4");
271 
272  unsigned int b5_id_p = model_parallel->addBody(0, RobotDynamics::Math::SpatialTransform(), j, b, "b5");
273  unsigned int b6_id_p = model_parallel->addBody(b5_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b6");
274  unsigned int b7_id_p = model_parallel->addBody(b6_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b7");
275  unsigned int b8_id_p = model_parallel->addBody(b7_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b8");
276 
277  // // Mixing these up intentionally
278  unsigned int b9_id_p = model_parallel->addBody(b5_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b9");
279  unsigned int b13_id_p = model_parallel->addBody(b5_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b13");
280 
281  unsigned int b10_id_p = model_parallel->addBody(b9_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b10");
282  unsigned int b14_id_p = model_parallel->addBody(b13_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b14");
283 
284  unsigned int b11_id_p = model_parallel->addBody(b10_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b11");
285  unsigned int b15_id_p = model_parallel->addBody(b14_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b15");
286 
287  unsigned int b12_id_p = model_parallel->addBody(b11_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b12");
288  unsigned int b16_id_p = model_parallel->addBody(b15_id_p, RobotDynamics::Math::SpatialTransform(), j, b, "b16");
289 
290  unsigned int b1_id = model->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b1");
291  unsigned int b2_id = model->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b2");
292  unsigned int b3_id = model->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b3");
293  unsigned int b4_id = model->appendBody(RobotDynamics::Math::SpatialTransform(), j, b, "b4");
294 
295  unsigned int b5_id = model->addBody(0, RobotDynamics::Math::SpatialTransform(), j, b, "b5");
296  unsigned int b6_id = model->addBody(b5_id, RobotDynamics::Math::SpatialTransform(), j, b, "b6");
297  unsigned int b7_id = model->addBody(b6_id, RobotDynamics::Math::SpatialTransform(), j, b, "b7");
298  unsigned int b8_id = model->addBody(b7_id, RobotDynamics::Math::SpatialTransform(), j, b, "b8");
299 
300  // // Mixing these up intentionally
301  unsigned int b9_id = model->addBody(b5_id, RobotDynamics::Math::SpatialTransform(), j, b, "b9");
302  unsigned int b13_id = model->addBody(b5_id, RobotDynamics::Math::SpatialTransform(), j, b, "b13");
303 
304  unsigned int b10_id = model->addBody(b9_id, RobotDynamics::Math::SpatialTransform(), j, b, "b10");
305  unsigned int b14_id = model->addBody(b13_id, RobotDynamics::Math::SpatialTransform(), j, b, "b14");
306 
307  unsigned int b11_id = model->addBody(b10_id, RobotDynamics::Math::SpatialTransform(), j, b, "b11");
308  unsigned int b15_id = model->addBody(b14_id, RobotDynamics::Math::SpatialTransform(), j, b, "b15");
309 
310  unsigned int b12_id = model->addBody(b11_id, RobotDynamics::Math::SpatialTransform(), j, b, "b12");
311  unsigned int b16_id = model->addBody(b15_id, RobotDynamics::Math::SpatialTransform(), j, b, "b16");
312  q = RobotDynamics::Math::VectorNd::Zero(model->q_size);
313  qdot = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
314  qddot = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
315  tau = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
316  randomizeStates();
317 
318  updateKinematicsCustom(*model, &q, nullptr, nullptr);
319  updateKinematicsCustomParallel(*model_parallel, &q, nullptr, nullptr);
320 
321  for (std::pair<std::string, RobotDynamics::ReferenceFramePtr> pair : model->referenceFrameMap)
322  {
323  EXPECT_TRUE(unit_test_utils::checkMatrix3dEpsilonClose(pair.second->getTransformToRoot().E, model_parallel->referenceFrameMap[pair.first]->getTransformToRoot().E,
324  1.e-12));
325  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(pair.second->getTransformToRoot().r, model_parallel->referenceFrameMap[pair.first]->getTransformToRoot().r,
326  1.e-12));
327  }
328 
329  for (unsigned int i = 0; i < model->v.size(); ++i)
330  {
331  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(model->v[i], model_parallel->v[i], 1.e-12));
332  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(model->a[i], model_parallel->a[i], 1.e-12));
333  }
334 
335  updateKinematicsCustom(*model, &q, &qdot, nullptr);
336  updateKinematicsCustomParallel(*model_parallel, &q, &qdot, nullptr);
337 
338  for (std::pair<std::string, RobotDynamics::ReferenceFramePtr> pair : model->referenceFrameMap)
339  {
340  EXPECT_TRUE(unit_test_utils::checkMatrix3dEpsilonClose(pair.second->getTransformToRoot().E, model_parallel->referenceFrameMap[pair.first]->getTransformToRoot().E,
341  1.e-12));
342  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(pair.second->getTransformToRoot().r, model_parallel->referenceFrameMap[pair.first]->getTransformToRoot().r,
343  1.e-12));
344  }
345 
346  for (unsigned int i = 0; i < model->v.size(); ++i)
347  {
348  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(model->v[i], model_parallel->v[i], 1.e-12));
349  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(model->a[i], model_parallel->a[i], 1.e-12));
350  }
351 
352  updateKinematicsCustom(*model, &q, &qdot, &qddot);
353  updateKinematicsCustomParallel(*model_parallel, &q, &qdot, &qddot);
354 
355  for (std::pair<std::string, RobotDynamics::ReferenceFramePtr> pair : model->referenceFrameMap)
356  {
357  EXPECT_TRUE(unit_test_utils::checkMatrix3dEpsilonClose(pair.second->getTransformToRoot().E, model_parallel->referenceFrameMap[pair.first]->getTransformToRoot().E,
358  1.e-12));
359  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(pair.second->getTransformToRoot().r, model_parallel->referenceFrameMap[pair.first]->getTransformToRoot().r,
360  1.e-12));
361  }
362 
363  for (unsigned int i = 0; i < model->v.size(); ++i)
364  {
365  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(model->v[i], model_parallel->v[i], 1.e-12));
366  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(model->a[i], model_parallel->a[i], 1.e-12));
367  }
368 }
369 
371 {
372  updateKinematics(*model, Q, QDot, QDDot);
373  FramePoint p_a(model->bodyFrames[1], 0., 0., 0.);
374  FramePoint p_b(model->bodyFrames[2], 0., 0., 0.);
375  FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
376  FramePoint p_d(model->bodyFrames[4], 0., 0., 0.);
377  p_a.changeFrame(ReferenceFrame::getWorldFrame());
378  p_b.changeFrame(ReferenceFrame::getWorldFrame());
379  p_c.changeFrame(ReferenceFrame::getWorldFrame());
380  p_d.changeFrame(ReferenceFrame::getWorldFrame());
381 
386 }
387 
388 TEST_F(RdlKinematicsSingleChainFixture, TestPositionBaseRotated90Deg)
389 {
390  Q[0] = M_PI_2;
391 
392  updateKinematics(*model, Q, QDot, QDDot);
393  FramePoint p_a(model->bodyFrames[1], 0., 0., 0.);
394  FramePoint p_b(model->bodyFrames[2], 0., 0., 0.);
395  FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
396  FramePoint p_d(model->bodyFrames[4], 0., 0., 0.);
397  p_a.changeFrame(ReferenceFrame::getWorldFrame());
398  p_b.changeFrame(ReferenceFrame::getWorldFrame());
399  p_c.changeFrame(ReferenceFrame::getWorldFrame());
400  p_d.changeFrame(ReferenceFrame::getWorldFrame());
401 
406 }
407 
408 TEST_F(RdlKinematicsSingleChainFixture, TestPositionBaseRotatedNeg45Deg)
409 {
410  Q[0] = -0.25 * M_PI;
411 
412  updateKinematics(*model, Q, QDot, QDDot);
413  FramePoint p_a(model->bodyFrames[1], 0., 0., 0.);
414  FramePoint p_b(model->bodyFrames[2], 0., 0., 0.);
415  FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
416  FramePoint p_d(model->bodyFrames[4], 0., 0., 0.);
417  p_a.changeFrame(ReferenceFrame::getWorldFrame());
418  p_b.changeFrame(ReferenceFrame::getWorldFrame());
419  p_c.changeFrame(ReferenceFrame::getWorldFrame());
420  p_d.changeFrame(ReferenceFrame::getWorldFrame());
421 
423  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(Vector3d(0.707106781186547, -0.707106781186547, 0.), p_b.vec(), unit_test_utils::TEST_PREC));
425  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(Vector3d(sqrt(2.0), 0., -1.), p_d.vec(), unit_test_utils::TEST_PREC));
426 }
427 
428 TEST_F(RdlKinematicsSingleChainFixture, TestPositionBodyBRotated90Deg)
429 {
430  Q[1] = 0.5 * M_PI;
431 
432  updateKinematics(*model, Q, QDot, QDDot);
433  FramePoint p_a(model->bodyFrames[1], 0., 0., 0.);
434  FramePoint p_b(model->bodyFrames[2], 0., 0., 0.);
435  FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
436  FramePoint p_d(model->bodyFrames[4], 0., 0., 0.);
437  p_a.changeFrame(ReferenceFrame::getWorldFrame());
438  p_b.changeFrame(ReferenceFrame::getWorldFrame());
439  p_c.changeFrame(ReferenceFrame::getWorldFrame());
440  p_d.changeFrame(ReferenceFrame::getWorldFrame());
441 
446 }
447 
448 TEST_F(RdlKinematicsSingleChainFixture, TestPositionBodyBRotatedNeg45Deg)
449 {
450  // We call ForwardDynamics() as it updates the spatial transformation
451  // matrices
452  Q[1] = -0.25 * M_PI;
453 
454  updateKinematics(*model, Q, QDot, QDDot);
455  FramePoint p_a(model->bodyFrames[1], 0., 0., 0.);
456  FramePoint p_b(model->bodyFrames[2], 0., 0., 0.);
457  FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
458  FramePoint p_d(model->bodyFrames[4], 0., 0., 0.);
459  p_a.changeFrame(ReferenceFrame::getWorldFrame());
460  p_b.changeFrame(ReferenceFrame::getWorldFrame());
461  p_c.changeFrame(ReferenceFrame::getWorldFrame());
462  p_d.changeFrame(ReferenceFrame::getWorldFrame());
463 
467  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(Vector3d(1 + 0.707106781186547, 1., -0.707106781186547), p_d.vec(), unit_test_utils::TEST_PREC));
468 }
469 
470 TEST_F(RdlKinematicsSingleChainFixture, TestCalcBodyToBaseCoordinates)
471 {
472  updateKinematics(*model, Q, QDot, QDDot);
473  FramePoint p_c(model->bodyFrames[3], 0., 1., 0.);
474  p_c.changeFrame(ReferenceFrame::getWorldFrame());
475 
477 }
478 
479 TEST_F(RdlKinematicsSingleChainFixture, TestCalcBodyToBaseCoordinatesRotated)
480 {
481  Q[2] = 0.5 * M_PI;
482 
483  updateKinematics(*model, Q, QDot, QDDot);
484  FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
485  p_c.changeFrame(ReferenceFrame::getWorldFrame());
486 
488 
489  p_c.setIncludingFrame(0., 1., 0., model->bodyFrames[3]);
490  p_c.changeFrame(ReferenceFrame::getWorldFrame());
491 
493 
494  // Rotate the other way round
495  Q[2] = -0.5 * M_PI;
496 
497  updateKinematics(*model, Q, QDot, QDDot);
498  p_c.setIncludingFrame(0., 0., 0., model->bodyFrames[3]);
499  p_c.changeFrame(ReferenceFrame::getWorldFrame());
500 
502 
503  p_c.setIncludingFrame(0., 1., 0., model->bodyFrames[3]);
504  p_c.changeFrame(ReferenceFrame::getWorldFrame());
505 
507 
508  // Rotate around the base
509  Q[0] = 0.5 * M_PI;
510  Q[2] = 0.;
511 
512  updateKinematics(*model, Q, QDot, QDDot);
513  p_c.setIncludingFrame(0., 0., 0., model->bodyFrames[3]);
514  p_c.changeFrame(ReferenceFrame::getWorldFrame());
515 
517 
518  p_c.setIncludingFrame(0., 1., 0., model->bodyFrames[3]);
519  p_c.changeFrame(ReferenceFrame::getWorldFrame());
520 
522 }
523 
525 {
526  randomizeStates();
527  ReferenceFramePtr body_a_frame = model->bodyFrames[body_a_id];
528  ReferenceFramePtr body_b_frame = model->bodyFrames[body_b_id];
529  ReferenceFramePtr body_c_frame = model->bodyFrames[body_c_id];
530 
531  SpatialMotion v = calcSpatialVelocity(*model, Q, QDot, body_a_id, body_c_id);
532  v.changeFrame(body_b_frame);
533 
534  MatrixNd G(6, model->qdot_size);
535  G.setZero();
536 
537  calcRelativeBodySpatialJacobian(*model, Q, G, body_a_frame, body_c_frame, body_b_frame);
538 
540 }
541 
542 TEST_F(RdlKinematicsSingleChainFixture, calcPointJacobianFrames)
543 {
544  randomizeStates();
545  ReferenceFramePtr body_a_frame = model->bodyFrames[body_a_id];
546  ReferenceFramePtr body_b_frame = model->bodyFrames[body_b_id];
547  ReferenceFramePtr body_c_frame = model->bodyFrames[body_c_id];
548 
549  MatrixNd G3d(3, model->qdot_size), G3dCheck(3, model->qdot_size);
550  G3d.setZero();
551  G3dCheck.setZero();
552  calcPointJacobian(*model, Q, G3d, body_c_frame);
553  calcPointJacobian(*model, Q, body_b_id, body_c_frame->getTransformFromParent().r, G3dCheck);
554 
555  EXPECT_TRUE(G3d.isApprox(G3dCheck, unit_test_utils::TEST_PREC));
556 
557  randomizeStates();
558 
559  unsigned int fb_id = model->addBody(body_c_id, RobotDynamics::Math::Xtrans(RobotDynamics::Math::Vector3d(0.1, -0.2, 0.3)),
561 
562  RobotDynamics::ReferenceFramePtr fb_frame = model->getReferenceFrame("fb1");
563 
564  G3d.setZero();
565  G3dCheck.setZero();
566  calcPointJacobian(*model, Q, G3d, fb_frame);
567  calcPointJacobian(*model, Q, body_c_id, RobotDynamics::Math::Vector3d(0.1, -0.2, 0.3), G3dCheck);
568 
569  EXPECT_TRUE(G3d.isApprox(G3dCheck, unit_test_utils::TEST_PREC));
570 
572  body_c, "fb2");
573 
574  fb_frame = model->getReferenceFrame("fb2");
575 
576  G3d.setZero();
577  G3dCheck.setZero();
578  calcPointJacobian(*model, Q, G3d, fb_frame);
579  calcPointJacobian(*model, Q, fb_id, RobotDynamics::Math::Vector3d(0.2, -0.3, 0.4), G3dCheck);
580 
581  EXPECT_TRUE(G3d.isApprox(G3dCheck, unit_test_utils::TEST_PREC));
582 }
583 
584 TEST_F(RdlKinematicsSingleChainFixture, calcPointJacobian6DFrames)
585 {
586  randomizeStates();
587  updateKinematicsCustom(*model, &Q, &QDot, nullptr);
588  ReferenceFramePtr body_a_frame = model->bodyFrames[body_a_id];
589  ReferenceFramePtr body_b_frame = model->bodyFrames[body_b_id];
590  ReferenceFramePtr body_c_frame = model->bodyFrames[body_c_id];
591 
592  MatrixNd G(6, model->qdot_size), GCheck(6, model->qdot_size);
593  G.setZero();
594  GCheck.setZero();
595  calcPointJacobian6D(*model, Q, G, body_c_frame, false);
596  calcPointJacobian6D(*model, Q, body_c_id, RobotDynamics::Math::Vector3dZero, GCheck, false);
597 
598  EXPECT_TRUE(G.isApprox(GCheck, unit_test_utils::TEST_PREC));
600  RobotDynamics::Math::FrameVectorPair p = calcPointVelocity6D(*model, Q, QDot, body_c_frame, false);
601  EXPECT_TRUE(v.getLinearPart().isApprox(p.linear(), TEST_PREC));
602  EXPECT_TRUE(v.getAngularPart().isApprox(p.angular(), TEST_PREC));
603 
604  randomizeStates();
605  updateKinematicsCustom(*model, &Q, &QDot, nullptr);
606 
607  unsigned int fb_id = model->addBody(body_c_id, RobotDynamics::Math::Xtrans(RobotDynamics::Math::Vector3d(0.1, -0.2, 0.3)),
609 
610  RobotDynamics::ReferenceFramePtr fb_frame = model->getReferenceFrame("fb1");
611 
612  G.setZero();
613  GCheck.setZero();
614  calcPointJacobian6D(*model, Q, G, fb_frame, false);
615  calcPointJacobian6D(*model, Q, fb_id, RobotDynamics::Math::Vector3dZero, GCheck, false);
616 
617  EXPECT_TRUE(G.isApprox(GCheck, unit_test_utils::TEST_PREC));
618  p = calcPointVelocity6D(*model, Q, QDot, fb_frame, false);
619  v = G * QDot;
620  EXPECT_TRUE(v.getLinearPart().isApprox(p.linear(), TEST_PREC));
621  EXPECT_TRUE(v.getAngularPart().isApprox(p.angular(), TEST_PREC));
622 
623  fb_id = model->addBody(fb_id, RobotDynamics::Math::Xtrans(RobotDynamics::Math::Vector3d(0.2, -0.3, 0.4)),
625 
626  fb_frame = model->getReferenceFrame("fb2");
627 
628  G.setZero();
629  GCheck.setZero();
630  calcPointJacobian6D(*model, Q, G, fb_frame, false);
631  calcPointJacobian6D(*model, Q, fb_id, RobotDynamics::Math::Vector3dZero, GCheck, false);
632 
633  EXPECT_TRUE(G.isApprox(GCheck, unit_test_utils::TEST_PREC));
634  p = calcPointVelocity6D(*model, Q, QDot, fb_frame, false);
635  v = G * QDot;
636  EXPECT_TRUE(v.getLinearPart().isApprox(p.linear(), TEST_PREC));
637  EXPECT_TRUE(v.getAngularPart().isApprox(p.angular(), TEST_PREC));
638 }
639 
640 TEST_F(RdlKinematicsSingleChainFixture, calcRelativePointJacobian6DFrames)
641 {
642  randomizeStates();
643  updateKinematicsCustom(*model, &Q, &QDot, nullptr);
644  ReferenceFramePtr body_a_frame = model->bodyFrames[body_a_id];
645  ReferenceFramePtr body_b_frame = model->bodyFrames[body_b_id];
646  ReferenceFramePtr body_c_frame = model->bodyFrames[body_c_id];
647 
648  MatrixNd G(6, model->qdot_size);
649  G.setZero();
650  calcRelativePointJacobian6D(*model, Q, G, body_c_frame, body_b_frame, model->worldFrame, false);
651 
652  calcPointVelocity6D(*model, Q, QDot, body_c_frame, false);
653  calcPointVelocity6D(*model, Q, QDot, body_b_frame, false);
654 
655  FrameVectorPair p = calcPointVelocity6D(*model, Q, QDot, body_c_frame, false) - calcPointVelocity6D(*model, Q, QDot, body_b_frame, false);
656  SpatialVector v = G * QDot;
659 
660  G.setZero();
661 
662  calcRelativePointJacobian6D(*model, Q, G, body_c_frame, body_b_frame, body_a_frame, false);
663  p = calcPointVelocity6D(*model, Q, QDot, body_c_frame, false) - calcPointVelocity6D(*model, Q, QDot, body_b_frame, false);
664  p.changeFrame(body_a_frame);
665  v = G * QDot;
668 
669  G.setZero();
670  calcRelativePointJacobian6D(*model, Q, G, body_b_frame, body_c_frame, model->worldFrame, false);
671  p = calcPointVelocity6D(*model, Q, QDot, body_b_frame, false) - calcPointVelocity6D(*model, Q, QDot, body_c_frame, false);
672  v = G * QDot;
675 
676  unsigned int fb_id = model->addBody(body_c_id, RobotDynamics::Math::Xtrans(RobotDynamics::Math::Vector3d(0.1, -0.2, 0.3)),
678 
679  RobotDynamics::ReferenceFramePtr fb_frame = model->getReferenceFrame("fb1");
680 
681  G.setZero();
682  calcRelativePointJacobian6D(*model, Q, G, body_b_frame, fb_frame, model->worldFrame, false);
683  p = calcPointVelocity6D(*model, Q, QDot, body_b_frame, false) - calcPointVelocity6D(*model, Q, QDot, fb_frame, false);
684  v = G * QDot;
687 
688  fb_id = model->addBody(fb_id, RobotDynamics::Math::Xtrans(RobotDynamics::Math::Vector3d(0.2, -0.3, 0.4)),
690 
691  RobotDynamics::ReferenceFramePtr fb_frame2 = model->getReferenceFrame("fb2");
692 
693  G.setZero();
694  calcRelativePointJacobian6D(*model, Q, G, fb_frame, fb_frame2, model->worldFrame, false);
695  p = calcPointVelocity6D(*model, Q, QDot, fb_frame, false) - calcPointVelocity6D(*model, Q, QDot, fb_frame2, false);
696  v = G * QDot;
699 }
700 
701 TEST_F(RdlKinematicsSingleChainFixture, calcPointJacobianDotFrames)
702 {
703  randomizeStates();
704  ReferenceFramePtr body_a_frame = model->bodyFrames[body_a_id];
705  ReferenceFramePtr body_b_frame = model->bodyFrames[body_b_id];
706  ReferenceFramePtr body_c_frame = model->bodyFrames[body_c_id];
707 
708  MatrixNd G3d(3, model->qdot_size), G3dCheck(3, model->qdot_size);
709  G3d.setZero();
710  G3dCheck.setZero();
711  calcPointJacobianDot(*model, Q, QDot, body_c_frame, G3d);
712  calcPointJacobianDot(*model, Q, QDot, body_c_id, RobotDynamics::Math::Vector3dZero, G3dCheck);
713 
714  EXPECT_TRUE(G3d.isApprox(G3dCheck, unit_test_utils::TEST_PREC));
715 
716  randomizeStates();
717 
718  unsigned int fb_id = model->addBody(body_c_id, RobotDynamics::Math::Xtrans(RobotDynamics::Math::Vector3d(0.1, -0.2, 0.3)),
720 
721  RobotDynamics::ReferenceFramePtr fb_frame = model->getReferenceFrame("fb1");
722 
723  G3d.setZero();
724  G3dCheck.setZero();
725  calcPointJacobianDot(*model, Q, QDot, fb_frame, G3d);
726  calcPointJacobianDot(*model, Q, QDot, fb_id, RobotDynamics::Math::Vector3dZero, G3dCheck);
727 
728  EXPECT_TRUE(G3d.isApprox(G3dCheck, unit_test_utils::TEST_PREC));
729 
730  unsigned int fb_id2 = model->addBody(fb_id, RobotDynamics::Math::Xtrans(RobotDynamics::Math::Vector3d(0.2, -0.3, 0.4)),
732 
733  fb_frame = model->getReferenceFrame("fb2");
734 
735  G3d.setZero();
736  G3dCheck.setZero();
737  calcPointJacobianDot(*model, Q, QDot, fb_frame, G3d);
738  calcPointJacobianDot(*model, Q, QDot, fb_id2, RobotDynamics::Math::Vector3dZero, G3dCheck);
739 
740  EXPECT_TRUE(G3d.isApprox(G3dCheck, unit_test_utils::TEST_PREC));
741 }
742 
744 {
745  randomizeStates();
746  QDDot.setZero(); // Needs to have zero accel until a method is written for calculating general accelerations
747  ReferenceFramePtr body_a_frame = model->bodyFrames[body_a_id];
748  ReferenceFramePtr body_b_frame = model->bodyFrames[body_b_id];
749  ReferenceFramePtr body_c_frame = model->bodyFrames[body_c_id];
750 
751  MatrixNd GDot(6, model->qdot_size);
752  GDot.setZero();
753 
754  updateKinematics(*model, Q, QDot, QDDot);
755 
756  ReferenceFramePtr f1 = body_a_frame;
757  ReferenceFramePtr f2 = body_b_frame;
758  ReferenceFramePtr f3 = body_c_frame;
759  calcRelativeBodySpatialJacobianDot(*model, Q, QDot, GDot, f3, f1, f2);
760 
761  SpatialAcceleration a_calc = calcSpatialAcceleration(*model, Q, QDot, QDDot, f3, f1, f2);
763 }
764 
766 {
767  randomizeStates();
768  QDDot.setZero(); // Needs to have zero accel until a method is written for calculating general accelerations
769  ReferenceFramePtr body_a_frame = model->bodyFrames[body_a_id];
770  ReferenceFramePtr body_b_frame = model->bodyFrames[body_b_id];
771  ReferenceFramePtr body_c_frame = model->bodyFrames[body_c_id];
772 
773  MatrixNd GDot(6, model->qdot_size), G(6, model->qdot_size), GDot2(6, model->qdot_size), G2(6, model->qdot_size);
774  G.setZero();
775  G2.setZero();
776  GDot.setZero();
777  GDot2.setZero();
778 
779  updateKinematics(*model, Q, QDot, QDDot);
780 
781  ReferenceFramePtr f1 = body_a_frame;
782  ReferenceFramePtr f2 = body_b_frame;
783  ReferenceFramePtr f3 = body_c_frame;
784  calcRelativeBodySpatialJacobianDot(*model, Q, QDot, GDot, f3, f1, f2);
785  calcRelativeBodySpatialJacobian(*model, Q, G, f3, f1, f2);
786 
787  calcRelativeBodySpatialJacobianAndJacobianDot(*model, Q, QDot, G2, GDot2, f3, f1, f2);
788 
791 }
792 
794 {
795  model->gravity.setZero();
796 
797  Body b1(1., Vector3d(0., 0., -0.1), Vector3d(1., 1., 1.));
799 
800  model->addBody(0, SpatialTransform(), jx, b1, "b1");
801  model->appendBody(Xtrans(Vector3d(0., 0., -1.)), jx, b1, "b2");
802  model->appendBody(Xtrans(Vector3d(0., 0., -2.)), jx, b1, "b3");
803 
804  VectorNd Q(model->q_size);
805  VectorNd QDot(model->qdot_size);
806  VectorNd QDDot(model->qdot_size);
807  VectorNd Tau(model->qdot_size);
808  Q.setZero();
809  Q[0] = 1.1;
810  Q[1] = -0.3;
811  QDot.setZero();
812  QDDot.setZero();
813  QDot[0] = 0.1;
814  QDot[1] = 0.1;
815  QDot[2] = 0.1;
816 
817  MatrixNd GDot(6, model->qdot_size);
818  GDot.setZero();
819 
820  updateKinematics(*model, Q, QDot, QDDot);
821 
822  ReferenceFramePtr f1 = model->bodyFrames[model->GetBodyId("b3")];
823  ReferenceFramePtr f2 = model->bodyFrames[model->GetBodyId("b1")];
824  ReferenceFramePtr f3 = model->worldFrame;
825  ReferenceFramePtr f4 = model->bodyFrames[model->GetBodyId("b2")];
826 
827  calcRelativeBodySpatialJacobianDot(*model, Q, QDot, GDot, f2, f1, f2);
828 
829  SpatialAcceleration a_calc = calcSpatialAcceleration(*model, Q, QDot, QDDot, f2, f1, f2);
831 }
832 
834 {
835  model->gravity.setZero();
836 
837  Body b1(1., Vector3d(0., 0., -0.1), Vector3d(1., 1., 1.));
839 
840  model->addBody(0, SpatialTransform(), jx, b1, "b1");
841  model->appendBody(Xtrans(Vector3d(0., 0., -1.)), jx, b1, "b2");
842  model->appendBody(Xtrans(Vector3d(0., 0., -2.)), jx, b1, "b3");
843 
844  VectorNd Q(model->q_size);
845  VectorNd QDot(model->qdot_size);
846  VectorNd QDDot(model->qdot_size);
847  VectorNd Tau(model->qdot_size);
848  Q.setZero();
849  Q[0] = 1.1;
850  Q[1] = -0.3;
851  QDot.setZero();
852  QDDot.setZero();
853  QDot[0] = 0.1;
854  QDot[1] = 0.1;
855  QDot[2] = 0.1;
856 
857  MatrixNd GDot(6, model->qdot_size), G(6, model->qdot_size), GDot2(6, model->qdot_size), G2(6, model->qdot_size);
858  G.setZero();
859  G2.setZero();
860  GDot.setZero();
861  GDot2.setZero();
862 
863  updateKinematics(*model, Q, QDot, QDDot);
864 
865  ReferenceFramePtr f1 = model->bodyFrames[model->GetBodyId("b3")];
866  ReferenceFramePtr f2 = model->bodyFrames[model->GetBodyId("b1")];
867  ReferenceFramePtr f3 = model->worldFrame;
868  ReferenceFramePtr f4 = model->bodyFrames[model->GetBodyId("b2")];
869 
870  calcRelativeBodySpatialJacobianDot(*model, Q, QDot, GDot, f2, f1, f2);
871  calcRelativeBodySpatialJacobian(*model, Q, G, f2, f1, f2);
872  calcRelativeBodySpatialJacobianAndJacobianDot(*model, Q, QDot, G2, GDot2, f2, f1, f2);
873 
876 }
877 
879 {
880  randomizeStates();
881  ReferenceFramePtr body_root_frame = model->bodyFrames[root_body_id];
882  ReferenceFramePtr body_1_frame = model->bodyFrames[body_1_id];
883  ReferenceFramePtr body_2_frame = model->bodyFrames[body_2_id];
884 
885  SpatialMotion v = calcSpatialVelocity(*model, Q, QDot, body_1_id, body_2_id);
886  v.changeFrame(body_root_frame);
887 
888  MatrixNd G(6, model->qdot_size);
889  G.setZero();
890 
891  calcRelativeBodySpatialJacobian(*model, Q, G, body_1_frame, body_2_frame, body_root_frame);
892 
894 }
895 
897 {
898  randomizeStates();
899  QDDot.setZero(); // Needs to have zero accel until a method is written for calculating general accelerations
900  ReferenceFramePtr body_a_frame = model->bodyFrames[root_body_id];
901  ReferenceFramePtr body_b_frame = model->bodyFrames[body_1_id];
902  ReferenceFramePtr body_c_frame = model->bodyFrames[body_2_id];
903 
904  MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size);
905  G.setZero();
906  GDot.setZero();
907 
908  updateKinematics(*model, Q, QDot, QDDot);
909 
910  ReferenceFramePtr f1 = body_b_frame;
911  ReferenceFramePtr f2 = body_c_frame;
912  ReferenceFramePtr f3 = body_a_frame;
913 
914  calcRelativeBodySpatialJacobianDot(*model, Q, QDot, GDot, f3, f1, f2, false);
915  SpatialAcceleration a_calc = calcSpatialAcceleration(*model, Q, QDot, QDDot, f3, f1, f2, false);
916 
918 }
919 
921 {
922  randomizeStates();
923  QDDot.setZero(); // Needs to have zero accel until a method is written for calculating general accelerations
924  ReferenceFramePtr body_a_frame = model->bodyFrames[root_body_id];
925  ReferenceFramePtr body_b_frame = model->bodyFrames[body_1_id];
926  ReferenceFramePtr body_c_frame = model->bodyFrames[body_2_id];
927 
928  MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size), G2(6, model->qdot_size), GDot2(6, model->qdot_size);
929  G.setZero();
930  GDot.setZero();
931  G2.setZero();
932  GDot2.setZero();
933 
934  updateKinematics(*model, Q, QDot, QDDot);
935 
936  ReferenceFramePtr f1 = body_b_frame;
937  ReferenceFramePtr f2 = body_c_frame;
938  ReferenceFramePtr f3 = body_a_frame;
939 
940  calcRelativeBodySpatialJacobianDot(*model, Q, QDot, GDot, f3, f1, f2, false);
941  calcRelativeBodySpatialJacobian(*model, Q, G, f3, f1, f2, false);
942  calcRelativeBodySpatialJacobianAndJacobianDot(*model, Q, QDot, G2, GDot2, f3, f1, f2, false);
943 
946 }
947 
949 {
950  randomizeStates();
951  ReferenceFramePtr body_fixed_frame = model->fixedBodyFrames[body_fixed_id - model->fixed_body_discriminator];
952 
953  ReferenceFramePtr body_a_frame = model->bodyFrames[body_a_id];
954  ReferenceFramePtr body_b_frame = model->bodyFrames[body_b_id];
955 
956  SpatialMotion v = calcSpatialVelocity(*model, Q, QDot, body_a_id, body_b_id);
957  v.changeFrame(body_fixed_frame);
958 
959  MatrixNd G(6, model->qdot_size);
960  G.setZero();
961 
962  calcRelativeBodySpatialJacobian(*model, Q, G, body_a_frame, body_b_frame, body_fixed_frame);
963 
965 
966  v = calcSpatialVelocity(*model, Q, QDot, body_fixed_id, body_b_id);
967  v.changeFrame(body_a_frame);
968 
969  G.setZero();
970 
971  calcRelativeBodySpatialJacobian(*model, Q, G, body_fixed_frame, body_b_frame, body_a_frame);
972 
974 
975  v = calcSpatialVelocity(*model, Q, QDot, body_b_id, body_fixed_id);
976  v.changeFrame(body_a_frame);
977 
978  G.setZero();
979 
980  calcRelativeBodySpatialJacobian(*model, Q, G, body_b_frame, body_fixed_frame, body_a_frame);
981 
983 }
984 
986 {
987  randomizeStates();
988  unsigned int body_trunk_id = model_3dof->GetBodyId("middletrunk");
989  unsigned int body_hand_r_id = model_3dof->GetBodyId("hand_r");
990  unsigned int body_hand_l_id = model_3dof->GetBodyId("hand_l");
991  ReferenceFramePtr body_trunk_frame = model_3dof->bodyFrames[body_trunk_id];
992  ReferenceFramePtr body_hand_r_frame = model_3dof->bodyFrames[body_hand_r_id];
993  ReferenceFramePtr body_hand_l_frame = model_3dof->bodyFrames[body_hand_l_id];
994 
995  SpatialMotion v = calcSpatialVelocity(*model_3dof, q, qdot, body_hand_r_id, body_hand_l_id);
996  v.changeFrame(body_trunk_frame);
997 
998  MatrixNd G(6, model_3dof->qdot_size);
999  G.setZero();
1000 
1001  calcRelativeBodySpatialJacobian(*model_3dof, q, G, body_hand_r_frame, body_hand_l_frame, body_trunk_frame);
1002 
1004 }
1005 
1006 TEST_F(Human36, calcRelativeBodySpatialJacobianDotEmulated)
1007 {
1008  randomizeStates();
1009  qddot.setZero();
1010  unsigned int body_trunk_id = model_emulated->GetBodyId("middletrunk");
1011  unsigned int body_hand_r_id = model_emulated->GetBodyId("hand_r");
1012  unsigned int body_hand_l_id = model_emulated->GetBodyId("hand_l");
1013  ReferenceFramePtr body_trunk_frame = model_emulated->bodyFrames[body_trunk_id];
1014  ReferenceFramePtr body_hand_r_frame = model_emulated->bodyFrames[body_hand_r_id];
1015  ReferenceFramePtr body_hand_l_frame = model_emulated->bodyFrames[body_hand_l_id];
1016 
1017  updateKinematics(*model_emulated, q, qdot, qddot);
1018 
1019  MatrixNd GDot(6, model_emulated->qdot_size);
1020  GDot.setZero();
1021 
1022  ReferenceFramePtr f1 = body_trunk_frame;
1023  ReferenceFramePtr f2 = body_hand_r_frame;
1024  ReferenceFramePtr f3 = body_hand_l_frame;
1025  calcRelativeBodySpatialJacobianDot(*model_emulated, q, qdot, GDot, f1, f2, f3, false);
1026 
1027  SpatialAcceleration a_calc = calcSpatialAcceleration(*model_emulated, q, qdot, qddot, f1, f2, f3, false);
1028  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(a_calc, GDot * qdot, unit_test_utils::TEST_PREC * 10.0));
1029 }
1030 
1031 TEST_F(Human36, calcRelativeBodySpatialJacobianAndJacobianDotEmulated)
1032 {
1033  randomizeStates();
1034  qddot.setZero();
1035  unsigned int body_trunk_id = model_emulated->GetBodyId("middletrunk");
1036  unsigned int body_hand_r_id = model_emulated->GetBodyId("hand_r");
1037  unsigned int body_hand_l_id = model_emulated->GetBodyId("hand_l");
1038  ReferenceFramePtr body_trunk_frame = model_emulated->bodyFrames[body_trunk_id];
1039  ReferenceFramePtr body_hand_r_frame = model_emulated->bodyFrames[body_hand_r_id];
1040  ReferenceFramePtr body_hand_l_frame = model_emulated->bodyFrames[body_hand_l_id];
1041 
1042  updateKinematics(*model_emulated, q, qdot, qddot);
1043 
1044  MatrixNd GDot(6, model_emulated->qdot_size), G(6, model_emulated->qdot_size), GDot2(6, model_emulated->qdot_size), G2(6, model_emulated->qdot_size);
1045  GDot.setZero();
1046  G.setZero();
1047  G2.setZero();
1048  GDot2.setZero();
1049 
1050  ReferenceFramePtr f1 = body_trunk_frame;
1051  ReferenceFramePtr f2 = body_hand_r_frame;
1052  ReferenceFramePtr f3 = body_hand_l_frame;
1053  calcRelativeBodySpatialJacobianDot(*model_emulated, q, qdot, GDot, f1, f2, f3, false);
1054  calcRelativeBodySpatialJacobian(*model_emulated, q, G, f1, f2, f3, false);
1055  calcRelativeBodySpatialJacobianAndJacobianDot(*model_emulated, q, qdot, G2, GDot2, f1, f2, f3, false);
1056 
1059 }
1060 
1061 TEST_F(Human36, calcRelativeBodySpatialJacobianDot3Dof)
1062 {
1063  randomizeStates();
1064  unsigned int body_trunk_id = model_3dof->GetBodyId("middletrunk");
1065  unsigned int body_hand_r_id = model_3dof->GetBodyId("hand_r");
1066  unsigned int body_hand_l_id = model_3dof->GetBodyId("hand_l");
1067  ReferenceFramePtr body_trunk_frame = model_3dof->bodyFrames[body_trunk_id];
1068  ReferenceFramePtr body_hand_r_frame = model_3dof->bodyFrames[body_hand_r_id];
1069  ReferenceFramePtr body_hand_l_frame = model_3dof->bodyFrames[body_hand_l_id];
1070 
1071  updateKinematics(*model_3dof, q, qdot, qddot);
1072 
1073  MatrixNd GDot(6, model_3dof->qdot_size), G(6, model_3dof->qdot_size);
1074  GDot.setZero();
1075  G.setZero();
1076 
1077  ReferenceFramePtr f1 = body_trunk_frame;
1078  ReferenceFramePtr f2 = body_hand_r_frame;
1079  ReferenceFramePtr f3 = body_hand_l_frame;
1080  calcRelativeBodySpatialJacobianDot(*model_3dof, q, qdot, GDot, f1, f2, f3, false);
1081  calcRelativeBodySpatialJacobian(*model_3dof, q, G, f1, f2, f3, false);
1082 
1083  SpatialAcceleration a_calc = calcSpatialAcceleration(*model_3dof, q, qdot, qddot, f1, f2, f3, false);
1084 
1085  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(a_calc, GDot * qdot + G * qddot, unit_test_utils::TEST_PREC * 10.));
1086 }
1087 
1088 TEST_F(Human36, calcRelativeBodySpatialJacobianAndJacobianDot3Dof)
1089 {
1090  randomizeStates();
1091  unsigned int body_trunk_id = model_3dof->GetBodyId("middletrunk");
1092  unsigned int body_hand_r_id = model_3dof->GetBodyId("hand_r");
1093  unsigned int body_hand_l_id = model_3dof->GetBodyId("hand_l");
1094  ReferenceFramePtr body_trunk_frame = model_3dof->bodyFrames[body_trunk_id];
1095  ReferenceFramePtr body_hand_r_frame = model_3dof->bodyFrames[body_hand_r_id];
1096  ReferenceFramePtr body_hand_l_frame = model_3dof->bodyFrames[body_hand_l_id];
1097 
1098  updateKinematics(*model_3dof, q, qdot, qddot);
1099 
1100  MatrixNd GDot(6, model_3dof->qdot_size), G(6, model_3dof->qdot_size), GDot2(6, model_3dof->qdot_size), G2(6, model_3dof->qdot_size);
1101  GDot.setZero();
1102  G.setZero();
1103  GDot2.setZero();
1104  G2.setZero();
1105 
1106  ReferenceFramePtr f1 = body_trunk_frame;
1107  ReferenceFramePtr f2 = body_hand_r_frame;
1108  ReferenceFramePtr f3 = body_hand_l_frame;
1109  calcRelativeBodySpatialJacobianDot(*model_3dof, q, qdot, GDot, f1, f2, f3, false);
1110  calcRelativeBodySpatialJacobian(*model_3dof, q, G, f1, f2, f3, false);
1111  calcRelativeBodySpatialJacobianAndJacobianDot(*model_3dof, q, qdot, G2, GDot2, f1, f2, f3, false);
1112 
1115 }
1116 
1117 TEST_F(Human36, calcRelativeBodySpatialJacobianDot3DofFixedBody)
1118 {
1119  randomizeStates();
1120  unsigned int body_trunk_id = model_3dof->GetBodyId("uppertrunk");
1121  unsigned int body_hand_r_id = model_3dof->GetBodyId("hand_r");
1122  unsigned int body_hand_l_id = model_3dof->GetBodyId("hand_l");
1123  ReferenceFramePtr body_trunk_frame = model_3dof->fixedBodyFrames[body_trunk_id - model_3dof->fixed_body_discriminator];
1124  ReferenceFramePtr body_hand_r_frame = model_3dof->bodyFrames[body_hand_r_id];
1125  ReferenceFramePtr body_hand_l_frame = model_3dof->bodyFrames[body_hand_l_id];
1126 
1127  updateKinematics(*model_3dof, q, qdot, qddot);
1128 
1129  MatrixNd GDot(6, model_3dof->qdot_size), G(6, model_3dof->qdot_size);
1130  GDot.setZero();
1131  G.setZero();
1132 
1133  ReferenceFramePtr f1 = body_trunk_frame;
1134  ReferenceFramePtr f2 = body_hand_r_frame;
1135  ReferenceFramePtr f3 = body_hand_l_frame;
1136  calcRelativeBodySpatialJacobianDot(*model_3dof, q, qdot, GDot, f1, f2, f3, false);
1137  calcRelativeBodySpatialJacobian(*model_3dof, q, G, f1, f2, f3, false);
1138 
1139  SpatialAcceleration a_calc = calcSpatialAcceleration(*model_3dof, q, qdot, qddot, f1, f2, f3, false);
1140  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(a_calc, GDot * qdot + G * qddot, unit_test_utils::TEST_PREC * 10.));
1141 
1142  G.setZero();
1143  GDot.setZero();
1144  calcRelativeBodySpatialJacobianDot(*model_3dof, q, qdot, GDot, f2, f1, f3, false);
1145  calcRelativeBodySpatialJacobian(*model_3dof, q, G, f2, f1, f3, false);
1146 
1147  a_calc = calcSpatialAcceleration(*model_3dof, q, qdot, qddot, f2, f1, f3, false);
1148  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(a_calc, GDot * qdot + G * qddot, unit_test_utils::TEST_PREC * 10.));
1149 
1150  G.setZero();
1151  GDot.setZero();
1152  calcRelativeBodySpatialJacobianDot(*model_3dof, q, qdot, GDot, f3, f2, f1, false);
1153  calcRelativeBodySpatialJacobian(*model_3dof, q, G, f3, f2, f1, false);
1154 
1155  a_calc = calcSpatialAcceleration(*model_3dof, q, qdot, qddot, f3, f2, f1, false);
1156  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(a_calc, GDot * qdot + G * qddot, unit_test_utils::TEST_PREC * 10.));
1157 }
1158 
1159 TEST_F(Human36, calcRelativeBodySpatialJacobianAndJacobianDot3DofFixedBody)
1160 {
1161  randomizeStates();
1162  unsigned int body_trunk_id = model_3dof->GetBodyId("uppertrunk");
1163  unsigned int body_hand_r_id = model_3dof->GetBodyId("hand_r");
1164  unsigned int body_hand_l_id = model_3dof->GetBodyId("hand_l");
1165  ReferenceFramePtr body_trunk_frame = model_3dof->fixedBodyFrames[body_trunk_id - model_3dof->fixed_body_discriminator];
1166  ReferenceFramePtr body_hand_r_frame = model_3dof->bodyFrames[body_hand_r_id];
1167  ReferenceFramePtr body_hand_l_frame = model_3dof->bodyFrames[body_hand_l_id];
1168 
1169  updateKinematics(*model_3dof, q, qdot, qddot);
1170 
1171  MatrixNd GDot(6, model_3dof->qdot_size), G(6, model_3dof->qdot_size), GDot2(6, model_3dof->qdot_size), G2(6, model_3dof->qdot_size);
1172  GDot.setZero();
1173  G.setZero();
1174  GDot2.setZero();
1175  G2.setZero();
1176 
1177  ReferenceFramePtr f1 = body_trunk_frame;
1178  ReferenceFramePtr f2 = body_hand_r_frame;
1179  ReferenceFramePtr f3 = body_hand_l_frame;
1180  calcRelativeBodySpatialJacobianDot(*model_3dof, q, qdot, GDot, f1, f2, f3, false);
1181  calcRelativeBodySpatialJacobian(*model_3dof, q, G, f1, f2, f3, false);
1182  calcRelativeBodySpatialJacobianAndJacobianDot(*model_3dof, q, qdot, G2, GDot2, f1, f2, f3, false);
1183 
1186 
1187  G.setZero();
1188  GDot.setZero();
1189  G2.setZero();
1190  GDot2.setZero();
1191  calcRelativeBodySpatialJacobianDot(*model_3dof, q, qdot, GDot, f2, f1, f3, false);
1192  calcRelativeBodySpatialJacobian(*model_3dof, q, G, f2, f1, f3, false);
1193  calcRelativeBodySpatialJacobianAndJacobianDot(*model_3dof, q, qdot, G2, GDot2, f2, f1, f3, false);
1194 
1197 
1198  G.setZero();
1199  GDot.setZero();
1200  G2.setZero();
1201  GDot2.setZero();
1202  calcRelativeBodySpatialJacobianDot(*model_3dof, q, qdot, GDot, f3, f2, f1, false);
1203  calcRelativeBodySpatialJacobian(*model_3dof, q, G, f3, f2, f1, false);
1204  calcRelativeBodySpatialJacobianAndJacobianDot(*model_3dof, q, qdot, G2, GDot2, f3, f2, f1, false);
1205 
1208 }
1209 
1211 {
1212  Model model;
1213  Body base_body(1., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
1214 
1215  unsigned int base_body_id = model.addBody(0, SpatialTransform(),
1216  Joint(SpatialVector(0., 0., 0., 1., 0., 0.), SpatialVector(0., 0., 0., 0., 1., 0.), SpatialVector(0., 0., 0., 0., 0., 1.),
1217  SpatialVector(0., 0., 1., 0., 0., 0.), SpatialVector(0., 1., 0., 0., 0., 0.), SpatialVector(1., 0., 0., 0., 0., 0.)),
1218  base_body, "b1");
1219 
1220  Body fixed_body(1., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
1221  Body fixed_body_2(1.1, Vector3d(1., 1., 1.), Vector3d(1.2, 1.3, 1.4));
1222 
1223  unsigned int fixed_body1_id = model.addBody(base_body_id, SpatialTransform(Xtrans(Vector3d(0.01, 0.02, 0.03))), Joint(JointTypeFixed), base_body, "fb1");
1224  unsigned int fixed_body2_id = model.addBody(base_body_id, SpatialTransform(Xtrans(Vector3d(-0.18, -0.05, 0.051))), Joint(JointTypeFixed), base_body, "fb2");
1225 
1226  VectorNd Q = VectorNd::Constant((size_t)model.dof_count, 0.);
1227  VectorNd QDot = VectorNd::Constant((size_t)model.dof_count, 0.);
1228  MatrixNd G = MatrixNd::Constant(3, model.dof_count, 0.);
1229  MatrixNd G2 = MatrixNd::Constant(3, model.dof_count, 0.);
1230  Vector3d point_position(1.1, 1.2, 2.1);
1231  FrameVector point_velocity_ref;
1232  Vector3d point_velocity;
1233 
1234  Q[0] = 1.1;
1235  Q[1] = 1.2;
1236  Q[2] = 1.3;
1237  Q[3] = 0.7;
1238  Q[4] = 0.8;
1239  Q[5] = 0.9;
1240 
1241  QDot[0] = -1.1;
1242  QDot[1] = 2.2;
1243  QDot[2] = 1.3;
1244  QDot[3] = -2.7;
1245  QDot[4] = 1.8;
1246  QDot[5] = -2.9;
1247 
1248  // Compute the reference velocity
1249  point_velocity_ref = calcPointVelocity(model, Q, QDot, base_body_id, point_position);
1250 
1251  G.setZero();
1252 
1253  calcPointJacobian(model, Q, base_body_id, point_position, G);
1254 
1255  point_velocity = G * QDot;
1256 
1257  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(point_velocity_ref, point_velocity, unit_test_utils::TEST_PREC));
1259 
1260  point_position = Vector3d(0.2, -0.1, 0.8);
1261 
1262  point_velocity_ref = calcPointVelocity(model, Q, QDot, fixed_body1_id, point_position);
1263 
1264  G.setZero();
1265 
1266  calcPointJacobian(model, Q, fixed_body1_id, point_position, G);
1267 
1268  point_velocity = G * QDot;
1269 
1270  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(point_velocity_ref, point_velocity, unit_test_utils::TEST_PREC));
1272 
1273  point_position = Vector3d(1.2, -1.1, 1.8);
1274 
1275  point_velocity_ref = calcPointVelocity(model, Q, QDot, fixed_body2_id, point_position);
1276 
1277  G.setZero();
1278 
1279  calcPointJacobian(model, Q, fixed_body2_id, point_position, G);
1280 
1281  point_velocity = G * QDot;
1282 
1283  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(point_velocity_ref, point_velocity, unit_test_utils::TEST_PREC));
1285 }
1286 
1287 TEST_F(RdlKinematicsSingleChainFixture, TestInverseKinematicSimple)
1288 {
1289  std::vector<unsigned int> body_ids;
1290  std::vector<Vector3d> body_points;
1291  std::vector<Vector3d> target_pos;
1292 
1293  Q[0] = 0.2;
1294  Q[1] = 0.1;
1295  Q[2] = 0.1;
1296 
1297  VectorNd Qres = VectorNd::Zero((size_t)model->dof_count);
1298 
1299  unsigned int body_id = body_d_id;
1300  Vector3d body_point = Vector3d(1., 0., 0.);
1301  Vector3d target(1.3, 0., 0.);
1302 
1303  body_ids.push_back(body_d_id);
1304  body_points.push_back(body_point);
1305  target_pos.push_back(target);
1306 
1307  bool res = inverseKinematics(*model, Q, body_ids, body_points, target_pos, Qres);
1308  EXPECT_EQ(true, res);
1309 
1310  updateKinematicsCustom(*model, &Qres, NULL, NULL);
1311 
1312  FramePoint p(model->bodyFrames[body_id], body_point);
1313  p.changeFrame(ReferenceFrame::getWorldFrame());
1314 
1315  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(target, p.vec(), TEST_PREC));
1316 }
1317 
1318 TEST_F(RdlKinematicsSingleChainFixture6DoF, TestInverseKinematicUnreachable)
1319 {
1320  std::vector<unsigned int> body_ids;
1321  std::vector<Vector3d> body_points;
1322  std::vector<Vector3d> target_pos;
1323 
1324  Q[0] = 0.2;
1325  Q[1] = 0.1;
1326  Q[2] = 0.1;
1327 
1328  VectorNd Qres = VectorNd::Zero((size_t)model->dof_count);
1329 
1330  unsigned int body_id = child_id;
1331  Vector3d body_point = Vector3d(1., 0., 0.);
1332  Vector3d target(2.2, 0., 0.);
1333 
1334  body_ids.push_back(body_id);
1335  body_points.push_back(body_point);
1336  target_pos.push_back(target);
1337 
1338  bool res = inverseKinematics(*model, Q, body_ids, body_points, target_pos, Qres, 1.0e-8, 0.9, 1000);
1339 
1340  EXPECT_EQ(true, res);
1341 
1342  updateKinematicsCustom(*model, &Qres, NULL, NULL);
1343 
1344  FramePoint p(model->bodyFrames[body_id], body_point);
1345  p.changeFrame(ReferenceFrame::getWorldFrame());
1346 
1347  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(Vector3d(2.0, 0., 0.), p.vec(), 1.0e-7));
1348 }
1349 
1350 TEST_F(RdlKinematicsSingleChainFixture6DoF, TestInverseKinematicTwoPoints)
1351 {
1352  std::vector<unsigned int> body_ids;
1353  std::vector<Vector3d> body_points;
1354  std::vector<Vector3d> target_pos;
1355 
1356  Q[0] = 0.2;
1357  Q[1] = 0.1;
1358  Q[2] = 0.1;
1359 
1360  VectorNd Qres = VectorNd::Zero((size_t)model->dof_count);
1361 
1362  unsigned int body_id = child_id;
1363  Vector3d body_point = Vector3d(1., 0., 0.);
1364  Vector3d target(2., 0., 0.);
1365 
1366  body_ids.push_back(body_id);
1367  body_points.push_back(body_point);
1368  target_pos.push_back(target);
1369 
1370  body_ids.push_back(base_id);
1371  body_points.push_back(Vector3d(0.6, 1.0, 0.));
1372  target_pos.push_back(Vector3d(0.5, 1.1, 0.));
1373 
1374  bool res = inverseKinematics(*model, Q, body_ids, body_points, target_pos, Qres, 1.0e-3, 0.9, 200);
1375  EXPECT_EQ(true, res);
1376 
1377  updateKinematicsCustom(*model, &Qres, NULL, NULL);
1378 
1379  FramePoint p(model->bodyFrames[body_ids[0]], body_points[0]);
1380  p.changeFrame(ReferenceFrame::getWorldFrame());
1381  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(target_pos[0], p.vec(), 1.0e-1));
1382 
1383  p.setIncludingFrame(body_points[1], model->bodyFrames[body_ids[1]]);
1384  p.changeFrame(ReferenceFrame::getWorldFrame());
1385  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(target_pos[1], p.vec(), 1.0e-1));
1386 }
1387 
1388 TEST_F(RdlKinematicsSingleChainFixture6DoF, FixedJointBodyCalcBodyToBase)
1389 {
1390  // the standard modeling using a null body
1391  Body null_body;
1392  Body body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1393  Body fixed_body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1394 
1395  Model model;
1396 
1397  Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.));
1398  model.addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_rot_z, body);
1399  model.appendBody(Xtrans(Vector3d(0., 1., 0.)), Joint(JointTypeFixed), fixed_body);
1400 
1401  VectorNd Q_zero = VectorNd::Zero(model.dof_count);
1402 
1403  FramePoint p(model.fixedBodyFrames[0], 1., 1., 0.1);
1404 
1405  p.changeFrame(model.worldFrame);
1406 
1407  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(Vector3d(1., 2., 0.1), p.vec(), TEST_PREC));
1409 }
1410 
1411 TEST_F(RdlKinematicsSingleChainFixture6DoF, FixedJointBodyCalcBodyToBaseRotated)
1412 {
1413  // the standard modeling using a null body
1414  Body null_body;
1415  Body body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1416  Body fixed_body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1417 
1418  Model model;
1419 
1420  Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.));
1421  model.addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_rot_z, body);
1422  model.appendBody(Xtrans(Vector3d(1., 0., 0.)), Joint(JointTypeFixed), fixed_body);
1423 
1424  VectorNd Q = VectorNd::Zero(model.dof_count);
1425 
1426  Q[0] = M_PI * 0.5;
1427 
1428  updateKinematicsCustom(model, &Q, nullptr, nullptr);
1429  FramePoint p(model.fixedBodyFrames[0], Vector3d(1., 0., 0.));
1430 
1431  p.changeFrame(ReferenceFrame::getWorldFrame());
1432  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(Vector3d(0., 2., 0.), p.vec(), TEST_PREC));
1434 }
1435 
1436 TEST_F(RdlKinematicsSingleChainFixture6DoF, FixedJointBodyCalcBaseToBody)
1437 {
1438  // the standard modeling using a null body
1439  Body null_body;
1440  Body body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1441  Body fixed_body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1442 
1443  Model model;
1444 
1445  Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.));
1446  model.addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_rot_z, body);
1447  model.appendBody(Xtrans(Vector3d(0., 1., 0.)), Joint(JointTypeFixed), fixed_body);
1448 
1449  VectorNd Q_zero = VectorNd::Zero(model.dof_count);
1450 
1451  updateKinematicsCustom(model, &Q_zero, nullptr, nullptr);
1452  FramePoint p(ReferenceFrame::getWorldFrame(), Vector3d(1., 2., 0.1));
1453 
1454  p.changeFrame(model.fixedBodyFrames[0]);
1455 
1456  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(Vector3d(1., 1., 0.1), p.vec(), TEST_PREC));
1458 }
1459 
1460 TEST_F(RdlKinematicsSingleChainFixture6DoF, FixedJointBodyCalcBaseToBodyRotated)
1461 {
1462  // the standard modeling using a null body
1463  Body null_body;
1464  Body body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1465  Body fixed_body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1466 
1467  Model model;
1468 
1469  Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.));
1470  model.addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_rot_z, body);
1471  model.appendBody(Xtrans(Vector3d(1., 0., 0.)), Joint(JointTypeFixed), fixed_body);
1472 
1473  VectorNd Q = VectorNd::Zero(model.dof_count);
1474 
1475  Q[0] = M_PI * 0.5;
1476 
1477  updateKinematicsCustom(model, &Q, nullptr, nullptr);
1478  FramePoint p(ReferenceFrame::getWorldFrame(), Vector3d(0., 2., 0.));
1479 
1480  p.changeFrame(model.fixedBodyFrames[0]);
1481 
1482  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(Vector3d(1., 0., 0.), p.vec(), TEST_PREC));
1484 }
1485 
1486 TEST_F(RdlKinematicsSingleChainFixture6DoF, FixedJointBodyWorldOrientation)
1487 {
1488  // the standard modeling using a null body
1489  Body null_body;
1490  Body body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1491  Body fixed_body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1492 
1493  Model model;
1494 
1495  Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.));
1496  model.addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_rot_z, body);
1497 
1498  SpatialTransform transform = Xrotz(0.25) * Xtrans(Vector3d(1., 2., 3.));
1499  unsigned int fixed_body_id = model.appendBody(transform, Joint(JointTypeFixed), fixed_body);
1500 
1501  updateKinematicsCustom(model, &Q, nullptr, nullptr);
1502  VectorNd Q_zero = VectorNd::Zero(model.dof_count);
1503  Matrix3d orientation = model.fixedBodyFrames[fixed_body_id - model.fixed_body_discriminator]->getInverseTransformToRoot().E;
1504 
1505  Matrix3d reference = transform.E;
1506 
1507  EXPECT_TRUE(unit_test_utils::checkMatrix3dEpsilonClose(reference, orientation, TEST_PREC));
1509 }
1510 
1511 TEST_F(RdlKinematicsSingleChainFixture6DoF, FixedJointCalcPointJacobian)
1512 {
1513  // the standard modeling using a null body
1514  Body null_body;
1515  Body body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1516  Body fixed_body(1., Vector3d(1., 0.4, 0.4), Vector3d(1., 1., 1.));
1517 
1518  Model model;
1519 
1520  Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.));
1521  model.addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_rot_z, body);
1522 
1523  SpatialTransform transform = Xrotz(0.25) * Xtrans(Vector3d(1., 2., 3.));
1524  unsigned int fixed_body_id = model.appendBody(transform, Joint(JointTypeFixed), fixed_body);
1525 
1526  VectorNd Q = VectorNd::Zero(model.dof_count);
1527  VectorNd QDot = VectorNd::Zero(model.dof_count);
1528 
1529  Q[0] = 1.1;
1530  QDot[0] = 1.2;
1531 
1532  Vector3d point_position(1., 0., 0.);
1533 
1534  MatrixNd G = MatrixNd::Zero(3, model.dof_count);
1535  calcPointJacobian(model, Q, fixed_body_id, point_position, G);
1536  Vector3d point_velocity_jacobian = G * QDot;
1537  FrameVector point_velocity_reference = calcPointVelocity(model, Q, QDot, fixed_body_id, point_position);
1538 
1539  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(point_velocity_reference, point_velocity_jacobian, TEST_PREC));
1541 }
1542 
1543 TEST_F(Human36, SpatialJacobianSimple)
1544 {
1545  randomizeStates();
1546 
1547  unsigned int foot_r_id = model->GetBodyId("foot_r");
1548  MatrixNd G(MatrixNd::Zero(6, model->dof_count));
1549 
1550  calcBodySpatialJacobian(*model, q, foot_r_id, G);
1551 
1552  updateKinematicsCustom(*model, &q, &qdot, NULL);
1553  SpatialVector v_body = SpatialVector(G * qdot);
1554 
1555  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(model->v[foot_r_id], v_body, TEST_PREC));
1556 
1557  G.setZero();
1558  calcBodySpatialJacobian(*model_3dof, q, foot_r_id, G);
1559 
1560  updateKinematicsCustom(*model_3dof, &q, &qdot, NULL);
1561  v_body = SpatialVector(G * qdot);
1562 
1563  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(model_3dof->v[foot_r_id], v_body, TEST_PREC));
1564 }
1565 
1566 TEST_F(Human36, SpatialJacobianFixedBody)
1567 {
1568  randomizeStates();
1569 
1570  unsigned int uppertrunk_id = model->GetBodyId("uppertrunk");
1571  MatrixNd G(MatrixNd::Zero(6, model->dof_count));
1572 
1573  updateKinematicsCustom(*model, &q, &qdot, NULL);
1574  calcBodySpatialJacobian(*model, q, uppertrunk_id, G);
1575 
1576  unsigned int fixed_body_id = uppertrunk_id - model->fixed_body_discriminator;
1577  unsigned int movable_parent = model->mFixedBodies[fixed_body_id].mMovableParent;
1578 
1579  updateKinematicsCustom(*model, &q, &qdot, NULL);
1580  SpatialVector v_body = SpatialVector(G * qdot);
1581 
1582  SpatialVector v_fixed_body = model->mFixedBodies[fixed_body_id].mParentTransform.apply(model->v[movable_parent]);
1583 
1584  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(v_fixed_body, v_body, TEST_PREC));
1585 }
1586 
1587 TEST_F(Human36, CalcPointJacobian6D)
1588 {
1589  unsigned int foot_r_id = model->GetBodyId("foot_r");
1590  Body nullBody(0., Vector3d(0., 0., 0.), Vector3d(0., 0., 0.));
1591  Vector3d point_local(1.1, 2.2, 3.3);
1592 
1593  model->addBody(foot_r_id, Xtrans(point_local), Joint(JointTypeFixed), nullBody, "right_sole_frame");
1594  randomizeStates();
1595 
1596  // Compute the 6-D velocity using the 6-D Jacobian
1597  MatrixNd G(MatrixNd::Zero(6, model->dof_count));
1598  calcPointJacobian6D(*model, q, foot_r_id, point_local, G);
1599  SpatialVector v_foot_0_jac = SpatialVector(G * qdot);
1600 
1601  updateKinematicsCustom(*model, &q, &qdot, NULL);
1602 
1603  FrameVectorPair v_f = calcPointVelocity6D(*model, q, qdot, model->GetBodyId("right_sole_frame"), Vector3d(0., 0., 0.), false);
1604 
1605  EXPECT_TRUE(v_f.linear().isApprox(v_foot_0_jac.getLinearPart(), TEST_PREC));
1606  EXPECT_TRUE(v_f.angular().isApprox(v_foot_0_jac.getAngularPart(), TEST_PREC));
1607 }
1608 
1609 TEST_F(Human36, CalcPointJacobian6DRelative)
1610 {
1611  unsigned int foot_r_id = model->GetBodyId("foot_r");
1612  Body nullBody(0., Vector3d(0., 0., 0.), Vector3d(0., 0., 0.));
1613  Vector3d point_local(1.1, 2.2, 3.3);
1614 
1615  model->addBody(foot_r_id, Xtrans(point_local), Joint(JointTypeFixed), nullBody, "right_sole_frame");
1616  randomizeStates();
1617 
1618  updateKinematicsCustom(*model, &q, &qdot, nullptr);
1619  // Compute the 6-D velocity using the 6-D Jacobian
1620  MatrixNd G(MatrixNd::Zero(6, model->dof_count));
1621  ReferenceFramePtr baseFrame = model->getReferenceFrame("foot_r");
1622  ReferenceFramePtr relFrame = model->getReferenceFrame("pelvis");
1623  ReferenceFramePtr expressedInFrame = model->getReferenceFrame("right_sole_frame");
1624 
1625  calcRelativePointJacobian6D(*model, q, G, baseFrame, relFrame, expressedInFrame, false);
1626  SpatialVector v_foot_0_jac = SpatialVector(G * qdot);
1627 
1628  FrameVectorPair v_f = calcPointVelocity6D(*model, q, qdot, baseFrame, relFrame, expressedInFrame, false);
1629  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(v_foot_0_jac.getLinearPart(), v_f.linear(), TEST_PREC));
1630  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(v_foot_0_jac.getAngularPart(), v_f.angular(), TEST_PREC));
1631 
1632  G.setZero();
1633  baseFrame = model->getReferenceFrame("pelvis");
1634  relFrame = model->getReferenceFrame("foot_r");
1635  expressedInFrame = model->getReferenceFrame("right_sole_frame");
1636 
1637  calcRelativePointJacobian6D(*model, q, G, baseFrame, relFrame, expressedInFrame, false);
1638  v_foot_0_jac = SpatialVector(G * qdot);
1639 
1640  v_f = calcPointVelocity6D(*model, q, qdot, baseFrame, relFrame, expressedInFrame, false);
1641 
1642  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(v_foot_0_jac.getLinearPart(), v_f.linear(), TEST_PREC));
1643  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(v_foot_0_jac.getAngularPart(), v_f.angular(), TEST_PREC));
1644 
1645  G.setZero();
1646  baseFrame = model->getReferenceFrame("right_sole_frame");
1647  relFrame = model->getReferenceFrame("foot_r");
1648  expressedInFrame = model->getReferenceFrame("pelvis");
1649 
1650  calcRelativePointJacobian6D(*model, q, G, baseFrame, relFrame, expressedInFrame, false);
1651  v_foot_0_jac = SpatialVector(G * qdot);
1652 
1653  v_f = calcPointVelocity6D(*model, q, qdot, baseFrame, relFrame, expressedInFrame, false);
1654 
1655  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(v_foot_0_jac.getLinearPart(), v_f.linear(), TEST_PREC));
1656  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(v_foot_0_jac.getAngularPart(), v_f.angular(), TEST_PREC));
1657 }
1658 
1659 TEST_F(Human36, CalcPointVelocity6D)
1660 {
1661  randomizeStates();
1662 
1663  unsigned int foot_r_id = model->GetBodyId("foot_r");
1664  Vector3d point_local(1.1, 2.2, 3.3);
1665 
1666  // Compute the 6-D velocity
1667  updateKinematicsCustom(*model, &q, &qdot, nullptr);
1668  FrameVectorPair v_foot_0 = calcPointVelocity6D(*model, q, qdot, foot_r_id, point_local, false);
1669 
1670  // Compute the 6-D velocity by transforming the body velocity to the
1671  // reference point and aligning it with the base coordinate system
1672  FramePoint p(model->bodyFrames[foot_r_id], point_local);
1673  p.changeFrame(ReferenceFrame::getWorldFrame());
1674 
1675  SpatialTransform X_foot(Matrix3d::Identity(), p.vec());
1676  updateKinematicsCustom(*model, &q, &qdot, NULL);
1677  SpatialVector v_foot_0_ref = X_foot.apply(model->bodyFrames[foot_r_id]->getTransformToRoot().apply(model->v[foot_r_id]));
1678 
1679  EXPECT_TRUE(v_foot_0_ref.getLinearPart().isApprox(v_foot_0.linear(), TEST_PREC));
1680  EXPECT_TRUE(v_foot_0_ref.getAngularPart().isApprox(v_foot_0.angular(), TEST_PREC));
1681 }
1682 
1683 TEST_F(Human36, CalcPointVelocity6DFrames)
1684 {
1685  randomizeStates();
1686 
1687  unsigned int foot_r_id = model->GetBodyId("foot_r");
1688 
1689  // Compute the 6-D velocity
1690  updateKinematicsCustom(*model, &q, &qdot, nullptr);
1691  FrameVectorPair v_foot_0 = calcPointVelocity6D(*model, q, qdot, foot_r_id, RobotDynamics::Math::Vector3dZero, false);
1692  FrameVectorPair v_foot_0_frame = calcPointVelocity6D(*model, q, qdot, model->getReferenceFrame("foot_r"), false);
1693 
1694  EXPECT_TRUE(v_foot_0.linear().isApprox(v_foot_0_frame.linear(), unit_test_utils::TEST_PREC));
1695  EXPECT_TRUE(v_foot_0.angular().isApprox(v_foot_0_frame.angular(), unit_test_utils::TEST_PREC));
1696 }
1697 
1699 {
1700  randomizeStates();
1701  ReferenceFramePtr body_a_frame = model->bodyFrames[body_a_id];
1702  ReferenceFramePtr body_b_frame = model->bodyFrames[body_b_id];
1703  ReferenceFramePtr body_c_frame = model->bodyFrames[body_c_id];
1704 
1706  FrameVectorPair v_frame = calcPointVelocity6D(*model, Q, QDot, body_b_frame, false);
1707  EXPECT_TRUE(v.linear().isApprox(v_frame.linear(), unit_test_utils::TEST_PREC));
1708  EXPECT_TRUE(v.angular().isApprox(v_frame.angular(), unit_test_utils::TEST_PREC));
1709 
1710  randomizeStates();
1711 
1712  unsigned int fb_id = model->addBody(body_c_id, RobotDynamics::Math::Xtrans(RobotDynamics::Math::Vector3d(0.1, -0.2, 0.3)),
1714 
1715  RobotDynamics::ReferenceFramePtr fb_frame = model->getReferenceFrame("fb1");
1716 
1717  v = calcPointVelocity6D(*model, Q, QDot, fb_id, RobotDynamics::Math::Vector3dZero, false);
1718  v_frame = calcPointVelocity6D(*model, Q, QDot, fb_frame, false);
1719  EXPECT_TRUE(v.linear().isApprox(v_frame.linear(), unit_test_utils::TEST_PREC));
1720  EXPECT_TRUE(v.angular().isApprox(v_frame.angular(), unit_test_utils::TEST_PREC));
1721 
1722  unsigned int fb_id2 = model->addBody(fb_id, RobotDynamics::Math::Xtrans(RobotDynamics::Math::Vector3d(0.2, -0.3, 0.4)),
1724 
1725  fb_frame = model->getReferenceFrame("fb2");
1726 
1727  v = calcPointVelocity6D(*model, Q, QDot, fb_id2, RobotDynamics::Math::Vector3dZero, false);
1728  v_frame = calcPointVelocity6D(*model, Q, QDot, fb_frame, false);
1729  EXPECT_TRUE(v.linear().isApprox(v_frame.linear(), unit_test_utils::TEST_PREC));
1730  EXPECT_TRUE(v.angular().isApprox(v_frame.angular(), unit_test_utils::TEST_PREC));
1731 }
1732 
1733 TEST_F(Human36, CalcPointVelocity6DFixedBody)
1734 {
1735  randomizeStates();
1736 
1737  unsigned int foot_r_id = model->GetBodyId("foot_r");
1738  Vector3d point_local(1.1, 2.2, 3.3);
1739 
1740  Body nullBody(0., Vector3d(0., 0., 0.), Vector3d(0., 0., 0.));
1741 
1742  unsigned int fixed_body_id = model->addBody(foot_r_id, Xtrans(point_local), Joint(JointTypeFixed), nullBody, "right_sole_frame");
1743 
1744  // Compute the 6-D velocity
1745  FrameVectorPair v_fixed = calcPointVelocity6D(*model, q, qdot, fixed_body_id, point_local);
1746 
1747  MatrixNd G(MatrixNd::Zero(6, model->dof_count));
1748 
1749  calcPointJacobian6D(*model, q, fixed_body_id, point_local, G);
1750  SpatialVector v_j_qdot = G * qdot;
1751 
1752  EXPECT_TRUE(v_j_qdot.getLinearPart().isApprox(v_fixed.linear(), v_j_qdot.norm() * unit_test_utils::TEST_PREC));
1753  EXPECT_TRUE(v_j_qdot.getAngularPart().isApprox(v_fixed.angular(), v_j_qdot.norm() * unit_test_utils::TEST_PREC));
1754 }
1755 
1756 TEST_F(Human36, CalcPointJacobianDot6D)
1757 {
1758  randomizeStates();
1759  unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1760  Vector3d point_local(1.1, 2.2, 3.3);
1761 
1762  MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size);
1763  G.setZero();
1764  GDot.setZero();
1765  calcPointJacobianDot6D(*model, q, qdot, body_id, point_local, GDot);
1766  calcPointJacobian6D(*model, q, body_id, point_local, G);
1767  FrameVectorPair a_ref = calcPointAcceleration6D(*model, q, qdot, qddot, body_id, point_local);
1768  SpatialVector a_exp = G * qddot + GDot * qdot;
1771 
1772  body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1773  G.setZero();
1774  GDot.setZero();
1775  a_ref = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_id, point_local);
1776  calcPointJacobianDot6D(*model_3dof, q, qdot, body_id, point_local, GDot);
1777  calcPointJacobian6D(*model_3dof, q, body_id, point_local, G);
1778  a_exp = G * qddot + GDot * qdot;
1781 
1782  Joint fj(JointTypeFixed);
1783  Body fb(1., Vector3d(0.1, 0.1, 0.1), Vector3d(0.1, 0.1, 0.1));
1784  body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1785  unsigned int fb_id = model_3dof->addBody(body_id, Xtrans(Vector3d(-0.01, 0.02, 0.01)) * Xrotx(0.5), fj, fb);
1786  G.setZero();
1787  GDot.setZero();
1788  a_ref = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, fb_id, point_local);
1789  calcPointJacobianDot6D(*model_3dof, q, qdot, fb_id, point_local, GDot);
1790  calcPointJacobian6D(*model_3dof, q, fb_id, point_local, G);
1791  a_exp = G * qddot + GDot * qdot;
1794 }
1795 
1796 TEST_F(Human36, CalcPointJacobianDot6DFrame)
1797 {
1798  randomizeStates();
1799  updateKinematics(*model, q, qdot, qddot);
1800  unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1801  Vector3d point_local(0., 0., 0.);
1802  ReferenceFramePtr body_frame = model->bodyFrames[body_id];
1803 
1804  MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size);
1805  G.setZero();
1806  GDot.setZero();
1807  calcPointJacobianDot6D(*model, q, qdot, body_frame, GDot, false);
1808  calcPointJacobian6D(*model, q, body_id, point_local, G, false);
1809  FrameVectorPair a_ref = calcPointAcceleration6D(*model, q, qdot, qddot, body_id, point_local, false);
1810  SpatialVector a_exp = G * qddot + GDot * qdot;
1813 
1814  updateKinematics(*model_3dof, q, qdot, qddot);
1815  body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1816  body_frame = model_3dof->bodyFrames[body_id];
1817  G.setZero();
1818  GDot.setZero();
1819  a_ref = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_id, point_local, false);
1820  calcPointJacobianDot6D(*model_3dof, q, qdot, body_frame, GDot, false);
1821  calcPointJacobian6D(*model_3dof, q, body_id, point_local, G, false);
1822  a_exp = G * qddot + GDot * qdot;
1825 
1826  Joint fj(JointTypeFixed);
1827  Body fb(1., Vector3d(0.1, 0.1, 0.1), Vector3d(0.1, 0.1, 0.1));
1828  body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1829  unsigned int fb_id = model_3dof->addBody(body_id, Xtrans(Vector3d(-0.01, 0.02, 0.01)) * Xrotx(0.5), fj, fb, "fixed_body");
1830 
1831  updateKinematics(*model_3dof, q, qdot, qddot);
1832 
1833  G.setZero();
1834  GDot.setZero();
1835  body_frame = model_3dof->referenceFrameMap["fixed_body"];
1836  a_ref = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, fb_id, point_local, false);
1837  calcPointJacobianDot6D(*model_3dof, q, qdot, body_frame, GDot, false);
1838  calcPointJacobian6D(*model_3dof, q, fb_id, point_local, G, false);
1839  a_exp = G * qddot + GDot * qdot;
1842 }
1843 
1844 TEST_F(Human36, CalcRelativePointJacobianDot6D)
1845 {
1846  randomizeStates();
1847  updateKinematics(*model, q, qdot, qddot);
1848  unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1849  unsigned int relative_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1850  unsigned int expressed_in_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1851 
1852  MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size);
1853  G.setZero();
1854  GDot.setZero();
1855  ReferenceFramePtr body_frame = model->bodyFrames[body_id];
1856  ReferenceFramePtr relative_frame = model->bodyFrames[relative_body_id];
1857  ReferenceFramePtr expressedInFrame = model->bodyFrames[expressed_in_body_id];
1858 
1859  FrameVectorPair a = calcPointAcceleration6D(*model, q, qdot, qddot, body_frame, relative_frame, expressedInFrame, false);
1860  FrameVectorPair a_body = calcPointAcceleration6D(*model, q, qdot, qddot, body_frame, model->worldFrame, model->worldFrame, false);
1861  FrameVectorPair a_rel = calcPointAcceleration6D(*model, q, qdot, qddot, relative_frame, model->worldFrame, model->worldFrame, false);
1862 
1863  a_body -= a_rel;
1864  a_body.changeFrame(expressedInFrame);
1865 
1867 
1868  calcRelativePointJacobian6D(*model, q, G, body_frame, relative_frame, expressedInFrame, false);
1869  calcRelativePointJacobianDot6D(*model, q, qdot, GDot, body_frame, relative_frame, expressedInFrame, false);
1870 
1871  SpatialVector a_calc = G * qddot + GDot * qdot;
1872 
1875 
1876  updateKinematics(*model_3dof, q, qdot, qddot);
1877  body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1878  relative_body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1879  expressed_in_body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1880 
1881  body_frame = model_3dof->bodyFrames[body_id];
1882  relative_frame = model_3dof->bodyFrames[relative_body_id];
1883  expressedInFrame = model_3dof->bodyFrames[expressed_in_body_id];
1884 
1885  a = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_frame, relative_frame, expressedInFrame, false);
1886  a_body = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_frame, model_3dof->worldFrame, model_3dof->worldFrame, false);
1887  a_rel = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, relative_frame, model_3dof->worldFrame, model_3dof->worldFrame, false);
1888 
1889  a_body -= a_rel;
1890  a_body.changeFrame(expressedInFrame);
1891 
1893 
1894  G = MatrixNd::Zero(6, model_3dof->qdot_size);
1895  GDot = MatrixNd::Zero(6, model_3dof->qdot_size);
1896  G.setZero();
1897  GDot.setZero();
1898  calcRelativePointJacobian6D(*model_3dof, q, G, body_frame, relative_frame, expressedInFrame, false);
1899  calcRelativePointJacobianDot6D(*model_3dof, q, qdot, GDot, body_frame, relative_frame, expressedInFrame, false);
1900 
1901  a_calc = G * qddot + GDot * qdot;
1902 
1905 
1906  Joint fj(JointTypeFixed);
1907  Body fb(1., Vector3d(0.1, 0.1, 0.1), Vector3d(0.1, 0.1, 0.1));
1908  body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1909  relative_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1910  expressed_in_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1911 
1912  unsigned int fb_id = model->addBody(body_id, Xtrans(Vector3d(-0.01, 0.02, 0.01)) * Xrotx(0.5), fj, fb, "fixed_body");
1913  G.setZero();
1914  GDot.setZero();
1915 
1916  qdot.setZero();
1917  updateKinematics(*model, q, qdot, qddot);
1918 
1919  body_frame = model->referenceFrameMap["fixed_body"];
1920  relative_frame = model->bodyFrames[relative_body_id];
1921  expressedInFrame = model->bodyFrames[expressed_in_body_id];
1922 
1923  a = calcPointAcceleration6D(*model, q, qdot, qddot, body_frame, relative_frame, expressedInFrame, false);
1924 
1925  calcRelativePointJacobianDot6D(*model, q, qdot, GDot, body_frame, relative_frame, expressedInFrame, false);
1926  calcRelativePointJacobian6D(*model, q, G, body_frame, relative_frame, expressedInFrame, false);
1927 
1928  a_calc.setZero();
1929  a_calc = G * qddot + GDot * qdot;
1930 
1933 }
1934 
1935 TEST_F(Human36, CalcRelativePointJacobianAndJacobianDot6D)
1936 {
1937  randomizeStates();
1938  updateKinematics(*model, q, qdot, qddot);
1939  unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1940  unsigned int relative_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1941  unsigned int expressed_in_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1942 
1943  MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size), G2(6, model->qdot_size), GDot2(6, model->qdot_size);
1944  G.setZero();
1945  GDot.setZero();
1946  G2.setZero();
1947  GDot2.setZero();
1948  ReferenceFramePtr body_frame = model->bodyFrames[body_id];
1949  ReferenceFramePtr relative_frame = model->bodyFrames[relative_body_id];
1950  ReferenceFramePtr expressedInFrame = model->bodyFrames[expressed_in_body_id];
1951 
1952  calcRelativePointJacobian6D(*model, q, G, body_frame, relative_frame, expressedInFrame, false);
1953  calcRelativePointJacobianDot6D(*model, q, qdot, GDot, body_frame, relative_frame, expressedInFrame, false);
1954  calcRelativePointJacobianAndJacobianDot6D(*model, q, qdot, G2, GDot2, body_frame, relative_frame, expressedInFrame, false);
1955 
1958 
1959  updateKinematics(*model_3dof, q, qdot, qddot);
1960  body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1961  relative_body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1962  expressed_in_body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1963 
1964  body_frame = model_3dof->bodyFrames[body_id];
1965  relative_frame = model_3dof->bodyFrames[relative_body_id];
1966  expressedInFrame = model_3dof->bodyFrames[expressed_in_body_id];
1967 
1968  G = MatrixNd::Zero(6, model_3dof->qdot_size);
1969  GDot = MatrixNd::Zero(6, model_3dof->qdot_size);
1970  G2 = MatrixNd::Zero(6, model_3dof->qdot_size);
1971  GDot2 = MatrixNd::Zero(6, model_3dof->qdot_size);
1972 
1973  calcRelativePointJacobian6D(*model_3dof, q, G, body_frame, relative_frame, expressedInFrame, false);
1974  calcRelativePointJacobianDot6D(*model_3dof, q, qdot, GDot, body_frame, relative_frame, expressedInFrame, false);
1975  calcRelativePointJacobianAndJacobianDot6D(*model_3dof, q, qdot, G2, GDot2, body_frame, relative_frame, expressedInFrame, false);
1976 
1979 
1980  Joint fj(JointTypeFixed);
1981  Body fb(1., Vector3d(0.1, 0.1, 0.1), Vector3d(0.1, 0.1, 0.1));
1982  body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1983  relative_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1984  expressed_in_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1985 
1986  unsigned int fb_id = model->addBody(body_id, Xtrans(Vector3d(-0.01, 0.02, 0.01)) * Xrotx(0.5), fj, fb, "fixed_body");
1987  G.setZero();
1988  GDot.setZero();
1989  G2.setZero();
1990  GDot2.setZero();
1991 
1992  updateKinematics(*model, q, qdot, qddot);
1993 
1994  body_frame = model->referenceFrameMap["fixed_body"];
1995  relative_frame = model->bodyFrames[relative_body_id];
1996  expressedInFrame = model->bodyFrames[expressed_in_body_id];
1997 
1998  calcRelativePointJacobianDot6D(*model, q, qdot, GDot, body_frame, relative_frame, expressedInFrame, false);
1999  calcRelativePointJacobian6D(*model, q, G, body_frame, relative_frame, expressedInFrame, false);
2000  calcRelativePointJacobianAndJacobianDot6D(*model, q, qdot, G2, GDot2, body_frame, relative_frame, expressedInFrame, false);
2001 
2004 }
2005 
2006 TEST_F(Human36, CalcPointAcceleration6DFixedFrames)
2007 {
2008  randomizeStates();
2009  updateKinematics(*model, q, qdot, qddot);
2010  unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2011 
2012  MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size);
2013  G.setZero();
2014  GDot.setZero();
2015 
2016  Joint fj(JointTypeFixed);
2017  Body fb(1., Vector3d(0.1, 0.1, 0.1), Vector3d(0.1, 0.1, 0.1));
2018  body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2019 
2020  unsigned int fb_id_1 = model->addBody(body_id, Xtrans(Vector3d(-0.01, 0.02, 0.01)) * Xrotx(0.5), fj, fb, "fixed_body_1");
2021  body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2022  unsigned int fb_id_2 = model->addBody(body_id, Xtrans(Vector3d(-0.01, 0.02, 0.01)) * Xrotx(0.5), fj, fb, "fixed_body_2");
2023  body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2024  unsigned int fb_id_3 = model->addBody(body_id, Xtrans(Vector3d(-0.01, 0.02, 0.01)) * Xrotx(0.5), fj, fb, "fixed_body_3");
2025 
2026  G.setZero();
2027  GDot.setZero();
2028 
2029  qdot.setZero();
2030  updateKinematics(*model, q, qdot, qddot);
2031 
2032  ReferenceFramePtr fb_1_frame = model->referenceFrameMap["fixed_body_1"];
2033  ReferenceFramePtr fb_2_frame = model->referenceFrameMap["fixed_body_2"];
2034  ReferenceFramePtr fb_3_frame = model->referenceFrameMap["fixed_body_3"];
2035 
2036  FrameVectorPair a_fb_1 = calcPointAcceleration6D(*model, q, qdot, qddot, fb_id_1, Vector3dZero, false);
2037  FrameVectorPair a_fb_2 = calcPointAcceleration6D(*model, q, qdot, qddot, fb_id_2, Vector3dZero, false);
2038 
2039  FrameVectorPair a_fb_1_frames = calcPointAcceleration6D(*model, q, qdot, qddot, fb_1_frame, model->worldFrame, model->worldFrame, false);
2040  FrameVectorPair a_fb_2_frames = calcPointAcceleration6D(*model, q, qdot, qddot, fb_2_frame, model->worldFrame, model->worldFrame, false);
2041 
2044 
2045  FrameVectorPair a = calcPointAcceleration6D(*model, q, qdot, qddot, fb_1_frame, fb_2_frame, fb_3_frame, false);
2046 
2047  a_fb_1_frames -= a_fb_2_frames;
2048  a_fb_1_frames.changeFrame(fb_3_frame);
2049 
2050  SpatialTransform X = model->worldFrame->getTransformToDesiredFrame(fb_3_frame);
2051  X.r.setZero();
2052 
2053  a_fb_1 -= a_fb_2;
2054  a_fb_1.changeFrame(fb_3_frame);
2055 
2058 }
2059 
2060 TEST_F(Human36, CalcPointAccelerationDot6DFrames)
2061 {
2062  randomizeStates();
2063  updateKinematics(*model, q, qdot, qddot);
2064  unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2065  ReferenceFramePtr body_frame = model->bodyFrames[body_id];
2066  FrameVectorPair a_ref = calcPointAcceleration6D(*model, q, qdot, qddot, body_id, Vector3dZero, false);
2067 
2068  body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2069  ReferenceFramePtr relative_frame = model->bodyFrames[body_id];
2070  FrameVectorPair a_ref2 = calcPointAcceleration6D(*model, q, qdot, qddot, body_id, Vector3dZero, false);
2071 
2072  FrameVectorPair a_beep = calcPointAcceleration6D(*model, q, qdot, qddot, body_frame, relative_frame, model->worldFrame, false);
2073 
2075 
2076  body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2077  ReferenceFramePtr expressedInFrame = model->bodyFrames[body_id];
2078 
2079  a_beep = calcPointAcceleration6D(*model, q, qdot, qddot, body_frame, relative_frame, expressedInFrame, false);
2080  SpatialTransform X_rot = model->worldFrame->getTransformToDesiredFrame(expressedInFrame);
2081  X_rot.r.setZero();
2082 
2083  a_ref -= a_ref2;
2084 
2085  a_ref.setLinearPart(a_ref.linear().transform_copy(X_rot));
2086  a_ref.setAngularPart(a_ref.angular().transform_copy(X_rot));
2087  a_ref.setReferenceFrame(expressedInFrame);
2088 
2089  EXPECT_TRUE(unit_test_utils::checkFrameVectorPairEpsilonClose(a_ref, a_beep, TEST_PREC));
2090 }
2091 
2092 TEST_F(Human36, CalcPointAccelerationDot6DFramesModel3Dof)
2093 {
2094  randomizeStates();
2095  updateKinematics(*model_3dof, q, qdot, qddot);
2096  unsigned int body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
2097  ReferenceFramePtr body_frame = model_3dof->bodyFrames[body_id];
2098  FrameVectorPair a_ref = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_id, Vector3dZero, false);
2099 
2100  body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
2101  ReferenceFramePtr relative_frame = model_3dof->bodyFrames[body_id];
2102  FrameVectorPair a_ref2 = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_id, Vector3dZero, false);
2103 
2104  FrameVectorPair a_beep = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_frame, relative_frame, model_3dof->worldFrame, false);
2105  EXPECT_TRUE(unit_test_utils::checkFrameVectorPairEpsilonClose(a_ref - a_ref2, a_beep, TEST_PREC));
2106 
2107  body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
2108  ReferenceFramePtr expressedInFrame = model_3dof->bodyFrames[body_id];
2109 
2110  a_beep = calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_frame, relative_frame, expressedInFrame, false);
2111  SpatialTransform X_rot = model_3dof->worldFrame->getTransformToDesiredFrame(expressedInFrame);
2112  X_rot.r.setZero();
2113 
2114  a_ref -= a_ref2;
2115 
2116  a_ref.setLinearPart(a_ref.linear().transform_copy(X_rot));
2117  a_ref.setAngularPart(a_ref.angular().transform_copy(X_rot));
2118  a_ref.setReferenceFrame(expressedInFrame);
2119 
2120  EXPECT_TRUE(unit_test_utils::checkFrameVectorPairEpsilonClose(a_ref, a_beep, TEST_PREC));
2121 }
2122 
2123 TEST_F(Human36, CalcPointAccelerationDot)
2124 {
2125  randomizeStates();
2126  unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2127  Vector3d point_local(1.1, 2.2, 3.3);
2128 
2129  MatrixNd G(3, model->qdot_size), GDot(3, model->qdot_size);
2130  G.setZero();
2131  GDot.setZero();
2132  calcPointJacobianDot(*model, q, qdot, body_id, point_local, GDot);
2133  calcPointJacobian(*model, q, body_id, point_local, G);
2134  FrameVector a_ref = calcPointAcceleration(*model, q, qdot, qddot, body_id, point_local);
2135  Vector3d a_exp = G * qddot + GDot * qdot;
2137 
2138  body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
2139  G.setZero();
2140  GDot.setZero();
2141  a_ref = calcPointAcceleration(*model_3dof, q, qdot, qddot, body_id, point_local);
2142  calcPointJacobianDot(*model_3dof, q, qdot, body_id, point_local, GDot);
2143  calcPointJacobian(*model_3dof, q, body_id, point_local, G);
2144  a_exp = G * qddot + GDot * qdot;
2146 
2147  Joint fj(JointTypeFixed);
2148  Body fb(1., Vector3d(0.1, 0.1, 0.1), Vector3d(0.1, 0.1, 0.1));
2149  body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
2150  unsigned int fb_id = model_3dof->addBody(body_id, Xtrans(Vector3d(-0.01, 0.02, 0.01)) * Xrotx(0.5), fj, fb);
2151  G.setZero();
2152  GDot.setZero();
2153  a_ref = calcPointAcceleration(*model_3dof, q, qdot, qddot, fb_id, point_local);
2154  calcPointJacobianDot(*model_3dof, q, qdot, fb_id, point_local, GDot);
2155  calcPointJacobian(*model_3dof, q, fb_id, point_local, G);
2156  a_exp = G * qddot + GDot * qdot;
2158 }
2159 
2160 TEST_F(Human36, CalcPointAcceleration)
2161 {
2162  randomizeStates();
2163  unsigned int foot_r_id = model->GetBodyId("foot_r");
2164  Vector3d point_local(1.1, 2.2, 3.3);
2165 
2166  // Compute the 6-D acceleration
2167  FrameVectorPair a_foot_0 = calcPointAcceleration6D(*model, q, qdot, qddot, foot_r_id, point_local);
2168  Vector3d a_v = calcPointAcceleration(*model, q, qdot, qddot, foot_r_id, point_local);
2169 
2170  EXPECT_NEAR(a_v(0), a_foot_0.linear().x(), unit_test_utils::TEST_PREC);
2171  EXPECT_NEAR(a_v(1), a_foot_0.linear().y(), unit_test_utils::TEST_PREC);
2172  EXPECT_NEAR(a_v(2), a_foot_0.linear().z(), unit_test_utils::TEST_PREC);
2173 
2174  // Compute the 6-D acceleration by adding the coriolis term to the
2175  // acceleration of the body and transforming the result to the
2176  // point and align it with the base coordinate system.
2177  FramePoint p(model->bodyFrames[foot_r_id], point_local);
2178  p.changeFrame(ReferenceFrame::getWorldFrame());
2179 
2180  FrameVector v_foot_0 = calcPointVelocity(*model, q, qdot, foot_r_id, point_local);
2181  SpatialVector rdot(0., 0., 0., v_foot_0[0], v_foot_0[1], v_foot_0[2]);
2182 
2183  SpatialTransform X_foot(Matrix3d::Identity(), p.vec());
2184  SpatialVector a_foot_0_ref = X_foot.apply(model->bodyFrames[foot_r_id]->getTransformToRoot().apply(model->a[foot_r_id]) -
2185  crossm(rdot, model->bodyFrames[foot_r_id]->getTransformToRoot().apply(model->v[foot_r_id])));
2186 
2187  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(a_foot_0_ref.getLinearPart(), a_foot_0.linear(), TEST_PREC));
2188  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(a_foot_0_ref.getAngularPart(), a_foot_0.angular(), TEST_PREC));
2189 }
2190 
2191 TEST_F(Human36, CalcPointAccelerationFixedBody)
2192 {
2193  randomizeStates();
2194  unsigned int foot_r_id = model->GetBodyId("foot_r");
2195  Body fb(1., Math::Vector3d(1., 1., 1.), Math::Vector3d(1., 1., 1.));
2196  Joint fj(JointTypeFixed);
2197  unsigned int fb_id = model->addBody(foot_r_id, Math::SpatialTransform(), fj, fb);
2198  Vector3d point_local(1.1, 2.2, 3.3);
2199 
2200  // Compute the 6-D acceleration
2201  FrameVectorPair a_foot_0 = calcPointAcceleration6D(*model, q, qdot, qddot, fb_id, point_local);
2202  Vector3d a_v = calcPointAcceleration(*model, q, qdot, qddot, fb_id, point_local);
2203 
2204  EXPECT_NEAR(a_v(0), a_foot_0.linear().x(), unit_test_utils::TEST_PREC);
2205  EXPECT_NEAR(a_v(1), a_foot_0.linear().y(), unit_test_utils::TEST_PREC);
2206  EXPECT_NEAR(a_v(2), a_foot_0.linear().z(), unit_test_utils::TEST_PREC);
2207 
2208  // Compute the 6-D acceleration by adding the coriolis term to the
2209  // acceleration of the body and transforming the result to the
2210  // point and align it with the base coordinate system.
2211  FramePoint p(model->fixedBodyFrames[fb_id - model->fixed_body_discriminator], point_local);
2212  p.changeFrame(ReferenceFrame::getWorldFrame());
2213 
2214  FrameVector v_foot_0 = calcPointVelocity(*model, q, qdot, fb_id, point_local);
2215  SpatialVector rdot(0., 0., 0., v_foot_0[0], v_foot_0[1], v_foot_0[2]);
2216 
2217  SpatialTransform X_foot(Matrix3d::Identity(), p.vec());
2218  SpatialVector a_foot_0_ref =
2219  X_foot.apply(model->fixedBodyFrames[fb_id - model->fixed_body_discriminator]->getTransformToRoot().apply(model->a[foot_r_id]) -
2220  crossm(rdot, model->fixedBodyFrames[fb_id - model->fixed_body_discriminator]->getTransformToRoot().apply(model->v[foot_r_id])));
2221 
2222  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(a_foot_0_ref.getLinearPart(), a_foot_0.linear(), TEST_PREC));
2223  EXPECT_TRUE(unit_test_utils::checkVector3dEpsilonClose(a_foot_0_ref.getAngularPart(), a_foot_0.angular(), TEST_PREC));
2224 }
2225 
2227 {
2228  Model model;
2229  Body b1(1., Math::Vector3d(0., 0., -0.1), Math::Vector3d(1., 1., 1.));
2231 
2232  unsigned int id = model.addBody(0, Math::SpatialTransform(), j1, b1, "b1");
2233 
2234  id = model.addBody(id, Xtrans(Math::Vector3d(0., 0., -1.)), j1, b1, "b2");
2235 
2236  Body fb1(0., Math::Vector3d(0., 0., 0.), Math::Vector3d(0., 0., 0.));
2237  Joint fj1(JointTypeFixed);
2238 
2239  unsigned int fb_id = model.addBody(id, Xtrans(Math::Vector3d(0., 0., -1.)), fj1, fb1, "fb1");
2240 
2241  Math::VectorNd Q(model.qdot_size), QDot(model.qdot_size);
2242 
2243  QDot[0] = 1.;
2244  updateKinematicsCustom(model, &Q, &QDot, nullptr);
2245  SpatialMotion m = calcSpatialVelocity(model, Q, QDot, 2, 0);
2246  SpatialMotion m_frame = calcSpatialVelocity(model, Q, QDot, model.bodyFrames[2], model.worldFrame);
2247  EXPECT_STREQ(m.getReferenceFrame()->getName().c_str(), "b2");
2248  EXPECT_STREQ(m.getBaseFrame()->getName().c_str(), "world");
2249  EXPECT_STREQ(m.getReferenceFrame()->getName().c_str(), "b2");
2250 
2251  EXPECT_STREQ(m_frame.getReferenceFrame()->getName().c_str(), "b2");
2252  EXPECT_STREQ(m_frame.getBaseFrame()->getName().c_str(), "world");
2253  EXPECT_STREQ(m_frame.getReferenceFrame()->getName().c_str(), "b2");
2254 
2256  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(m_frame, SpatialVector(1., 0., 0., 0., 1., 0.), unit_test_utils::TEST_PREC));
2258 
2259  m = calcSpatialVelocity(model, Q, QDot, fb_id, 0);
2260  m_frame = calcSpatialVelocity(model, Q, QDot, model.fixedBodyFrames[fb_id - model.fixed_body_discriminator], model.worldFrame);
2261  EXPECT_STREQ(m.getReferenceFrame()->getName().c_str(), "fb1");
2262  EXPECT_STREQ(m.getBaseFrame()->getName().c_str(), "world");
2263  EXPECT_STREQ(m.getReferenceFrame()->getName().c_str(), "fb1");
2264 
2265  EXPECT_STREQ(m_frame.getReferenceFrame()->getName().c_str(), "fb1");
2266  EXPECT_STREQ(m_frame.getBaseFrame()->getName().c_str(), "world");
2267  EXPECT_STREQ(m_frame.getReferenceFrame()->getName().c_str(), "fb1");
2268 
2270  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(m_frame, SpatialVector(1., 0., 0., 0., 2., 0.), unit_test_utils::TEST_PREC));
2272 
2273  m = calcSpatialVelocity(model, Q, QDot, 0, 2);
2274  m_frame = calcSpatialVelocity(model, Q, QDot, model.worldFrame, model.bodyFrames[2]);
2275  EXPECT_STREQ(m.getReferenceFrame()->getName().c_str(), "world");
2276  EXPECT_STREQ(m.getBaseFrame()->getName().c_str(), "b2");
2277  EXPECT_STREQ(m.getReferenceFrame()->getName().c_str(), "world");
2278 
2279  EXPECT_STREQ(m_frame.getReferenceFrame()->getName().c_str(), "world");
2280  EXPECT_STREQ(m_frame.getBaseFrame()->getName().c_str(), "b2");
2281  EXPECT_STREQ(m_frame.getReferenceFrame()->getName().c_str(), "world");
2282 
2283  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(-m, MotionVector(1., 0., 0., 0., 1., 0.).transform_copy(model.bodyFrames[2]->getTransformToRoot()),
2285  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(-m_frame, MotionVector(1., 0., 0., 0., 1., 0.).transform_copy(model.bodyFrames[2]->getTransformToRoot()),
2287 
2288  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(m.transform_copy(model.worldFrame->getTransformToDesiredFrame(model.bodyFrames[2])),
2289  -MotionVector(1., 0., 0., 0., 1., 0.), unit_test_utils::TEST_PREC));
2290  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(m_frame.transform_copy(model.worldFrame->getTransformToDesiredFrame(model.bodyFrames[2])),
2291  -MotionVector(1., 0., 0., 0., 1., 0.), unit_test_utils::TEST_PREC));
2293 
2294  for (unsigned int i = 0; i < QDot.size(); i++)
2295  {
2296  Q[i] = 0.4 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2297  QDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2298  }
2299 
2300  updateKinematicsCustom(model, &Q, &QDot, nullptr);
2301  MotionVector m1 = calcSpatialVelocity(model, Q, QDot, 2, 0);
2302  MotionVector m2 = calcSpatialVelocity(model, Q, QDot, 0, 2);
2303 
2304  MotionVector m1_frame = calcSpatialVelocity(model, Q, QDot, model.bodyFrames[2], model.worldFrame);
2305  MotionVector m2_frame = calcSpatialVelocity(model, Q, QDot, model.worldFrame, model.bodyFrames[2]);
2306 
2307  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(m1.transform_copy(model.bodyFrames[2]->getTransformToRoot()), -m2, unit_test_utils::TEST_PREC));
2308  EXPECT_TRUE(
2309  unit_test_utils::checkSpatialVectorsEpsilonClose(m1_frame.transform_copy(model.bodyFrames[2]->getTransformToRoot()), -m2_frame, unit_test_utils::TEST_PREC));
2311 
2312  m1 = calcSpatialVelocity(model, Q, QDot, fb_id, 0);
2313  m2 = calcSpatialVelocity(model, Q, QDot, 0, fb_id);
2314 
2315  m1_frame = calcSpatialVelocity(model, Q, QDot, model.fixedBodyFrames[fb_id - model.fixed_body_discriminator], model.worldFrame);
2316  m2_frame = calcSpatialVelocity(model, Q, QDot, model.worldFrame, model.fixedBodyFrames[fb_id - model.fixed_body_discriminator]);
2317 
2319  EXPECT_TRUE(
2322 
2323  Body fb2(1., Math::Vector3d(0.1, -0.1, 0.2), Math::Vector3d(1., 1., 1.));
2324  Joint fj2(JointTypeFixed);
2325 
2326  unsigned int fb_id2 = model.addBody(1, Xtrans(Math::Vector3d(0.1, 0.2, 0.1)) * Xrotx(0.1), fj2, fb2, "fb2");
2327 
2328  m = calcSpatialVelocity(model, Q, QDot, fb_id, fb_id2);
2329  m_frame = calcSpatialVelocity(model, Q, QDot, model.fixedBodyFrames[fb_id - model.fixed_body_discriminator],
2330  model.fixedBodyFrames[fb_id2 - model.fixed_body_discriminator]);
2331  m1 = m;
2332  m1_frame = m_frame;
2333 
2334  EXPECT_STREQ(m.getReferenceFrame()->getName().c_str(), "fb1");
2335  EXPECT_STREQ(m.getBaseFrame()->getName().c_str(), "fb2");
2336  EXPECT_STREQ(m.getReferenceFrame()->getName().c_str(), "fb1");
2337  EXPECT_STREQ(m_frame.getReferenceFrame()->getName().c_str(), "fb1");
2338  EXPECT_STREQ(m_frame.getBaseFrame()->getName().c_str(), "fb2");
2339  EXPECT_STREQ(m_frame.getReferenceFrame()->getName().c_str(), "fb1");
2341 
2342  m = calcSpatialVelocity(model, Q, QDot, fb_id2, fb_id);
2343  m_frame = calcSpatialVelocity(model, Q, QDot, model.fixedBodyFrames[fb_id2 - model.fixed_body_discriminator],
2344  model.fixedBodyFrames[fb_id - model.fixed_body_discriminator]);
2345  EXPECT_STREQ(m.getReferenceFrame()->getName().c_str(), "fb2");
2346  EXPECT_STREQ(m.getBaseFrame()->getName().c_str(), "fb1");
2347  EXPECT_STREQ(m.getReferenceFrame()->getName().c_str(), "fb2");
2349 
2350  m2 = m;
2351  m2_frame = m_frame;
2352 
2353  EXPECT_TRUE(
2355  model.fixedBodyFrames[fb_id2 - model.fixed_body_discriminator])),
2358  m1_frame.transform_copy(
2359  model.fixedBodyFrames[fb_id - model.fixed_body_discriminator]->getTransformToDesiredFrame(model.fixedBodyFrames[fb_id2 - model.fixed_body_discriminator])),
2360  -m2_frame, unit_test_utils::TEST_PREC));
2361 }
2362 
2364 {
2365  Model model;
2366  Body b1(1., Math::Vector3d(0.1, -0.1, 0.1), Math::Vector3d(1., 1., 1.));
2367  Joint j_rev_x(JointTypeRevoluteX);
2368  Joint j_rev_y(JointTypeRevoluteY);
2369  Joint j_rev_z(JointTypeRevoluteZ);
2370 
2371  unsigned int parent_id = 0;
2372 
2373  parent_id = model.addBody(parent_id, Math::Xtrans(Math::Vector3d(0.1, -0.2, 0.15)), j_rev_x, b1, "b1");
2374 
2375  parent_id = model.addBody(parent_id, Math::Xtrans(Math::Vector3d(0.1, -0.2, 0.15)), j_rev_y, b1, "b2");
2376 
2377  parent_id = model.addBody(parent_id, Math::Xtrans(Math::Vector3d(0.1, -0.2, 0.15)), j_rev_z, b1, "b3");
2378 
2379  Math::VectorNd Q(model.qdot_size), QDot(model.qdot_size), QDDot(model.qdot_size);
2380  Math::MatrixNd GDot(6, model.qdot_size), G(6, model.qdot_size);
2381  Q.setZero();
2382  QDot.setZero();
2383  QDDot.setZero();
2384  GDot.setZero();
2385 
2386  for (int i = 0; i < model.qdot_size; i++)
2387  {
2388  Q[i] = 0.4 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2389  QDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2390  QDDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2391  }
2392 
2393  updateKinematics(model, Q, QDot, QDDot);
2394 
2395  calcBodySpatialJacobianDot(model, Q, QDot, parent_id, GDot, false);
2396  calcBodySpatialJacobian(model, Q, parent_id, G, false);
2397 
2398  Math::SpatialVector a_exp = GDot * QDot + G * QDDot;
2399 
2400  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(a_exp, model.a[parent_id], unit_test_utils::TEST_PREC));
2402 
2403  Joint j_fixed(JointTypeFixed);
2404 
2405  parent_id = model.addBody(parent_id, Math::Xtrans(Math::Vector3d(-0.1, 0.2, 0.1)), j_fixed, b1, "fb1");
2406 
2407  updateKinematics(model, Q, QDot, QDDot);
2408 
2409  calcBodySpatialJacobianDot(model, Q, QDot, parent_id, GDot, false);
2410  calcBodySpatialJacobian(model, Q, parent_id, G, false);
2411 
2412  a_exp = GDot * QDot + G * QDDot;
2413  Math::SpatialAcceleration a_fixed = model.a[model.mFixedBodies[parent_id - model.fixed_body_discriminator].mMovableParent];
2414  a_fixed.changeFrame(model.fixedBodyFrames[parent_id - model.fixed_body_discriminator]);
2415 
2418 }
2419 
2421 {
2422  Model model;
2423  Body b1(1., Math::Vector3d(0.1, -0.1, 0.1), Math::Vector3d(1., 1., 1.));
2424  Joint j_rev_x(JointTypeRevoluteX);
2425  Joint j_rev_y(JointTypeRevoluteY);
2426  Joint j_rev_z(JointTypeRevoluteZ);
2427 
2428  unsigned int parent_id = 0;
2429 
2430  parent_id = model.addBody(parent_id, Math::Xtrans(Math::Vector3d(0.1, -0.2, 0.15)), j_rev_x, b1, "b1");
2431 
2432  parent_id = model.addBody(parent_id, Math::Xtrans(Math::Vector3d(0.1, -0.2, 0.15)), j_rev_y, b1, "b2");
2433 
2434  parent_id = model.addBody(parent_id, Math::Xtrans(Math::Vector3d(0.1, -0.2, 0.15)), j_rev_z, b1, "b3");
2435 
2436  Math::VectorNd Q(model.qdot_size), QDot(model.qdot_size), QDDot(model.qdot_size);
2437  Math::MatrixNd GDot(6, model.qdot_size), G(6, model.qdot_size);
2438  Q.setZero();
2439  QDot.setZero();
2440  QDDot.setZero();
2441  GDot.setZero();
2442 
2443  for (int i = 0; i < model.qdot_size; i++)
2444  {
2445  Q[i] = 0.4 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2446  QDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2447  QDDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2448  }
2449 
2450  updateKinematics(model, Q, QDot, QDDot);
2451 
2452  calcBodySpatialJacobianDot(model, Q, QDot, parent_id, GDot, false);
2453  calcBodySpatialJacobian(model, Q, parent_id, G, false);
2454 
2455  SpatialAcceleration a_calc = calcSpatialAcceleration(model, Q, QDot, QDDot, parent_id, 0);
2456 
2457  Math::SpatialVector a_exp = GDot * QDot + G * QDDot;
2458 
2460  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(a_exp, model.a[parent_id], unit_test_utils::TEST_PREC));
2462 
2463  Joint j_fixed(JointTypeFixed);
2464 
2465  parent_id = model.addBody(parent_id, Math::Xtrans(Math::Vector3d(-0.1, 0.2, 0.1)), j_fixed, b1, "fb1");
2466 
2467  updateKinematics(model, Q, QDot, QDDot);
2468 
2469  calcBodySpatialJacobianDot(model, Q, QDot, parent_id, GDot, false);
2470  calcBodySpatialJacobian(model, Q, parent_id, G, false);
2471  a_calc = calcSpatialAcceleration(model, Q, QDot, QDDot, parent_id, 0);
2472 
2473  a_exp = GDot * QDot + G * QDDot;
2474  Math::SpatialAcceleration a_fixed = model.a[model.mFixedBodies[parent_id - model.fixed_body_discriminator].mMovableParent];
2475  a_fixed.changeFrame(model.fixedBodyFrames[parent_id - model.fixed_body_discriminator]);
2476  a_fixed.setBodyFrame(model.fixedBodyFrames[parent_id - model.fixed_body_discriminator]);
2477 
2481 }
2482 
2484 {
2485  randomizeStates();
2486 
2487  updateKinematics(*model_emulated, q, qdot, qddot);
2488 
2489  Math::MatrixNd GDot(6, model_emulated->qdot_size), G(6, model_emulated->qdot_size);
2490  GDot.setZero();
2491  G.setZero();
2492 
2493  int id = rand() % static_cast<int>(model->mBodies.size() - 1);
2494  calcBodySpatialJacobianDot(*model_emulated, q, qdot, id, GDot, false);
2495  calcBodySpatialJacobian(*model_emulated, q, id, G, false);
2496 
2497  Math::SpatialVector a_exp = GDot * qdot + G * qddot;
2498 
2499  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(a_exp, model_emulated->a[id], unit_test_utils::TEST_PREC));
2500 
2501  id = rand() % static_cast<int>(model_3dof->mBodies.size() - 1);
2502 
2503  updateKinematics(*model_3dof, q, qdot, qddot);
2504 
2505  GDot.setZero();
2506  G.setZero();
2507 
2508  calcBodySpatialJacobianDot(*model_3dof, q, qdot, id, GDot, false);
2509  calcBodySpatialJacobian(*model_3dof, q, id, G, false);
2510 
2511  a_exp = GDot * qdot + G * qddot;
2512 
2513  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEpsilonClose(a_exp, model_3dof->a[id], unit_test_utils::TEST_PREC));
2514 }
2515 
2516 int main(int argc, char** argv)
2517 {
2518  ::testing::InitGoogleTest(&argc, argv);
2519  return RUN_ALL_TESTS();
2520 }
Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.))
File containing the FramePoint<T> object definition.
void calcPointJacobian(Model &model, const Math::VectorNd &Q, unsigned int body_id, const Math::Vector3d &point_position, Math::MatrixNd &G, bool update_kinematics=true)
Computes the 3D point jacobian for a point on a body.
Definition: Kinematics.cc:510
ReferenceFramePtr getReferenceFrame() const
Get a pointer to the reference frame this FrameObject is expressed in.
Definition: FrameObject.hpp:52
A FramePoint is a 3D point that is expressed in a ReferenceFrame. To change the ReferenceFrame a Fram...
Definition: FramePoint.hpp:40
Describes all properties of a single body.
Definition: Body.h:30
VectorNd Tau
void calcRelativeBodySpatialJacobianAndJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, Math::MatrixNd &GDot, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=nullptr, bool update_kinematics=true)
Computes both the body spatial jacobian and its time derivative. This function will be a bit more eff...
Definition: Kinematics.cc:402
VectorNd QDDot
std::shared_ptr< Model > ModelPtr
Definition: Model.h:731
FrameVector linear() const
Get copy of linear component.
std::vector< FixedBody > mFixedBodies
All bodies that are attached to a body via a fixed joint.
Definition: Model.h:298
Math::SpatialMotion calcSpatialVelocity(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, ReferenceFramePtr body_frame, ReferenceFramePtr relative_body_frame, ReferenceFramePtr expressedInFrame=nullptr, const bool update_kinematics=true)
Compute the spatial velocity of any frame with respect to any other frame, expressed in an arbirtary ...
Definition: Kinematics.cc:1670
VectorNd QDot
void setAngularPart(const Vector3d &v)
Set the angular vector.
void calcRelativeBodySpatialJacobian(Model &model, const Math::VectorNd &Q, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=nullptr, bool update_kinematics=true)
Computes the jacobian of a frame with being the "base" frame, being the "relative" frame...
Definition: Kinematics.cc:234
const double TEST_PREC
VectorNd Q
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
Fixed joint which causes the inertial properties to be merged with.
Definition: Joint.h:205
void calcPointJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, Math::MatrixNd &G, bool update_kinematics=true)
Computes the time derivative of the linear components the a point jacobian on a body.
Definition: Kinematics.cc:751
bool checkModelZeroVectorsAndMatrices(RobotDynamics::Model &model)
FrameVector angular() const
Get copy of angular component.
void calcRelativePointJacobian6D(Model &model, const Math::VectorNd &Q, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=RobotDynamics::ReferenceFrame::getWorldFrame(), bool update_kinematics=true)
Compute the 6D jacobian of the origin of a reference frame relative to the origin of another referenc...
Definition: Kinematics.cc:643
Math::FrameVector calcPointAcceleration(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes the linear acceleration of a point on a body.
Definition: Kinematics.cc:1593
void calcRelativePointJacobianAndJacobianDot6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, Math::MatrixNd &GDot, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=RobotDynamics::ReferenceFrame::getWorldFrame(), bool update_kinematics=true)
Compute the point Jacobian of the origin of baseFrame, relative to the origin of relativeFrame, expressed in expressedInFrame. Also compute that point Jacobians time derivative.
Definition: Kinematics.cc:1033
Math::MotionVector gravity
the cartesian vector of the gravity
Definition: Model.h:196
Vector3d transform_copy(const RobotDynamics::Math::SpatialTransform &X) const
int main(int argc, char **argv)
unsigned int appendBody(const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
Adds a Body to the model such that the previously added Body is the Parent.
Definition: Model.cc:517
const double TEST_PREC
Math::SpatialAcceleration calcSpatialAcceleration(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, const unsigned int body_id, const unsigned int relative_body_id, ReferenceFramePtr expressedInFrame=nullptr, const bool update_kinematics=true)
Compute the spatial acceleration of any body with respect to any other body and express the result in...
Definition: Kinematics.cc:1852
std::vector< ReferenceFramePtr > bodyFrames
Definition: Model.h:145
ReferenceFramePtr worldFrame
Definition: Model.h:141
unsigned int addBody(const unsigned int parent_id, const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
Connects a given body to the model.
Definition: Model.cc:271
void calcPointJacobian6D(Model &model, const Math::VectorNd &Q, Math::MatrixNd &G, ReferenceFramePtr frame, bool update_kinematics=true)
Compute the 6D point jacobian of the origin of a reference frame If a position of a point is computed...
Definition: Kinematics.cc:604
SpatialTransform Xrotz(const double &zrot)
Get transform with zero translation and pure rotation about z axis.
EIGEN_STRONG_INLINE void setIncludingFrame(const Math::Vector3d &v, ReferenceFramePtr referenceFrame)
Set both the ReferenceFrame this object is expressed in as well as the (x,y,z) coordinates of the poi...
Definition: FramePoint.hpp:138
EIGEN_STRONG_INLINE Math::Vector3d vec() const
Definition: Point3.hpp:269
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
Math::FrameVector calcPointVelocity(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes the velocity of a point on a body.
Definition: Kinematics.cc:1422
RobotDynamics::Math::VectorNd tau
Compact representation of spatial transformations.
void calcRelativePointJacobianDot6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=RobotDynamics::ReferenceFrame::getWorldFrame(), bool update_kinematics=true)
Compute the time derivative of the 6D jacobian of the origin of a reference frame relative to the ori...
Definition: Kinematics.cc:877
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
Definition: FrameObject.cpp:12
void calcPointJacobianDot6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, RobotDynamics::ReferenceFramePtr frame, Math::MatrixNd &G, bool update_kinematics=true)
Computes the time derivative of a point jacobian of a point on a body.
Definition: Kinematics.cc:826
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
Definition: FrameVector.hpp:33
A SpatialMotion vector is a MotionVector with a RobotDynamics::ReferenceFrame it is expressed in...
void changeFrame(ReferenceFramePtr referenceFrame)
Change the frame of the two 3d vectors. Equivalent to the following math expression ...
Describes a joint relative to the predecessor body.
Definition: Joint.h:228
void calcBodySpatialJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd QDot, unsigned int body_id, Math::MatrixNd &G, const bool update_kinematics=true)
Computes the time derivative of the spatial jacobian for a body. The result will be returned via the ...
Definition: Kinematics.cc:1367
void updateKinematicsParallel(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:214
ReferenceFramePtr getBaseFrame() const
Get a SpatialMotions SpatialMotion::baseFrame.
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
Eigen::VectorXd VectorNd
Definition: rdl_eigenmath.h:25
static bool checkMatrixNdEpsilonClose(const RobotDynamics::Math::MatrixNd &t1, const RobotDynamics::Math::MatrixNd &t2, const double epsilon)
void calcBodySpatialJacobian(Model &model, const Math::VectorNd &Q, unsigned int body_id, Math::MatrixNd &G, bool update_kinematics=true)
Computes the spatial jacobian for a body. The result will be returned via the G argument and represen...
Definition: Kinematics.cc:1310
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::SpatialAccelerationV a
The spatial velocity of the bodies.
Definition: Model.h:200
EIGEN_STRONG_INLINE Vector3d getAngularPart() const
bool inverseKinematics(Model &model, const Math::VectorNd &Qinit, const std::vector< unsigned int > &body_id, const std::vector< Math::Vector3d > &body_point, const std::vector< Math::Vector3d > &target_pos, Math::VectorNd &Qres, double step_tol=1.0e-12, double lambda=0.01, unsigned int max_iter=50)
Computes the inverse kinematics iteratively using a damped Levenberg-Marquardt method (also known as ...
Contains all information about the rigid body model.
Definition: Model.h:121
void calcRelativeBodySpatialJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=nullptr, bool update_kinematics=true)
Computes the rate of change of the jacobian, , with being the "base" frame, being the relative" fra...
Definition: Kinematics.cc:301
void setLinearPart(const Vector3d &v)
Set the linear vector.
void updateKinematicsCustom(Model &model, const Math::VectorNd *Q, const Math::VectorNd *QDot=nullptr, const Math::VectorNd *QDDot=nullptr)
Selectively updates model internal states of body positions, velocities and/or accelerations.
Definition: Kinematics.cc:72
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::MatrixXd MatrixNd
Definition: rdl_eigenmath.h:26
TEST_F(RdlKinematicsFixture, parallelKinematics)
unsigned int fixed_body_discriminator
Value that is used to discriminate between fixed and movable bodies.
Definition: Model.h:312
SpatialAcceleration. For clarity, the ReferenceFrames are stated as follows. A spatial acceleration i...
A FrameVector is a pair of 3D vector with a ReferenceFrame.
static bool checkVector3dEpsilonClose(const RobotDynamics::Math::Vector3d &v1, const RobotDynamics::Math::Vector3d &v2, const double epsilon)
Math::FrameVectorPair calcPointAcceleration6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes linear and angular acceleration of a point on a body.
Definition: Kinematics.cc:1631
Math::FrameVectorPair calcPointVelocity6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes angular and linear velocity of a point that is fixed on a body.
Definition: Kinematics.cc:1459
EIGEN_STRONG_INLINE Vector3d getLinearPart() const
std::vector< ReferenceFramePtr > fixedBodyFrames
Definition: Model.h:154
SpatialMatrix crossm(const SpatialVector &v)
Get the spatial motion cross matrix.
MotionVector transform_copy(const SpatialTransform &X) const
Copies, transforms, and returns a MotionVector. Performs .
void updateKinematicsCustomParallel(Model &model, const Math::VectorNd *Q, const Math::VectorNd *QDot=nullptr, const Math::VectorNd *QDDot=nullptr)
Selectively updates model internal states of body positions, velocities and/or accelerations and spaw...
Definition: Kinematics.cc:194
unsigned int dof_count
number of degrees of freedoms of the model
Definition: Model.h:169
static bool checkFrameVectorPairEpsilonClose(const RobotDynamics::Math::FrameVectorPair &v1, const RobotDynamics::Math::FrameVectorPair &v2, const double epsilon)
void setReferenceFrame(ReferenceFramePtr referenceFrame)
Set the reference frame.
void setBodyFrame(ReferenceFramePtr referenceFrame)
Sets the body frame of a spatial motion.
Namespace for all structures of the RobotDynamics library.
Definition: Body.h:21
static bool checkMatrix3dEpsilonClose(const RobotDynamics::Math::Matrix3d &t1, const RobotDynamics::Math::Matrix3d &t2, const double epsilon)
unsigned int qdot_size
The size of the.
Definition: Model.h:187


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