bindings_inertia.py
Go to the documentation of this file.
1 import unittest
2 import pinocchio as pin
3 import numpy as np
4 from pinocchio.utils import eye,zero,rand
5 
6 from test_case import PinocchioTestCase as TestCase
7 
8 class TestInertiaBindings(TestCase):
9 
10  def test_zero_getters(self):
11  Y = pin.Inertia.Zero()
12  self.assertTrue(Y.mass == 0)
13  self.assertTrue(np.allclose(zero(3), Y.lever))
14  self.assertTrue(np.allclose(zero([3,3]), Y.inertia))
15 
17  Y = pin.Inertia.Identity()
18  self.assertTrue(Y.mass == 1)
19  self.assertTrue(np.allclose(zero(3), Y.lever))
20  self.assertTrue(np.allclose(eye(3), Y.inertia))
21 
22  # TODO: this is not nice, since a random matrix can *in theory* be unity
23  def test_setRandom(self):
24  Y = pin.Inertia.Identity()
25  Y.setRandom()
26  self.assertFalse(Y.mass == 1)
27  self.assertFalse(np.allclose(zero(3), Y.lever))
28  self.assertFalse(np.allclose(eye(3), Y.inertia))
29 
30  def test_setZero(self):
31  Y = pin.Inertia.Zero()
32  Y.setRandom()
33  Y.setZero()
34  self.assertTrue(Y.mass == 0)
35  self.assertTrue(np.allclose(zero(3), Y.lever))
36  self.assertTrue(np.allclose(zero([3,3]), Y.inertia))
37 
38  def test_setIdentity(self):
39  Y = pin.Inertia.Zero()
40  Y.setIdentity()
41  self.assertTrue(Y.mass == 1)
42  self.assertTrue(np.allclose(zero(3), Y.lever))
43  self.assertTrue(np.allclose(eye(3), Y.inertia))
44 
45  def test_set_mass(self):
46  Y = pin.Inertia.Zero()
47  Y.mass = 10
48  self.assertTrue(np.allclose(Y.mass, 10))
49 
50  def test_set_lever(self):
51  Y = pin.Inertia.Zero()
52  lev = rand(3)
53  Y.lever = lev
54  self.assertTrue(np.allclose(Y.lever, lev))
55 
56  def test_set_inertia(self):
57  Y = pin.Inertia.Zero()
58  iner = rand([3,3])
59  iner = (iner + iner.T) / 2. # Symmetrize the matrix
60  Y.inertia = iner
61  self.assertTrue(np.allclose(Y.inertia, iner))
62 
63  def test_internal_sums(self):
64  Y1 = pin.Inertia.Random()
65  Y2 = pin.Inertia.Random()
66  Y = Y1 + Y2
67  self.assertTrue(np.allclose(Y1.matrix() + Y2.matrix(), Y.matrix()))
68 
69  def test_se3_action(self):
70  m = pin.SE3.Random()
71  Y = pin.Inertia.Random()
72  v = pin.Motion.Random()
73  self.assertTrue(np.allclose((Y * v).vector, Y.matrix().dot(v.vector)))
74  self.assertTrue(np.allclose((m * Y).matrix(), m.inverse().action.T.dot(Y.matrix()).dot(m.inverse().action)))
75  self.assertTrue(np.allclose(m.act(Y).matrix(), m.inverse().action.T.dot(Y.matrix()).dot(m.inverse().action)))
76  self.assertTrue(np.allclose((m.actInv(Y)).matrix(), m.action.T.dot(Y.matrix()).dot(m.action)))
77 
79  I = pin.Inertia.Random()
80 
81  v = I.toDynamicParameters()
82 
83  self.assertApprox(v[0], I.mass)
84  self.assertApprox(v[1:4], I.mass * I.lever)
85 
86  I_o = I.inertia + I.mass * pin.skew(I.lever).transpose().dot(pin.skew(I.lever))
87  I_ov = np.array(
88  [[float(v[4]), float(v[5]), float(v[7])],
89  [float(v[5]), float(v[6]), float(v[8])],
90  [float(v[7]), float(v[8]), float(v[9])]
91  ]
92  )
93 
94  self.assertApprox(I_o, I_ov)
95 
96  I2 = pin.Inertia.FromDynamicParameters(v)
97  self.assertApprox(I2, I)
98 
99  def test_array(self):
100  I = pin.Inertia.Random()
101  I_array = np.array(I)
102 
103  self.assertApprox(I_array,I.matrix())
104 
105  def test_several_init(self):
106  for _ in range(100000):
107  i = pin.Inertia.Random() + pin.Inertia.Random()
108  s = i.__str__()
109  self.assertTrue(s != '')
110 
111 if __name__ == '__main__':
112  unittest.main()


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