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


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:06