4 import pinocchio
as pin
6 from test_case
import PinocchioTestCase
as TestCase
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))
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))
24 Y = pin.Inertia.Identity()
26 self.assertFalse(Y.mass == 1)
27 self.assertFalse(np.allclose(
zero(3), Y.lever))
28 self.assertFalse(np.allclose(
eye(3), Y.inertia))
31 Y = pin.Inertia.Zero()
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))
39 Y = pin.Inertia.Zero()
41 self.assertTrue(Y.mass == 1)
42 self.assertTrue(np.allclose(
zero(3), Y.lever))
43 self.assertTrue(np.allclose(
eye(3), Y.inertia))
46 Y = pin.Inertia.Zero()
48 self.assertTrue(np.allclose(Y.mass, 10))
51 Y = pin.Inertia.Zero()
54 self.assertTrue(np.allclose(Y.lever, lev))
57 Y = pin.Inertia.Zero()
59 iner = (iner + iner.T) / 2.0
61 self.assertTrue(np.allclose(Y.inertia, iner))
64 Y1 = pin.Inertia.Random()
65 Y2 = pin.Inertia.Random()
67 self.assertTrue(np.allclose(Y1.matrix() + Y2.matrix(), Y.matrix()))
71 Y = pin.Inertia.Random()
72 v = pin.Motion.Random()
73 self.assertTrue(np.allclose((Y * v).vector, Y.matrix().dot(v.vector)))
77 m.inverse().action.T.dot(Y.matrix()).dot(m.inverse().action),
83 m.inverse().action.T.dot(Y.matrix()).dot(m.inverse().action),
88 (m.actInv(Y)).matrix(), m.action.T.dot(Y.matrix()).dot(m.action)
93 In = pin.Inertia.Random()
95 v = In.toDynamicParameters()
97 self.assertApprox(v[0], In.mass)
98 self.assertApprox(v[1:4], In.mass * In.lever)
100 I_o = In.inertia + In.mass * pin.skew(In.lever).transpose().dot(
105 [float(v[4]), float(v[5]), float(v[7])],
106 [float(v[5]), float(v[6]), float(v[8])],
107 [float(v[7]), float(v[8]), float(v[9])],
111 self.assertApprox(I_o, I_ov)
113 I2 = pin.Inertia.FromDynamicParameters(v)
114 self.assertApprox(I2, In)
118 with self.assertRaises(ValueError):
119 pin.Inertia.FromDynamicParameters(np.array([]))
122 In = pin.Inertia.Random()
124 pseudo = In.toPseudoInertia()
127 self.assertApprox(pseudo.mass, In.mass)
128 self.assertApprox(pseudo.h, In.mass * In.lever)
129 self.assertEqual(pseudo.sigma.shape, (3, 3))
132 _ = pseudo.toMatrix()
135 params = pseudo.toDynamicParameters()
138 pseudo2 = pin.PseudoInertia.FromDynamicParameters(params)
139 self.assertApprox(pseudo.mass, pseudo2.mass)
140 self.assertApprox(pseudo.h, pseudo2.h)
141 self.assertApprox(pseudo.sigma, pseudo2.sigma)
145 with self.assertRaises(ValueError):
146 pin.PseudoInertia.FromDynamicParameters(np.array([]))
149 pseudo3 = pin.PseudoInertia.FromMatrix(pseudo.toMatrix())
150 self.assertApprox(pseudo.mass, pseudo3.mass)
151 self.assertApprox(pseudo.h, pseudo3.h)
152 self.assertApprox(pseudo.sigma, pseudo3.sigma)
155 pseudo4 = pin.PseudoInertia.FromInertia(In)
156 self.assertApprox(pseudo.mass, pseudo4.mass)
157 self.assertApprox(pseudo.h, pseudo4.h)
158 self.assertApprox(pseudo.sigma, pseudo4.sigma)
161 self.assertApprox(pseudo4.toInertia(), In)
164 pin.PseudoInertia(pseudo)
167 pseudo_array = np.array(pseudo)
168 self.assertApprox(pseudo_array, pseudo.toMatrix())
171 log_cholesky = pin.LogCholeskyParameters(np.random.randn(10))
172 In = pin.Inertia.FromLogCholeskyParameters(log_cholesky)
175 with self.assertRaises(ValueError):
176 log_cholesky = pin.LogCholeskyParameters(np.array([]))
179 self.assertEqual(log_cholesky.parameters.shape, (10,))
182 params = log_cholesky.toDynamicParameters()
183 params2 = In.toDynamicParameters()
184 self.assertApprox(params, params2)
187 pseudo = log_cholesky.toPseudoInertia()
188 pseudo2 = In.toPseudoInertia()
189 self.assertApprox(pseudo.mass, pseudo2.mass)
190 self.assertApprox(pseudo.h, pseudo2.h)
191 self.assertApprox(pseudo.sigma, pseudo2.sigma)
194 In2 = log_cholesky.toInertia()
195 self.assertApprox(In, In2)
198 log_cholesky.calculateJacobian()
201 log_cholesky_array = np.array(log_cholesky)
202 self.assertApprox(log_cholesky_array, log_cholesky.parameters)
205 In = pin.Inertia.Random()
206 I_array = np.array(In)
208 self.assertApprox(I_array, In.matrix())
211 for _
in range(100000):
212 In = pin.Inertia.Random() + pin.Inertia.Random()
214 self.assertTrue(s !=
"")
217 if __name__ ==
"__main__":