bindings_model.py
Go to the documentation of this file.
1 import unittest
2 import pinocchio as pin
3 from pinocchio.utils import np, zero
4 
5 from test_case import PinocchioTestCase as TestCase
6 
7 
8 class TestModel(TestCase):
9  def setUp(self):
10  self.model = pin.buildSampleModelHumanoidRandom()
11 
13  model = pin.Model()
14  self.assertEqual(model.nbodies, 1)
15  self.assertEqual(model.nq, 0)
16  self.assertEqual(model.nv, 0)
17  model.name = "empty_model"
18 
19  def test_add_joint(self):
20  model = pin.Model()
21  idx = 0
22  idx = model.addJoint(idx, pin.JointModelRY(), pin.SE3.Identity(), 'joint_'+str(idx+1))
23 
24  MAX_EFF = 100.
25  MAX_VEL = 10.
26  MIN_POS = -1.
27  MAX_POS = 1.
28 
29  me = np.array([MAX_EFF])
30  mv = np.array([MAX_VEL])
31  lb = np.array([MIN_POS])
32  ub = np.array([MAX_POS])
33  idx = model.addJoint(idx, pin.JointModelRY(), pin.SE3.Identity(), 'joint_'+str(idx+1),me,mv,lb,ub)
34 
35  self.assertEqual(model.nbodies, 1)
36  self.assertEqual(model.njoints, 3)
37  self.assertEqual(model.nq, 2)
38  self.assertEqual(model.nv, 2)
39 
40  self.assertEqual(float(model.effortLimit[1]), MAX_EFF)
41  self.assertEqual(float(model.velocityLimit[1]), MAX_VEL)
42  self.assertEqual(float(model.lowerPositionLimit[1]), MIN_POS)
43  self.assertEqual(float(model.upperPositionLimit[1]), MAX_POS)
44 
45  def test_model(self):
46  model = self.model
47  nb = 28 # We should have 28 bodies, thus 27 joints, one of them a free-flyer.
48  self.assertEqual(model.nbodies, nb)
49  self.assertEqual(model.nq, nb - 1 + 6)
50  self.assertEqual(model.nv, nb - 1 + 5)
51 
52  def test_inertias(self):
53  model = self.model
54  model.inertias[1] = model.inertias[2]
55  self.assertApprox(model.inertias[1].np, model.inertias[2].np)
56 
57  def test_placements(self):
58  model = self.model
59  model.jointPlacements[1] = model.jointPlacements[2]
60  self.assertApprox(model.jointPlacements[1].np, model.jointPlacements[2].np)
61  self.assertEqual(model.parents[0], 0)
62  self.assertEqual(model.parents[1], 0)
63  model.parents[2] = model.parents[1]
64  self.assertEqual(model.parents[2], model.parents[1])
65  self.assertEqual(model.names[0], "universe")
66 
67  def test_gravity(self):
68  self.assertApprox(self.model.gravity.np, np.array([0, 0, -9.81, 0, 0, 0]).T)
69 
70  def test_rnea(self):
71  model = self.model
72  data = model.createData()
73 
74  q = zero(model.nq)
75  qdot = zero(model.nv)
76  qddot = zero(model.nv)
77  for i in range(model.nbodies):
78  data.a[i] = pin.Motion.Zero()
79 
80  pin.rnea(model, data, q, qdot, qddot)
81  for i in range(model.nbodies):
82  self.assertApprox(data.v[i].np, zero(6))
83  self.assertApprox(data.a_gf[0].np, -model.gravity.np)
84  self.assertApprox(data.f[-1], model.inertias[-1] * data.a_gf[-1])
85 
87  model = self.model
88  model.referenceConfigurations["neutral"] = pin.neutral(model)
89  q_neutral = model.referenceConfigurations["neutral"]
90 
91  q_neutral.fill(1.)
92  self.assertApprox(model.referenceConfigurations["neutral"],q_neutral)
93 
94  def test_pickle(self):
95  import pickle
96 
97  model = self.model
98  filename = "model.pickle"
99  with open(filename, 'wb') as f:
100  pickle.dump(model,f)
101 
102  with open(filename, 'rb') as f:
103  model_copy = pickle.load(f)
104 
105  self.assertTrue(model == model_copy)
106 
107 if __name__ == '__main__':
108  unittest.main()


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:28