Source

rbdl / tests / ModelTests.cc

The dev branch has multiple heads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
#include <UnitTest++.h>

#include <iostream>

#include "rbdl/rbdl_mathutils.h"
#include "rbdl/Logging.h"

#include "rbdl/Model.h"
#include "rbdl/Kinematics.h"
#include "rbdl/Dynamics.h"

using namespace std;
using namespace RigidBodyDynamics;
using namespace RigidBodyDynamics::Math;

const double TEST_PREC = 1.0e-14;

struct ModelFixture {
	ModelFixture () {
		ClearLogOutput();
		model = new Model;
		model->gravity = Vector3d (0., -9.81, 0.);
	}
	~ModelFixture () {
		delete model;
	}
	Model *model;
};

TEST_FIXTURE(ModelFixture, TestInit) {
	CHECK_EQUAL (1u, model->lambda.size());
	CHECK_EQUAL (1u, model->mu.size());
	CHECK_EQUAL (0u, model->dof_count);

	CHECK_EQUAL (1u, model->v.size());
	CHECK_EQUAL (1u, model->a.size());
	
	CHECK_EQUAL (1u, model->mJoints.size());
	CHECK_EQUAL (1u, model->S.size());

	CHECK_EQUAL (1u, model->c.size());
	CHECK_EQUAL (1u, model->IA.size());
	CHECK_EQUAL (1u, model->pA.size());
	CHECK_EQUAL (1u, model->U.size());
	CHECK_EQUAL (1u, model->d.size());
	CHECK_EQUAL (1u, model->u.size());
	CHECK_EQUAL (1u, model->Ic.size());
	
	CHECK_EQUAL (1u, model->X_lambda.size());
	CHECK_EQUAL (1u, model->X_base.size());
	CHECK_EQUAL (1u, model->mBodies.size());
}

TEST_FIXTURE(ModelFixture, TestAddBodyDimensions) {
	Body body;
	Joint joint (
			JointTypeRevolute,
			Vector3d(0., 0., 1.)
			);

	unsigned int body_id = 0;
	body_id = model->AddBody(0, Xtrans(Vector3d(0., 0., 0.)), joint, body); 

	CHECK_EQUAL (1u, body_id);
	CHECK_EQUAL (2u, model->lambda.size());
	CHECK_EQUAL (2u, model->mu.size());
	CHECK_EQUAL (1u, model->dof_count);

	CHECK_EQUAL (2u, model->v.size());
	CHECK_EQUAL (2u, model->a.size());
	
	CHECK_EQUAL (2u, model->mJoints.size());
	CHECK_EQUAL (2u, model->S.size());

	CHECK_EQUAL (2u, model->c.size());
	CHECK_EQUAL (2u, model->IA.size());
	CHECK_EQUAL (2u, model->pA.size());
	CHECK_EQUAL (2u, model->U.size());
	CHECK_EQUAL (2u, model->d.size());
	CHECK_EQUAL (2u, model->u.size());
	CHECK_EQUAL (2u, model->Ic.size());

	SpatialVector spatial_zero;
	spatial_zero.setZero();
	
	CHECK_EQUAL (2u, model->X_lambda.size());
	CHECK_EQUAL (2u, model->X_base.size());
	CHECK_EQUAL (2u, model->mBodies.size());
}

TEST_FIXTURE(ModelFixture, TestFloatingBodyDimensions) {
	Body body;

	model->SetFloatingBaseBody(body);

	CHECK_EQUAL (7u, model->lambda.size());
	CHECK_EQUAL (7u, model->mu.size());
	CHECK_EQUAL (6u, model->dof_count);

	CHECK_EQUAL (7u, model->v.size());
	CHECK_EQUAL (7u, model->a.size());
	
	CHECK_EQUAL (7u, model->mJoints.size());
	CHECK_EQUAL (7u, model->S.size());

	CHECK_EQUAL (7u, model->c.size());
	CHECK_EQUAL (7u, model->IA.size());
	CHECK_EQUAL (7u, model->pA.size());
	CHECK_EQUAL (7u, model->U.size());
	CHECK_EQUAL (7u, model->d.size());
	CHECK_EQUAL (7u, model->u.size());

	SpatialVector spatial_zero;
	spatial_zero.setZero();
	
	CHECK_EQUAL (7u, model->X_lambda.size());
	CHECK_EQUAL (7u, model->X_base.size());
	CHECK_EQUAL (7u, model->mBodies.size());
}

/** \brief Tests whether the joint and body information stored in the Model are computed correctly 
 */
TEST_FIXTURE(ModelFixture, TestAddBodySpatialValues) {
	Body body;
	Joint joint (
		JointTypeRevolute,
		Vector3d(0., 0., 1.)
		);

	model->AddBody(0, Xtrans(Vector3d(0., 0., 0.)), joint, body); 

	SpatialVector spatial_joint_axis(0., 0., 1., 0., 0., 0.);
	CHECK_EQUAL (spatial_joint_axis, joint.mJointAxes[0]);

	// \Todo: Dynamic properties
}

TEST_FIXTURE(ModelFixture, TestAddBodyTestBodyName) {
	Body body;
	Joint joint (
		JointTypeRevolute,
		Vector3d(0., 0., 1.)
		);

	model->AddBody(0, Xtrans(Vector3d(0., 0., 0.)), joint, body, "mybody"); 

	unsigned int body_id = model->GetBodyId("mybody");

	CHECK_EQUAL (1u, body_id);
	CHECK_EQUAL (std::numeric_limits<unsigned int>::max(), model->GetBodyId("unknownbody"));
}

TEST_FIXTURE(ModelFixture, TestjcalcSimple) {
	Body body;
	Joint joint (
		JointTypeRevolute,
		Vector3d(0., 0., 1.)
		);

	model->AddBody(0, Xtrans(Vector3d(1., 0., 0.)), joint, body);

	SpatialTransform X_j;
	SpatialVector S;
	SpatialVector v_j;
	SpatialVector c;

	jcalc (*model, 1, X_j, S, v_j, c, 0., 1.);

	SpatialMatrix test_matrix (
			1.,  0.,  0.,  0.,  0.,  0.,
			0.,  1.,  0.,  0.,  0.,  0.,
			0.,  0.,  1.,  0.,  0.,  0.,
			0.,  0.,  0.,  1.,  0.,  0.,
			0.,  0.,  0.,  0.,  1.,  0.,
			0.,  0.,  0.,  0.,  0.,  1.
			);
	SpatialVector test_vector (
			0., 0., 1., 0., 0., 0.
			);
	SpatialVector test_joint_axis (
			0., 0., 1., 0., 0., 0.
			);

	CHECK (SpatialMatrixCompareEpsilon (test_matrix, X_j.toMatrix(), 1.0e-16));
	CHECK (SpatialVectorCompareEpsilon (test_vector, v_j, 1.0e-16));
	CHECK_EQUAL (test_joint_axis, S);

	jcalc (*model, 1, X_j, S, v_j, c, M_PI * 0.5, 1.);

	test_matrix.set (
			0.,  1.,  0.,  0.,  0.,  0.,
		 -1.,  0.,  0.,  0.,  0.,  0.,
			0.,  0.,  1.,  0.,  0.,  0.,
			0.,  0.,  0.,  0.,  1.,  0.,
			0.,  0.,  0., -1.,  0.,  0.,
			0.,  0.,  0.,  0.,  0.,  1.
			);

	CHECK (SpatialMatrixCompareEpsilon (test_matrix, X_j.toMatrix(), TEST_PREC));
	CHECK (SpatialVectorCompareEpsilon (test_vector, v_j, TEST_PREC));
	CHECK_EQUAL (test_joint_axis, S);
}

TEST_FIXTURE ( ModelFixture, TestTransformBaseToLocal ) {
	Body body;
	unsigned int body_id = model->SetFloatingBaseBody (body);

	VectorNd q = VectorNd::Zero (model->dof_count);
	VectorNd qdot = VectorNd::Zero (model->dof_count);
	VectorNd qddot = VectorNd::Zero (model->dof_count);
	VectorNd tau = VectorNd::Zero (model->dof_count);

	Vector3d base_coords (0., 0., 0.);
	Vector3d body_coords;
	Vector3d base_coords_back;

	UpdateKinematics (*model, q, qdot, qddot);
	body_coords = CalcBaseToBodyCoordinates (*model, q, body_id, base_coords, false);
	base_coords_back = CalcBodyToBaseCoordinates (*model, q, body_id, body_coords, false);

	CHECK_ARRAY_CLOSE (base_coords.data(), base_coords_back.data(), 3, TEST_PREC);

	q[0] = 1.;
	q[1] = 0.2;
	q[2] = -2.3;
	q[3] = -2.3;
	q[4] = 0.03;
	q[5] = -0.23;

	UpdateKinematics (*model, q, qdot, qddot);
	body_coords = CalcBaseToBodyCoordinates (*model, q, body_id, base_coords, false);
	base_coords_back = CalcBodyToBaseCoordinates (*model, q, body_id, body_coords, false);

	CHECK_ARRAY_CLOSE (base_coords.data(), base_coords_back.data(), 3, TEST_PREC);
}

TEST ( Model2DoFJoint ) {
	// the standard modeling using a null body
	Body null_body;
	Body body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));
	Joint joint_rot_z (
			JointTypeRevolute,
			Vector3d(0., 0., 1.)
			);
	Joint joint_rot_x (
			JointTypeRevolute,
			Vector3d(1., 0., 0.)
			);

	Model model_std;
	model_std.gravity = Vector3d (0., -9.81, 0.);

	model_std.AddBody(0, Xtrans(Vector3d(1., 0., 0.)), joint_rot_z, null_body); 
	model_std.AppendBody(Xtrans(Vector3d(0., 0., 0.)), joint_rot_x, body); 

	// using a model with a 2 DoF joint
	Joint joint_rot_zx (
		SpatialVector (0., 0., 1., 0., 0., 0.),
		SpatialVector (1., 0., 0., 0., 0., 0.)
		);

	Model model_2;
	model_2.gravity = Vector3d (0., -9.81, 0.);

	model_2.AddBody(0, Xtrans(Vector3d(1., 0., 0.)), joint_rot_zx, body);

	VectorNd Q = VectorNd::Zero(model_std.dof_count);
	VectorNd QDot = VectorNd::Zero(model_std.dof_count);
	VectorNd Tau = VectorNd::Zero(model_std.dof_count);

	VectorNd QDDot_2 = VectorNd::Zero(model_std.dof_count);
	VectorNd QDDot_std = VectorNd::Zero(model_std.dof_count);

	ForwardDynamics (model_std, Q, QDot, Tau, QDDot_std);
	ForwardDynamics (model_2, Q, QDot, Tau, QDDot_2);

	CHECK_ARRAY_CLOSE (QDDot_std.data(), QDDot_2.data(), model_std.dof_count, TEST_PREC);
}

TEST ( Model3DoFJoint ) {
	// the standard modeling using a null body
	Body null_body;
	Body body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));

	Joint joint_rot_z (
			JointTypeRevolute,
			Vector3d(0., 0., 1.)
			);
	Joint joint_rot_y (
			JointTypeRevolute,
			Vector3d(0., 1., 0.)
			);
	Joint joint_rot_x (
			JointTypeRevolute,
			Vector3d(1., 0., 0.)
			);

	Model model_std;
	model_std.gravity = Vector3d (0., -9.81, 0.);

	unsigned int body_id;

	// in total we add two bodies to make sure that the transformations are
	// correct.
	model_std.AddBody(0, Xtrans(Vector3d(1., 0., 0.)), joint_rot_z, null_body); 
	model_std.AppendBody(Xtrans(Vector3d(0., 0., 0.)), joint_rot_y, null_body); 
	body_id = model_std.AppendBody(Xtrans(Vector3d(0., 0., 0.)), joint_rot_x, body); 

	model_std.AddBody(body_id, Xtrans(Vector3d(1., 0., 0.)), joint_rot_z, null_body); 
	model_std.AppendBody(Xtrans(Vector3d(0., 0., 0.)), joint_rot_y, null_body); 
	body_id = model_std.AppendBody(Xtrans(Vector3d(0., 0., 0.)), joint_rot_x, body); 

	// using a model with a 2 DoF joint
	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.)
		);

	Model model_2;
	model_2.gravity = Vector3d (0., -9.81, 0.);

	// in total we add two bodies to make sure that the transformations are
	// correct.
	body_id = model_2.AddBody(0, Xtrans(Vector3d(1., 0., 0.)), joint_rot_zyx, body);
	body_id = model_2.AddBody(body_id, Xtrans(Vector3d(1., 0., 0.)), joint_rot_zyx, body);

	VectorNd Q = VectorNd::Zero(model_std.dof_count);
	VectorNd QDot = VectorNd::Zero(model_std.dof_count);
	VectorNd Tau = VectorNd::Zero(model_std.dof_count);

	VectorNd QDDot_2 = VectorNd::Zero(model_std.dof_count);
	VectorNd QDDot_std = VectorNd::Zero(model_std.dof_count);

	ForwardDynamics (model_std, Q, QDot, Tau, QDDot_std);
	ForwardDynamics (model_2, Q, QDot, Tau, QDDot_2);

	CHECK_ARRAY_CLOSE (QDDot_std.data(), QDDot_2.data(), model_std.dof_count, TEST_PREC);
}

TEST ( Model6DoFJoint ) {
	// the standard modeling using a null body
	Body null_body;
	Body body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));

	Joint joint_rot_z (
			JointTypeRevolute,
			Vector3d(0., 0., 1.)
			);
	Joint joint_rot_y (
			JointTypeRevolute,
			Vector3d(0., 1., 0.)
			);
	Joint joint_rot_x (
			JointTypeRevolute,
			Vector3d(1., 0., 0.)
			);

	Model model_std;
	model_std.gravity = Vector3d (0., -9.81, 0.);

	unsigned int body_id;

	// in total we add two bodies to make sure that the transformations are
	// correct.
	body_id = model_std.SetFloatingBaseBody (body);

	model_std.AddBody(body_id, Xtrans(Vector3d(1., 0., 0.)), joint_rot_z, null_body); 
	model_std.AppendBody(Xtrans(Vector3d(0., 0., 0.)), joint_rot_y, null_body); 
	body_id = model_std.AppendBody(Xtrans(Vector3d(0., 0., 0.)), joint_rot_x, body); 

	// using a model with a 2 DoF joint
	Joint joint_floating_base (
		SpatialVector (0., 0., 0., 1., 0., 0.),
		SpatialVector (0., 0., 0., 0., 1., 0.),
		SpatialVector (0., 0., 0., 0., 0., 1.),
		SpatialVector (0., 0., 1., 0., 0., 0.),
		SpatialVector (0., 1., 0., 0., 0., 0.),
		SpatialVector (1., 0., 0., 0., 0., 0.)
		);

	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.)
		);

	Model model_2;
	model_2.gravity = Vector3d (0., -9.81, 0.);

	// in total we add two bodies to make sure that the transformations are
	// correct.
	body_id = model_2.AddBody(0, Xtrans(Vector3d(1., 0., 0.)), joint_floating_base, body);
	body_id = model_2.AddBody(body_id, Xtrans(Vector3d(1., 0., 0.)), joint_rot_zyx, body);

	VectorNd Q = VectorNd::Zero(model_std.dof_count);
	VectorNd QDot = VectorNd::Zero(model_std.dof_count);
	VectorNd Tau = VectorNd::Zero(model_std.dof_count);

	VectorNd QDDot_2 = VectorNd::Zero(model_std.dof_count);
	VectorNd QDDot_std = VectorNd::Zero(model_std.dof_count);

	ForwardDynamics (model_std, Q, QDot, Tau, QDDot_std);
	ForwardDynamics (model_2, Q, QDot, Tau, QDDot_2);

	CHECK_ARRAY_CLOSE (QDDot_std.data(), QDDot_2.data(), model_std.dof_count, TEST_PREC);
}

TEST ( ModelFixedJointQueryBodyId ) {
	// the standard modeling using a null body
	Body null_body;
	Body body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));
	Body fixed_body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));

	Model model;

	Joint joint_rot_z (
			JointTypeRevolute,
			Vector3d(0., 0., 1.)
			);
	model.AddBody (0, Xtrans(Vector3d(0., 0., 0.)), joint_rot_z, body);
	unsigned int fixed_body_id = model.AppendBody (Xtrans(Vector3d(0., 1., 0.)), Joint(JointTypeFixed), fixed_body, "fixed_body");

	CHECK_EQUAL (fixed_body_id, model.GetBodyId("fixed_body"));
}

/* 
 * Makes sure that when appending a body to a fixed joint the parent of the
 * newly added parent is actually the moving body that the fixed body is
 * attached to.
 */
TEST ( ModelAppendToFixedBody ) {
	Body null_body;
	Body body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));
	Body fixed_body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));

	Model model;

	Joint joint_rot_z (
			JointTypeRevolute,
			Vector3d(0., 0., 1.)
			);
	unsigned int movable_body = model.AddBody (0, Xtrans(Vector3d(0., 0., 0.)), joint_rot_z, body);
	unsigned int fixed_body_id = model.AppendBody (Xtrans(Vector3d(0., 1., 0.)), Joint(JointTypeFixed), fixed_body, "fixed_body");
	unsigned int appended_body_id = model.AppendBody (Xtrans(Vector3d(0., 1., 0.)), joint_rot_z, body, "appended_body");

	CHECK_EQUAL (movable_body + 1, appended_body_id);
	CHECK_EQUAL (movable_body, model.lambda[appended_body_id]);
}

// Adds a fixed body to another fixed body.
TEST ( ModelAppendFixedToFixedBody ) {
	Body null_body;

	double movable_mass = 1.1;
	Vector3d movable_com (1., 0.4, 0.4);

	double fixed_mass = 1.2;
	Vector3d fixed_com (1.1, 0.5, 0.5);

	Vector3d fixed_displacement (0., 1., 0.);

	Body body(movable_mass, movable_com, Vector3d (1., 1., 1.));
	Body fixed_body(fixed_mass, fixed_com, Vector3d (1., 1., 1.));

	Model model;

	Joint joint_rot_z (
			JointTypeRevolute,
			Vector3d(0., 0., 1.)
			);
	unsigned int movable_body = model.AddBody (0, Xtrans(Vector3d(0., 0., 0.)), joint_rot_z, body);
	unsigned int fixed_body_id = model.AppendBody (Xtrans(fixed_displacement), Joint(JointTypeFixed), fixed_body, "fixed_body");
	unsigned int fixed_body_2_id = model.AppendBody (Xtrans(fixed_displacement), Joint(JointTypeFixed), fixed_body, "fixed_body_2");
	unsigned int appended_body_id = model.AppendBody (Xtrans(Vector3d(0., 1., 0.)), joint_rot_z, body, "appended_body");

	CHECK_EQUAL (movable_body + 1, appended_body_id);
	CHECK_EQUAL (movable_body, model.lambda[appended_body_id]);
	CHECK_EQUAL (movable_mass + fixed_mass * 2., model.mBodies[movable_body].mMass);

	CHECK_EQUAL (movable_body, model.mFixedBodies[fixed_body_id - model.fixed_body_discriminator].mMovableParent);
	CHECK_EQUAL (movable_body, model.mFixedBodies[fixed_body_2_id - model.fixed_body_discriminator].mMovableParent);

	double new_mass = 3.5;
	Vector3d new_com = (1. / new_mass) * (movable_mass * movable_com + fixed_mass * (fixed_com + fixed_displacement) + fixed_mass * (fixed_com + fixed_displacement * 2.));

	CHECK_ARRAY_EQUAL (new_com.data(), model.mBodies[movable_body].mCenterOfMass.data(), 3);
}

// Ensures that the transformations of the movable parent and fixed joint
// frame is in proper order
TEST ( ModelFixedJointRotationOrderTranslationRotation ) {
	// the standard modeling using a null body
	Body null_body;
	Body body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));
	Body fixed_body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));

	Model model;

	Joint joint_rot_z (
			JointTypeRevolute,
			Vector3d(0., 0., 1.)
			);

	SpatialTransform trans_x = Xtrans (Vector3d (1., 0., 0.));
	SpatialTransform rot_z = Xrotz (45. * M_PI / 180.);

	model.AddBody (0, trans_x, joint_rot_z, body);
	unsigned int fixed_body_id = model.AppendBody (rot_z, Joint(JointTypeFixed), fixed_body, "fixed_body");
	unsigned int body_after_fixed = model.AppendBody (trans_x, joint_rot_z, body);

	VectorNd Q (VectorNd::Zero(model.dof_count));
	Q[0] = 45 * M_PI / 180.;
	Vector3d point = CalcBodyToBaseCoordinates (model, Q, body_after_fixed, Vector3d (0., 1., 0.));

	CHECK_ARRAY_CLOSE (Vector3d (0., 1., 0.).data(), point.data(), 3, TEST_PREC);
}

// Ensures that the transformations of the movable parent and fixed joint
// frame is in proper order
TEST ( ModelFixedJointRotationOrderRotationTranslation ) {
	// the standard modeling using a null body
	Body null_body;
	Body body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));
	Body fixed_body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));

	Model model;

	Joint joint_rot_z (
			JointTypeRevolute,
			Vector3d(0., 0., 1.)
			);

	SpatialTransform rot_z = Xrotz (45. * M_PI / 180.);
	SpatialTransform trans_x = Xtrans (Vector3d (1., 0., 0.));

	model.AddBody (0, rot_z, joint_rot_z, body);
	unsigned int fixed_body_id = model.AppendBody (trans_x, Joint(JointTypeFixed), fixed_body, "fixed_body");
	unsigned int body_after_fixed = model.AppendBody (trans_x, joint_rot_z, body);

	VectorNd Q (VectorNd::Zero(model.dof_count));
	Q[0] = 45 * M_PI / 180.;
	Vector3d point = CalcBodyToBaseCoordinates (model, Q, body_after_fixed, Vector3d (0., 1., 0.));

	CHECK_ARRAY_CLOSE (Vector3d (-1., 2., 0.).data(), point.data(), 3, TEST_PREC);
}

TEST ( ModelGetBodyName ) {
	Body null_body;
	Body body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));
	Body fixed_body(1., Vector3d (1., 0.4, 0.4), Vector3d (1., 1., 1.));

	Model model;

	Joint joint_rot_z (
			JointTypeRevolute,
			Vector3d(0., 0., 1.)
			);
	unsigned int movable_body = model.AddBody (0, Xtrans(Vector3d(0., 0., 0.)), joint_rot_z, body);
	unsigned int fixed_body_id = model.AppendBody (Xtrans(Vector3d(0., 1., 0.)), Joint(JointTypeFixed), fixed_body, "fixed_body");
	unsigned int appended_body_id = model.AppendBody (Xtrans(Vector3d(0., 1., 0.)), joint_rot_z, body, "appended_body");

	CHECK_EQUAL (string("fixed_body"), model.GetBodyName(fixed_body_id));
	CHECK_EQUAL (string("appended_body"), model.GetBodyName(appended_body_id));
	CHECK_EQUAL (string(""), model.GetBodyName(123));
}