bindings_motion.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 zero,rand
5 
6 class TestMotionBindings(unittest.TestCase):
7 
8  def test_zero_getters(self):
9  v = pin.Motion.Zero()
10  self.assertTrue(np.allclose(zero(3), v.linear))
11  self.assertTrue(np.allclose(zero(3), v.angular))
12  self.assertTrue(np.allclose(zero(6), v.vector))
13 
14  # TODO: this is not nice, since a random vector can *in theory* be zero
15  def test_setRandom(self):
16  v = pin.Motion.Zero()
17  v.setRandom()
18  self.assertFalse(np.allclose(zero(3), v.linear))
19  self.assertFalse(np.allclose(zero(3), v.angular))
20  self.assertFalse(np.allclose(zero(6), v.vector))
21 
22  def test_setZero(self):
23  v = pin.Motion.Zero()
24  v.setRandom()
25  v.setZero()
26  self.assertTrue(np.allclose(zero(3), v.linear))
27  self.assertTrue(np.allclose(zero(3), v.angular))
28  self.assertTrue(np.allclose(zero(6), v.vector))
29 
30  def test_set_linear(self):
31  v = pin.Motion.Zero()
32  lin = rand(3)
33  v.linear = lin
34  self.assertTrue(np.allclose(v.linear, lin))
35 
36  v.linear[1] = 1.
37  self.assertTrue(v.linear[1] == 1.)
38 
39  def test_set_angular(self):
40  v = pin.Motion.Zero()
41  ang = rand(3)
42  v.angular = ang
43  self.assertTrue(np.allclose(v.angular, ang))
44 
45  v.angular[1] = 1.
46  self.assertTrue(v.angular[1] == 1.)
47 
48  def test_set_vector(self):
49  v = pin.Motion.Zero()
50  vec = rand(6)
51  v.vector = vec
52  self.assertTrue(np.allclose(v.vector, vec))
53 
54  def test_internal_sums(self):
55  v1 = pin.Motion.Random()
56  v2 = pin.Motion.Random()
57  self.assertTrue(np.allclose((v1+v2).vector,v1.vector + v2.vector))
58  self.assertTrue(np.allclose((v1 - v2).vector, v1.vector - v2.vector))
59 
60  def test_se3_action(self):
61  m = pin.SE3.Random()
62  v = pin.Motion.Random()
63  self.assertTrue(np.allclose((m * v).vector, m.action.dot(v.vector)))
64  self.assertTrue(np.allclose(m.act(v).vector, m.action.dot(v.vector)))
65  self.assertTrue(np.allclose((m.actInv(v)).vector, np.linalg.inv(m.action).dot(v.vector)))
66  self.assertTrue(np.allclose((v ^ v).vector, zero(6)))
67 
68  def test_conversion(self):
69 
70  m = pin.Motion.Random()
71  m_array = np.array(m)
72 
73  m_from_array = pin.Motion(m_array)
74 
75  self.assertTrue(m_from_array == m)
76 
77 if __name__ == '__main__':
78  unittest.main()


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:02