Fixtures.h
Go to the documentation of this file.
1 #include "rdl_dynamics/Model.h"
3 #include <gtest/gtest.h>
4 
5 using namespace RobotDynamics;
6 using namespace RobotDynamics::Math;
7 
8 class FixedBase3DoFPlanar : public testing::Test
9 {
10  public:
12  {
13  srand(time(NULL));
14  };
15 
17  {
18  Q = VectorNd(model->q_size);
19  QDot = VectorNd(model->qdot_size);
20  QDDot = VectorNd(model->qdot_size);
21  Tau = VectorNd(model->qdot_size);
22 
23  for (int i = 0; i < Q.size(); i++)
24  {
25  Q[i] = 0.4 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
26  QDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
27  Tau[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
28  QDDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
29  }
30  }
31 
32  void SetUp()
33  {
34  model = new Model;
35 
36  /* Basically a model like this, where there are 3 planar
37  * joints rotating about the Y-axis. Link COM's are in
38  * the geometric center of the links.
39  *
40  * ---------------------------- X - axis
41  * * - Y
42  * |
43  * | body_a length - L1 = 1m
44  * |
45  * * - Y
46  * |
47  * |
48  * |
49  * | body_b length - L2 = 2m
50  * |
51  * |
52  * * - Y
53  * |
54  * |
55  * |
56  * |
57  * | body_c length - L3 = 3m
58  * |
59  * |
60  * |
61  * |
62  *
63  *
64  */
65 
66  com_a = Vector3d(0., 0., -0.5);
67  body_a = Body(6., com_a, Vector3d(1.2, 1.3, 1.4));
68  joint_a = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
69 
70  body_a_id = model->addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_a, body_a, "body_a");
71 
72  com_b = Vector3d(0., 0., -1.);
73  body_b = Body(3., com_b, Vector3d(1., 1., 1.));
74  joint_b = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
75 
76  body_b_id = model->addBody(1, Xtrans(Vector3d(0., 0., -1.)), joint_b, body_b, "body_b");
77 
78  com_c = Vector3d(0., 0., -1.5);
79  body_c = Body(4., com_c, Vector3d(1., 1., 1.));
80  joint_c = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
81 
82  body_c_id = model->addBody(2, Xtrans(Vector3d(0., 0., -2.)), joint_c, body_c, "body_c");
83 
84  Joint fixed_joint(JointType::JointTypeFixed);
85  Vector3d r_fixed = Vector3d(0.1, 0.1, 0.1);
86  X_fixed_c = Xtrans(Vector3d(0.02, 0.01, -0.25));
87  X_fixed_c2 = Xtrans(Vector3d(-0.04, -0.02, 0.5));
88  fixed_body = RobotDynamics::Body(0.1, r_fixed, Vector3d(0.1, 0.1, 0.1));
89  fixed_body_c_id = model->addBody(body_c_id, X_fixed_c, fixed_joint, fixed_body, "fixed_body_c");
90  fixed_body_c_2_id = model->addBody(fixed_body_c_id, X_fixed_c2, fixed_joint, fixed_body, "fixed_body_c_2");
91 
92  Q = VectorNd(model->q_size);
93  QDot = VectorNd(model->qdot_size);
94  QDDot = VectorNd(model->qdot_size);
95  Tau = VectorNd(model->qdot_size);
96  }
97 
98  void TearDown()
99  {
100  delete model;
101  }
102 
104 
105  unsigned int body_a_id, body_b_id, body_c_id, ref_body_id, fixed_body_c_id, fixed_body_c_2_id;
106  RobotDynamics::Body body_a, body_b, body_c, fixed_body;
107  RobotDynamics::Joint joint_a, joint_b, joint_c;
108  Vector3d com_a, com_b, com_c;
110 
115 };
116 
117 class FixedBaseTwoChain6DoF3D : public testing::Test
118 {
119  public:
121 
122  void SetUp()
123  {
124  model = new Model;
125 
126  /* Two kinematic chains of 3 links.COM's are in
127  * the geometric centers of the links.
128  *
129  * /
130  * /
131  * / body_f length - L6 = 1m
132  * Z
133  * /
134  * * - neg-X -----------
135  * |
136  * |
137  * | body_e length - L5 = 1m
138  * Z
139  * |
140  * * - neg-X ------------
141  * /
142  * /
143  * / body_d length - L4 = 2m
144  * /
145  * X
146  * /
147  * origin/rotx * - neg-Y ----------
148  * |
149  * | body_a length - L1 = 1m
150  * |
151  * rotx * - Z ----------
152  * |
153  * neg-Y
154  * |
155  * | body_b length - L2 = 2m
156  * |
157  * |
158  * rotx * - Y ----------
159  * |
160  * Z
161  * |
162  * |
163  * | body_c length - L3 = 3m
164  * |
165  * |
166  * |
167  * |
168  *
169  *
170  */
172 
173  body_a = Body(1., Vector3d(0., 0., -0.5), Vector3d(1., 1., 1.));
174  joint_a = Joint(SpatialVector(1., 0., 0., 0., 0., 0.));
175 
176  body_a_id = model->addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_a, body_a, "body_a");
177 
178  body_b = Body(1., Vector3d(0., -1., 0.), Vector3d(1., 1., 1.));
179  joint_b = Joint(SpatialVector(1., 0., 0., 0., 0., 0.));
180 
181  X = Xrotx(M_PI_2);
182  X.r = Vector3d(0., 0., -1.);
183 
184  body_b_id = model->addBody(body_a_id, X, joint_b, body_b, "body_b");
185 
186  body_c = Body(1., Vector3d(0., 0., 1.5), Vector3d(1., 1., 1.));
187  joint_c = Joint(SpatialVector(1., 0., 0., 0., 0., 0.));
188 
189  X = Xrotx(M_PI_2);
190  X.r = Vector3d(0., -2., 0.);
191 
192  body_c_id = model->addBody(2, X, joint_c, body_c, "body_c");
193 
194  body_d = Body(1., Vector3d(1., 0., 0.), Vector3d(1., 1., 1.));
195  joint_d = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
196 
197  body_d_id = model->addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_d, body_d, "body_d");
198 
199  body_e = Body(1., Vector3d(0., 0., 0.5), Vector3d(1., 1., 1.));
200  joint_e = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
201 
202  X = Xrotz(M_PI_2);
203  X.r = Vector3d(2., 0., 0.);
204 
205  body_e_id = model->addBody(body_d_id, X, joint_e, body_e, "body_e");
206 
207  body_f = Body(1., Vector3d(0., 0., 0.5), Vector3d(1., 1., 1.));
208  joint_f = Joint(SpatialVector(1., 0., 0., 0., 0., 0.));
209 
210  X = Xrotx(M_PI_2);
211  X.r = Vector3d(0., 0., 1.);
212 
213  body_f_id = model->addBody(body_e_id, X, joint_f, body_f, "body_f");
214 
215  Q = VectorNd::Constant((size_t)model->dof_count, 0.);
216  QDot = VectorNd::Constant((size_t)model->dof_count, 0.);
217  QDDot = VectorNd::Constant((size_t)model->dof_count, 0.);
218  Tau = VectorNd::Constant((size_t)model->dof_count, 0.);
219  }
220 
221  void TearDown()
222  {
223  delete model;
224  }
225 
227 
228  unsigned int body_a_id, body_b_id, body_c_id, body_d_id, body_e_id, body_f_id;
229  RobotDynamics::Body body_a, body_b, body_c, body_d, body_e, body_f;
230  RobotDynamics::Joint joint_a, joint_b, joint_c, joint_d, joint_e, joint_f;
231 
236 };
237 
238 class FloatingBaseWith2SingleDofJoints : public testing::Test
239 {
240  public:
242  {
243  srand(time(nullptr));
244  }
245 
264  void SetUp()
265  {
266  model = new Model;
267 
268  root_body = Body(1., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
269 
270  root_joint = Joint(JointTypeFloatingBase);
272 
273  root_body_id = model->appendBody(X, root_joint, root_body, "floating_body");
274 
275  body_1 = Body(1., Vector3d(0., 0., -0.5), Vector3d(1., 1., 1.));
276  joint_1 = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
277 
278  X.E = Matrix3dIdentity;
279  X.r = Vector3d(-1.5, 0., 0.);
280 
281  body_1_id = model->addBody(root_body_id, X, joint_1, body_1, "body_1");
282 
283  body_2 = Body(1., Vector3d(0., 0., 0.75), Vector3d(1., 1., 1.));
284  joint_2 = Joint(SpatialVector(1., 0., 0., 0., 0., 0.));
285 
286  X.E = Xrotz(M_PI_2).E;
287  X.r = Vector3d(1.5, 0., 0.);
288 
289  body_2_id = model->addBody(root_body_id, X, joint_2, body_2, "body_2");
290 
291  Q = VectorNd::Constant((size_t)model->dof_count + 1, 0.); // dof_count+1 because there is a spherical joint
292  QDot = VectorNd::Constant((size_t)model->dof_count, 0.);
293  QDDot = VectorNd::Constant((size_t)model->dof_count, 0.);
294  Tau = VectorNd::Constant((size_t)model->dof_count, 0.);
295  }
296 
298  {
299  for (int i = 0; i < Q.size(); i++)
300  {
301  Q[i] = 0.4 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
302  }
303  for (int i = 0; i < QDot.size(); i++)
304  {
305  QDot[i] = 0.1 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
306  Tau[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
307  QDDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
308  }
309 
311  q = model->GetQuaternion(root_body_id, Q);
312  q.normalize();
313  model->SetQuaternion(root_body_id, q, Q);
314  }
315 
316  void TearDown()
317  {
318  delete model;
319  }
320 
323  RobotDynamics::Joint root_joint, joint_1, joint_2;
324  unsigned int root_body_id, body_1_id, body_2_id;
325 
330 };
331 
332 class FixedBase3DoF : public testing::Test
333 {
334  public:
336 
337  void SetUp()
338  {
339  model = new Model;
340 
341  /* Basically a model like this, where X are the Center of Masses
342  * and the CoM of the last (3rd) body comes out of the Y=X=0 plane.
343  *
344  * Z
345  * *---*
346  * |
347  * |
348  * Z |
349  * O---*
350  * Y
351  */
352 
353  body_a = Body(1., Vector3d(1., 0., 0.), Vector3d(1., 1., 1.));
354  joint_a = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
355 
356  body_a_id = model->addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_a, body_a, "body_a");
357 
358  body_b = Body(1., Vector3d(0., 1., 0.), Vector3d(1., 1., 1.));
359  joint_b = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
360 
361  body_b_id = model->addBody(1, Xtrans(Vector3d(1., 0., 0.)), joint_b, body_b, "body_b");
362 
363  body_c = Body(1., Vector3d(0., 0., 1.), Vector3d(1., 1., 1.));
364  joint_c = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
365 
366  body_c_id = model->addBody(2, Xtrans(Vector3d(0., 1., 0.)), joint_c, body_c, "body_c");
367 
368  Q = VectorNd::Constant((size_t)model->dof_count, 0.);
369  QDot = VectorNd::Constant((size_t)model->dof_count, 0.);
370  QDDot = VectorNd::Constant((size_t)model->dof_count, 0.);
371  Tau = VectorNd::Constant((size_t)model->dof_count, 0.);
372 
373  point_position = Vector3d::Zero(3);
374  point_acceleration = Vector3d::Zero(3);
375 
376  ref_body_id = 0;
377  }
378 
379  void TearDown()
380  {
381  delete model;
382  }
383 
385 
386  unsigned int body_a_id, body_b_id, body_c_id, ref_body_id;
387  RobotDynamics::Body body_a, body_b, body_c;
388  RobotDynamics::Joint joint_a, joint_b, joint_c;
389 
394 
397 };
398 
399 struct FixedBase6DoF : public testing::Test
400 {
402  {
403  }
404 
405  void SetUp()
406  {
407  using namespace RobotDynamics;
408  using namespace RobotDynamics::Math;
409 
410  model = new Model;
411 
412  model->gravity = MotionVector(0., 0., 0., 0., -9.81, 0.);
413 
414  /* 3 DoF (rot.) joint at base
415  * 3 DoF (rot.) joint child origin
416  *
417  * X Contact point (ref child)
418  * |
419  * Base |
420  * / body |
421  * O-------*
422  * \
423  * Child body
424  */
425 
426  // base body (3 DoF)
427  base_rot_z = Body(0., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
428  joint_base_rot_z = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
429  base_rot_z_id = model->addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_base_rot_z, base_rot_z);
430 
431  base_rot_y = Body(0., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
432  joint_base_rot_y = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
433  base_rot_y_id = model->appendBody(Xtrans(Vector3d(0., 0., 0.)), joint_base_rot_y, base_rot_y);
434 
435  base_rot_x = Body(1., Vector3d(0.5, 0., 0.), Vector3d(1., 1., 1.));
436  joint_base_rot_x = Joint(SpatialVector(1., 0., 0., 0., 0., 0.));
437  base_rot_x_id = model->addBody(base_rot_y_id, Xtrans(Vector3d(0., 0., 0.)), joint_base_rot_x, base_rot_x);
438 
439  // child body (3 DoF)
440  child_rot_z = Body(0., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
441  joint_child_rot_z = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
442  child_rot_z_id = model->addBody(base_rot_x_id, Xtrans(Vector3d(1., 0., 0.)), joint_child_rot_z, child_rot_z);
443 
444  child_rot_y = Body(0., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
445  joint_child_rot_y = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
446  child_rot_y_id = model->addBody(child_rot_z_id, Xtrans(Vector3d(0., 0., 0.)), joint_child_rot_y, child_rot_y);
447 
448  child_rot_x = Body(1., Vector3d(0., 0.5, 0.), Vector3d(1., 1., 1.));
449  joint_child_rot_x = Joint(SpatialVector(1., 0., 0., 0., 0., 0.));
450  child_rot_x_id = model->addBody(child_rot_y_id, Xtrans(Vector3d(0., 0., 0.)), joint_child_rot_x, child_rot_x);
451 
452  Q = VectorNd::Constant(model->mBodies.size() - 1, 0.);
453  QDot = VectorNd::Constant(model->mBodies.size() - 1, 0.);
454  QDDot = VectorNd::Constant(model->mBodies.size() - 1, 0.);
455  Tau = VectorNd::Constant(model->mBodies.size() - 1, 0.);
456 
457  contact_body_id = child_rot_x_id;
458  contact_point = Vector3d(0.5, 0.5, 0.);
459  contact_normal = Vector3d(0., 1., 0.);
460  }
461 
462  void TearDown()
463  {
464  delete model;
465  }
466 
468 
469  unsigned int base_rot_z_id, base_rot_y_id, base_rot_x_id, child_rot_z_id, child_rot_y_id, child_rot_x_id, base_body_id;
470 
471  RobotDynamics::Body base_rot_z, base_rot_y, base_rot_x, child_rot_z, child_rot_y, child_rot_x;
472 
473  RobotDynamics::Joint joint_base_rot_z, joint_base_rot_y, joint_base_rot_x, joint_child_rot_z, joint_child_rot_y, joint_child_rot_x;
474 
479 
480  unsigned int contact_body_id;
484 };
485 
486 class FloatingBase12DoF : public testing::Test
487 {
488  public:
490  {
491  }
492 
493  void SetUp()
494  {
495  using namespace RobotDynamics;
496  using namespace RobotDynamics::Math;
497 
498  model = new Model;
499 
500  model->gravity = SpatialVector(0., 0., 0., 0., -9.81, 0.);
501 
502  /* 3 DoF (rot.) joint at base
503  * 3 DoF (rot.) joint child origin
504  *
505  * X Contact point (ref child)
506  * |
507  * Base |
508  * / body |
509  * O-------*
510  * \
511  * Child body
512  */
513 
514  base_rot_x = Body(1., Vector3d(0.5, 0., 0.), Vector3d(1., 1., 1.));
515  base_rot_x_id = model->addBody(0, SpatialTransform(),
516  Joint(SpatialVector(0., 0., 0., 1., 0., 0.), SpatialVector(0., 0., 0., 0., 1., 0.), SpatialVector(0., 0., 0., 0., 0., 1.),
517  SpatialVector(0., 0., 1., 0., 0., 0.), SpatialVector(0., 1., 0., 0., 0., 0.), SpatialVector(1., 0., 0., 0., 0., 0.)),
518  base_rot_x);
519 
520  // child body 1 (3 DoF)
521  child_rot_z = Body(0., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
522  joint_child_rot_z = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
523  child_rot_z_id = model->addBody(base_rot_x_id, Xtrans(Vector3d(1., 0., 0.)), joint_child_rot_z, child_rot_z);
524 
525  child_rot_y = Body(0., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
526  joint_child_rot_y = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
527  child_rot_y_id = model->addBody(child_rot_z_id, Xtrans(Vector3d(0., 0., 0.)), joint_child_rot_y, child_rot_y);
528 
529  child_rot_x = Body(1., Vector3d(0., 0.5, 0.), Vector3d(1., 1., 1.));
530  joint_child_rot_x = Joint(SpatialVector(1., 0., 0., 0., 0., 0.));
531  child_rot_x_id = model->addBody(child_rot_y_id, Xtrans(Vector3d(0., 0., 0.)), joint_child_rot_x, child_rot_x);
532 
533  // child body (3 DoF)
534  child_2_rot_z = Body(0., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
535  joint_child_2_rot_z = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
536  child_2_rot_z_id = model->addBody(child_rot_x_id, Xtrans(Vector3d(1., 0., 0.)), joint_child_2_rot_z, child_2_rot_z);
537 
538  child_2_rot_y = Body(0., Vector3d(0., 0., 0.), Vector3d(1., 1., 1.));
539  joint_child_2_rot_y = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
540  child_2_rot_y_id = model->addBody(child_2_rot_z_id, Xtrans(Vector3d(0., 0., 0.)), joint_child_2_rot_y, child_2_rot_y);
541 
542  child_2_rot_x = Body(1., Vector3d(0., 0.5, 0.), Vector3d(1., 1., 1.));
543  joint_child_2_rot_x = Joint(SpatialVector(1., 0., 0., 0., 0., 0.));
544  child_2_rot_x_id = model->addBody(child_2_rot_y_id, Xtrans(Vector3d(0., 0., 0.)), joint_child_2_rot_x, child_2_rot_x);
545 
546  Q = VectorNd::Constant(model->dof_count, 0.);
547  QDot = VectorNd::Constant(model->dof_count, 0.);
548  QDDot = VectorNd::Constant(model->dof_count, 0.);
549  Tau = VectorNd::Constant(model->dof_count, 0.);
550  }
551 
552  void TearDown()
553  {
554  delete model;
555  }
556 
558 
559  unsigned int base_rot_z_id, base_rot_y_id, base_rot_x_id, child_rot_z_id, child_rot_y_id, child_rot_x_id, child_2_rot_z_id, child_2_rot_y_id, child_2_rot_x_id,
560  base_body_id;
561 
562  RobotDynamics::Body base_rot_z, base_rot_y, base_rot_x, child_rot_z, child_rot_y, child_rot_x, child_2_rot_z, child_2_rot_y, child_2_rot_x;
563 
564  RobotDynamics::Joint joint_base_rot_z, joint_base_rot_y, joint_base_rot_x, joint_child_rot_z, joint_child_rot_y, joint_child_rot_x, joint_child_2_rot_z,
565  joint_child_2_rot_y, joint_child_2_rot_x;
566 
571 };
572 
573 struct SimpleFixture : public testing::Test
574 {
576  {
577  }
578 
579  void SetUp()
580  {
581  model = new RobotDynamics::Model;
582  model->gravity = RobotDynamics::Math::SpatialVector(0., 0., 0., 0., -9.81, 0.);
583  }
584 
585  void TearDown()
586  {
587  delete model;
588  }
589 
591  {
592  Q = RobotDynamics::Math::VectorNd::Zero(model->dof_count);
593  QDot = RobotDynamics::Math::VectorNd::Zero(model->dof_count);
594  QDDot = RobotDynamics::Math::VectorNd::Zero(model->dof_count);
595  Tau = RobotDynamics::Math::VectorNd::Zero(model->dof_count);
596  }
597 
599 
604 };
605 
606 struct FixedJoint2DoF : public testing::Test
607 {
609  {
610  }
611 
612  void SetUp()
613  {
614  using namespace RobotDynamics;
615  using namespace RobotDynamics::Math;
616 
617  model = new Model;
618 
619  /* Basically a model like this, where X are the Center of Masses
620  * and the CoM of the last (3rd) body comes out of the Y=X=0 plane.
621  *
622  * Z
623  * *---*
624  * |
625  * |
626  * Z |
627  * O---*
628  * Y
629  */
630 
631  body_a = Body(1., Vector3d(1., 0., 0.), Vector3d(1., 1., 1.));
632  joint_a = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
633 
634  body_a_id = model->addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_a, body_a);
635 
636  body_b = Body(1., Vector3d(0., 1., 0.), Vector3d(1., 1., 1.));
637  joint_b = Joint(JointTypeFixed);
638 
639  body_b_id = model->addBody(1, Xtrans(Vector3d(1., 0., 0.)), joint_b, body_b);
640 
641  body_c = Body(1., Vector3d(0., 0., 1.), Vector3d(1., 1., 1.));
642  joint_c = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
643 
644  body_c_id = model->addBody(2, Xtrans(Vector3d(0., 1., 0.)), joint_c, body_c);
645 
646  Q = VectorNd::Constant((size_t)model->dof_count, 0.);
647  QDot = VectorNd::Constant((size_t)model->dof_count, 0.);
648  QDDot = VectorNd::Constant((size_t)model->dof_count, 0.);
649 
650  point_position = Vector3d::Zero(3);
651  point_acceleration = Vector3d::Zero(3);
652 
653  ref_body_id = 0;
654  }
655 
656  void TearDown()
657  {
658  delete model;
659  }
660 
662 
663  unsigned int body_a_id, body_b_id, body_c_id, ref_body_id;
664  RobotDynamics::Body body_a, body_b, body_c;
665  RobotDynamics::Joint joint_a, joint_b, joint_c;
666 
670 
672 };
673 
676 struct FixedAndMovableJoint : public testing::Test
677 {
679  {
680  }
681 
682  void SetUp()
683  {
684  using namespace RobotDynamics;
685  using namespace RobotDynamics::Math;
686 
687  model_movable = new Model;
688 
689  /* Basically a model like this, where X are the Center of Masses
690  * and the CoM of the last (3rd) body comes out of the Y=X=0 plane.
691  *
692  * Z
693  * *---*
694  * |
695  * |
696  * Z |
697  * O---*
698  * Y
699  */
700 
701  body_a = Body(1., Vector3d(1., 0., 0.), Vector3d(1., 1., 1.));
702  joint_a = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
703 
704  body_a_id = model_movable->addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_a, body_a);
705 
706  body_b = Body(1., Vector3d(0., 1., 0.), Vector3d(1., 1., 1.));
707  joint_b = Joint(SpatialVector(0., 1., 0., 0., 0., 0.));
708 
709  body_b_id = model_movable->addBody(body_a_id, Xtrans(Vector3d(1., 0., 0.)), joint_b, body_b);
710 
711  body_c = Body(1., Vector3d(0., 0., 1.), Vector3d(1., 1., 1.));
712  joint_c = Joint(SpatialVector(0., 0., 1., 0., 0., 0.));
713 
714  body_c_id = model_movable->addBody(body_b_id, Xtrans(Vector3d(0., 1., 0.)), joint_c, body_c);
715 
716  Q = VectorNd::Constant((size_t)model_movable->dof_count, 0.);
717  QDot = VectorNd::Constant((size_t)model_movable->dof_count, 0.);
718  QDDot = VectorNd::Constant((size_t)model_movable->dof_count, 0.);
719  Tau = VectorNd::Constant((size_t)model_movable->dof_count, 0.);
720  C_movable = VectorNd::Zero((size_t)model_movable->dof_count);
721  H_movable = MatrixNd::Zero((size_t)model_movable->dof_count, (size_t)model_movable->dof_count);
722 
723  // Assemble the fixed joint model
724  model_fixed = new Model;
725 
726  body_a_fixed_id = model_fixed->addBody(0, Xtrans(Vector3d(0., 0., 0.)), joint_a, body_a, "body_a");
727  Joint joint_fixed(JointTypeFixed);
728  body_b_fixed_id = model_fixed->addBody(body_a_fixed_id, Xtrans(Vector3d(1., 0., 0.)), joint_fixed, body_b, "body_b");
729  body_c_fixed_id = model_fixed->addBody(body_b_fixed_id, Xtrans(Vector3d(0., 1., 0.)), joint_c, body_c, "body_c");
730 
731  Q_fixed = VectorNd::Constant((size_t)model_fixed->dof_count, 0.);
732  QDot_fixed = VectorNd::Constant((size_t)model_fixed->dof_count, 0.);
733  QDDot_fixed = VectorNd::Constant((size_t)model_fixed->dof_count, 0.);
734  Tau_fixed = VectorNd::Constant((size_t)model_fixed->dof_count, 0.);
735  C_fixed = VectorNd::Zero((size_t)model_fixed->dof_count);
736  H_fixed = MatrixNd::Zero((size_t)model_fixed->dof_count, (size_t)model_fixed->dof_count);
737 
738  point_position = Vector3d::Zero(3);
739  point_acceleration = Vector3d::Zero(3);
740 
741  ref_body_id = 0;
742  }
743 
744  void TearDown()
745  {
746  delete model_movable;
747  delete model_fixed;
748  }
749 
751  {
752  assert(q_fixed.size() == model_fixed->dof_count);
753 
754  RobotDynamics::Math::VectorNd q_movable(model_movable->dof_count);
755 
756  q_movable[0] = q_fixed[0];
757  q_movable[1] = 0.;
758  q_movable[2] = q_fixed[1];
759 
760  return q_movable;
761  }
762 
764  {
765  assert(H_movable.rows() == model_movable->dof_count);
766  assert(H_movable.cols() == model_movable->dof_count);
767  RobotDynamics::Math::MatrixNd H(model_fixed->dof_count, model_fixed->dof_count);
768 
769  H(0, 0) = H_movable(0, 0);
770  H(0, 1) = H_movable(0, 2);
771  H(1, 0) = H_movable(2, 0);
772  H(1, 1) = H_movable(2, 2);
773 
774  return H;
775  }
776 
779 
780  unsigned int body_a_id, body_b_id, body_c_id, ref_body_id;
781  unsigned int body_a_fixed_id, body_b_fixed_id, body_c_fixed_id;
782 
783  RobotDynamics::Body body_a, body_b, body_c;
784  RobotDynamics::Joint joint_a, joint_b, joint_c;
785 
792 
799 
801 };
802 
805 struct RotZRotZYXFixed : public testing::Test
806 {
808  {
809  }
810 
811  void SetUp()
812  {
813  using namespace RobotDynamics;
814  using namespace RobotDynamics::Math;
815 
816  model = new Model;
817 
818  Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.));
819 
820  Joint joint_rot_zyx(SpatialVector(0., 0., 1., 0., 0., 0.), SpatialVector(0., 1., 0., 0., 0., 0.), SpatialVector(1., 0., 0., 0., 0., 0.));
821 
822  Body body_a(1., RobotDynamics::Math::Vector3d(1., 0.4, 0.4), RobotDynamics::Math::Vector3d(1., 1., 1.));
823  Body body_b(2., RobotDynamics::Math::Vector3d(1., 0.4, 0.4), RobotDynamics::Math::Vector3d(1., 1., 1.));
824  Body body_fixed(10., RobotDynamics::Math::Vector3d(1., 0.4, 0.4), RobotDynamics::Math::Vector3d(1., 1., 1.));
825 
826  fixture_transform_a = Xtrans(RobotDynamics::Math::Vector3d(1., 2., 3.));
827  fixture_transform_b = Xtrans(RobotDynamics::Math::Vector3d(4., 5., 6.));
828  fixture_transform_fixed = Xtrans(RobotDynamics::Math::Vector3d(-1., -2., -3.));
829 
830  body_a_id = model->addBody(0, fixture_transform_a, joint_rot_z, body_a);
831  body_b_id = model->appendBody(fixture_transform_b, joint_rot_zyx, body_b);
832  body_fixed_id = model->appendBody(fixture_transform_fixed, Joint(JointTypeFixed), body_fixed);
833 
834  Q = VectorNd(model->q_size);
835  QDot = VectorNd(model->qdot_size);
836  QDDot = VectorNd(model->qdot_size);
837  Tau = VectorNd(model->qdot_size);
838 
839  Q.setZero();
840  QDot.setZero();
841  QDDot.setZero();
842  Tau.setZero();
843  }
844 
845  void TearDown()
846  {
847  delete model;
848  }
849 
851  {
852  for (int i = 0; i < Q.size(); i++)
853  {
854  Q[i] = 0.4 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
855  QDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
856  Tau[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
857  QDDot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
858  }
859  }
860 
862 
863  unsigned int body_a_id, body_b_id, body_fixed_id;
864 
869 
873 };
874 
875 struct TwoArms12DoF : public testing::Test
876 {
878  {
879  srand(time(nullptr));
880  }
881 
882  void SetUp()
883  {
884  using namespace RobotDynamics;
885  using namespace RobotDynamics::Math;
886 
887  model = new Model;
888 
889  /* Basically a model like this, where X are the Center of Masses
890  * and the CoM of the last (3rd) body comes out of the Y=X=0 plane.
891  *
892  * *----O----*
893  * | |
894  * | |
895  * * *
896  * | |
897  * | |
898  *
899  */
900 
901  Body body_upper = Body(1., Vector3d(0., -0.2, 0.), Vector3d(1.1, 1.3, 1.5));
902  Body body_lower = Body(0.5, Vector3d(0., -0.15, 0.), Vector3d(0.3, 0.5, 0.2));
903 
904  Joint joint_zyx = Joint(SpatialVector(0., 0., 1., 0., 0., 0.), SpatialVector(0., 1., 0., 0., 0., 0.), SpatialVector(1., 0., 0., 0., 0., 0.));
905 
906  right_upper_arm = model->appendBody(Xtrans(Vector3d(0., 0., -0.3)), joint_zyx, body_upper, "RightUpper");
907  // model->appendBody (Xtrans (Vector3d (0., -0.4, 0.)), joint_zyx, body_lower, "RightLower");
908  left_upper_arm = model->addBody(0, Xtrans(Vector3d(0., 0., 0.3)), joint_zyx, body_upper, "LeftUpper");
909  // model->appendBody (Xtrans (Vector3d (0., -0.4, 0.)), joint_zyx, body_lower, "LeftLower");
910 
911  q = VectorNd::Constant((size_t)model->dof_count, 0.);
912  qdot = VectorNd::Constant((size_t)model->dof_count, 0.);
913  qddot = VectorNd::Constant((size_t)model->dof_count, 0.);
914  tau = VectorNd::Constant((size_t)model->dof_count, 0.);
915  }
916 
918  {
919  for (int i = 0; i < q.size(); i++)
920  {
921  q[i] = 0.4 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
922  qdot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
923  tau[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
924  qddot[i] = 0.5 * M_PI * static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
925  }
926  }
927 
928  void TearDown()
929  {
930  delete model;
931  }
932 
934 
939 
940  unsigned int right_upper_arm, left_upper_arm;
941 };
942 
943 struct FixedBase6DoF12DoFFloatingBase : public testing::Test
944 {
946  {
947  }
948 
949  void SetUp()
950  {
951  using namespace RobotDynamics;
952  using namespace RobotDynamics::Math;
953 
954  model = new Model;
955 
956  model->gravity = SpatialVector(0., 0., 0., 0., -9.81, 0.);
957 
958  /* 3 DoF (rot.) joint at base
959  * 3 DoF (rot.) joint child origin
960  *
961  * X Contact point (ref child)
962  * |
963  * Base |
964  * / body |
965  * O-------*
966  * \
967  * Child body
968  */
969 
970  // base body (3 DoF)
971  base = Body(1., Vector3d(0.5, 0., 0.), Vector3d(1., 1., 1.));
972  base_id = model->addBody(0, SpatialTransform(),
973  Joint(SpatialVector(0., 0., 0., 1., 0., 0.), SpatialVector(0., 0., 0., 0., 1., 0.), SpatialVector(0., 0., 0., 0., 0., 1.),
974  SpatialVector(0., 0., 1., 0., 0., 0.), SpatialVector(0., 1., 0., 0., 0., 0.), SpatialVector(1., 0., 0., 0., 0., 0.)),
975  base);
976 
977  // child body 1 (3 DoF)
978  child = Body(1., Vector3d(0., 0.5, 0.), Vector3d(1., 1., 1.));
979  joint_rotzyx = Joint(SpatialVector(0., 0., 1., 0., 0., 0.), SpatialVector(0., 1., 0., 0., 0., 0.), SpatialVector(1., 0., 0., 0., 0., 0.));
980  child_id = model->addBody(base_id, Xtrans(Vector3d(1., 0., 0.)), joint_rotzyx, child);
981 
982  // child body (3 DoF)
983  child_2 = Body(1., Vector3d(0., 0.5, 0.), Vector3d(1., 1., 1.));
984  child_2_id = model->addBody(child_id, Xtrans(Vector3d(1., 0., 0.)), joint_rotzyx, child_2);
985 
986  Q = VectorNd::Constant(model->dof_count, 0.);
987  QDot = VectorNd::Constant(model->dof_count, 0.);
988  QDDot = VectorNd::Constant(model->dof_count, 0.);
989  Tau = VectorNd::Constant(model->dof_count, 0.);
990 
991  contact_body_id = child_id;
992  contact_point = Vector3d(0.5, 0.5, 0.);
993  contact_normal = Vector3d(0., 1., 0.);
994  }
995 
996  void TearDown()
997  {
998  delete model;
999  }
1000 
1002 
1003  unsigned int base_id, child_id, child_2_id;
1004 
1006 
1008 
1013 
1014  unsigned int contact_body_id;
1018 };
Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.))
RobotDynamics::Model * model
Definition: Fixtures.h:861
RobotDynamics::Joint joint_f
Definition: Fixtures.h:230
RobotDynamics::Joint joint_c
Definition: Fixtures.h:107
RobotDynamics::Math::VectorNd Tau
Definition: Fixtures.h:570
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:392
Math::FrameVector point_accel
Definition: Fixtures.h:396
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:1010
RobotDynamics::Joint root_joint
Definition: Fixtures.h:323
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:111
Describes all properties of a single body.
Definition: Body.h:30
RobotDynamics::Math::VectorNd Q_fixed
Definition: Fixtures.h:793
RobotDynamics::Math::VectorNd Tau
Definition: Fixtures.h:329
unsigned int body_c_fixed_id
Definition: Fixtures.h:781
VectorNd Tau
RobotDynamics::Math::VectorNd Tau
Definition: Fixtures.h:478
RobotDynamics::Math::Vector3d contact_normal
Definition: Fixtures.h:1016
RobotDynamics::Math::MatrixNd CreateReducedInertiaMatrix(const RobotDynamics::Math::MatrixNd &H_movable)
Definition: Fixtures.h:763
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:865
RobotDynamics::Math::VectorNd Tau
Definition: Fixtures.h:789
RobotDynamics::Math::Vector3d contact_point
Definition: Fixtures.h:481
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:567
RobotDynamics::Math::VectorNd Tau
Definition: Fixtures.h:868
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:602
VectorNd QDDot
RobotDynamics::Model * model
Definition: Fixtures.h:103
void SetUp()
Definition: Fixtures.h:579
Matrix3d Matrix3dIdentity
void randomizeStates()
Definition: Fixtures.h:917
RobotDynamics::Math::Vector3d contact_normal
Definition: Fixtures.h:482
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:328
unsigned int body_fixed_id
Definition: Fixtures.h:863
VectorNd QDot
Fixture that contains two models of which one has one joint fixed.
Definition: Fixtures.h:676
void TearDown()
Definition: Fixtures.h:928
RobotDynamics::Math::VectorNd qdot
Definition: Fixtures.h:936
void TearDown()
Definition: Fixtures.h:379
RobotDynamics::Math::VectorNd QDDot_fixed
Definition: Fixtures.h:795
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:569
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:866
RobotDynamics::Math::MatrixNd H_fixed
Definition: Fixtures.h:798
RobotDynamics::Math::SpatialTransform fixture_transform_a
Definition: Fixtures.h:870
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:787
RobotDynamics::Joint joint_c
Definition: Fixtures.h:665
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:600
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:113
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
VectorNd Q
RobotDynamics::Model * model
Definition: Fixtures.h:384
Fixed joint which causes the inertial properties to be merged with.
Definition: Joint.h:205
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:601
RobotDynamics::Math::VectorNd Tau_fixed
Definition: Fixtures.h:796
void TearDown()
Definition: Fixtures.h:656
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:669
RobotDynamics::Model * model
Definition: Fixtures.h:321
RobotDynamics::ConstraintSet constraint_set
Definition: Fixtures.h:483
RobotDynamics::Math::VectorNd CreateDofVectorFromReducedVector(const RobotDynamics::Math::VectorNd &q_fixed)
Definition: Fixtures.h:750
void SetUp()
Definition: Fixtures.h:882
Math::MotionVector gravity
the cartesian vector of the gravity
Definition: Model.h:196
RobotDynamics::Body body_c
Definition: Fixtures.h:387
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:390
RobotDynamics::Math::MatrixNd H_movable
Definition: Fixtures.h:791
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:668
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:112
void TearDown()
Definition: Fixtures.h:585
RobotDynamics::Model * model
Definition: Fixtures.h:226
RobotDynamics::Model * model
Definition: Fixtures.h:467
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:475
void SetUp()
Definition: Fixtures.h:612
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
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:788
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:234
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:568
RobotDynamics::Body child_2
Definition: Fixtures.h:1005
unsigned int child_rot_z_id
Definition: Fixtures.h:469
SpatialTransform Xrotz(const double &zrot)
Get transform with zero translation and pure rotation about z axis.
RobotDynamics::Math::SpatialTransform fixture_transform_fixed
Definition: Fixtures.h:872
RobotDynamics::Body root_body
Definition: Fixtures.h:322
unsigned int child_rot_z_id
Definition: Fixtures.h:559
unsigned int ref_body_id
Definition: Fixtures.h:663
Compact representation of spatial transformations.
Structure that contains both constraint information and workspace memory.
Definition: Contacts.h:168
void randomizeStates()
Definition: Fixtures.h:16
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:476
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:477
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
Definition: FrameVector.hpp:33
RobotDynamics::Math::VectorNd C_fixed
Definition: Fixtures.h:797
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:867
RobotDynamics::ConstraintSet constraint_set
Definition: Fixtures.h:1017
RobotDynamics::Body child_rot_z
Definition: Fixtures.h:471
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:667
RobotDynamics::Model * model_fixed
Definition: Fixtures.h:777
RobotDynamics::Math::VectorNd QDot_fixed
Definition: Fixtures.h:794
Describes a joint relative to the predecessor body.
Definition: Joint.h:228
Quaternion that are used for singularity free joints.
Definition: Quaternion.h:25
RobotDynamics::Math::Vector3d point_position
Definition: Fixtures.h:395
RobotDynamics::Math::VectorNd Tau
Definition: Fixtures.h:114
RobotDynamics::Math::VectorNd Tau
Definition: Fixtures.h:235
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
Eigen::VectorXd VectorNd
Definition: rdl_eigenmath.h:25
unsigned int ref_body_id
Definition: Fixtures.h:780
RobotDynamics::Math::Vector3d contact_point
Definition: Fixtures.h:1015
void SetUp()
Definition: Fixtures.h:811
RobotDynamics::Joint joint_c
Definition: Fixtures.h:784
RobotDynamics::Body fixed_body
Definition: Fixtures.h:106
RobotDynamics::Math::VectorNd Tau
Definition: Fixtures.h:1012
unsigned int body_f_id
Definition: Fixtures.h:228
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:233
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:1009
RobotDynamics::Model * model
Definition: Fixtures.h:557
unsigned int ref_body_id
Definition: Fixtures.h:386
RobotDynamics::Body body_c
Definition: Fixtures.h:783
Contains all information about the rigid body model.
Definition: Model.h:121
RobotDynamics::Joint joint_child_rot_z
Definition: Fixtures.h:564
A 6-DoF joint for floating-base (or freeflyer) systems.
Definition: Joint.h:204
Math types such as vectors and matrices and utility functions.
Definition: ForceVector.hpp:21
RobotDynamics::Model * model
Definition: Fixtures.h:661
Eigen::MatrixXd MatrixNd
Definition: rdl_eigenmath.h:26
RobotDynamics::Math::VectorNd C_movable
Definition: Fixtures.h:790
void randomizeStates()
Definition: Fixtures.h:850
SpatialTransform X_fixed_c2
Definition: Fixtures.h:109
RobotDynamics::Math::VectorNd QDDot
Definition: Fixtures.h:1011
RobotDynamics::Math::VectorNd q
Definition: Fixtures.h:935
RobotDynamics::Model * model
Definition: Fixtures.h:933
RobotDynamics::Math::Vector3d point_position
Definition: Fixtures.h:671
void TearDown()
Definition: Fixtures.h:845
RobotDynamics::Math::VectorNd Tau
Definition: Fixtures.h:393
unsigned int ref_body_id
Definition: Fixtures.h:105
RobotDynamics::Joint joint_child_rot_z
Definition: Fixtures.h:473
RobotDynamics::Body child_rot_z
Definition: Fixtures.h:562
void SetUp()
Definition: Fixtures.h:337
RobotDynamics::Model * model
Definition: Fixtures.h:598
RobotDynamics::Joint joint_c
Definition: Fixtures.h:388
RobotDynamics::Joint joint_rotzyx
Definition: Fixtures.h:1007
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:786
RobotDynamics::Math::VectorNd Tau
Definition: Fixtures.h:603
RobotDynamics::Math::Vector3d point_position
Definition: Fixtures.h:800
RobotDynamics::Math::VectorNd tau
Definition: Fixtures.h:938
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:326
RobotDynamics::Model * model
Definition: Fixtures.h:1001
RobotDynamics::Math::SpatialTransform fixture_transform_b
Definition: Fixtures.h:871
RobotDynamics::Math::VectorNd qddot
Definition: Fixtures.h:937
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:327
RobotDynamics::Body body_f
Definition: Fixtures.h:229
unsigned int contact_body_id
Definition: Fixtures.h:480
RobotDynamics::Math::VectorNd QDot
Definition: Fixtures.h:391
void TearDown()
Definition: Fixtures.h:462
RobotDynamics::Model * model_movable
Definition: Fixtures.h:778
RobotDynamics::Body body_c
Definition: Fixtures.h:664
Namespace for all structures of the RobotDynamics library.
Definition: Body.h:21
void ResizeVectors()
Definition: Fixtures.h:590
void SetUp()
Definition: Fixtures.h:405
RobotDynamics::Math::VectorNd Q
Definition: Fixtures.h:232
unsigned int right_upper_arm
Definition: Fixtures.h:940


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