bindings_motion.py
Go to the documentation of this file.
1 import unittest
2 
3 import numpy as np
4 import pinocchio as pin
5 from pinocchio.utils import rand, zero
6 
7 
8 class TestMotionBindings(unittest.TestCase):
9  def test_zero_getters(self):
10  v = pin.Motion.Zero()
11  self.assertTrue(np.allclose(zero(3), v.linear))
12  self.assertTrue(np.allclose(zero(3), v.angular))
13  self.assertTrue(np.allclose(zero(6), v.vector))
14 
15  # TODO: this is not nice, since a random vector can *in theory* be zero
16  def test_setRandom(self):
17  v = pin.Motion.Zero()
18  v.setRandom()
19  self.assertFalse(np.allclose(zero(3), v.linear))
20  self.assertFalse(np.allclose(zero(3), v.angular))
21  self.assertFalse(np.allclose(zero(6), v.vector))
22 
23  def test_setZero(self):
24  v = pin.Motion.Zero()
25  v.setRandom()
26  v.setZero()
27  self.assertTrue(np.allclose(zero(3), v.linear))
28  self.assertTrue(np.allclose(zero(3), v.angular))
29  self.assertTrue(np.allclose(zero(6), v.vector))
30 
31  def test_set_linear(self):
32  v = pin.Motion.Zero()
33  lin = rand(3)
34  v.linear = lin
35  self.assertTrue(np.allclose(v.linear, lin))
36 
37  v.linear[1] = 1.0
38  self.assertTrue(v.linear[1] == 1.0)
39 
40  def test_set_angular(self):
41  v = pin.Motion.Zero()
42  ang = rand(3)
43  v.angular = ang
44  self.assertTrue(np.allclose(v.angular, ang))
45 
46  v.angular[1] = 1.0
47  self.assertTrue(v.angular[1] == 1.0)
48 
49  def test_set_vector(self):
50  v = pin.Motion.Zero()
51  vec = rand(6)
52  v.vector = vec
53  self.assertTrue(np.allclose(v.vector, vec))
54 
55  def test_internal_sums(self):
56  v1 = pin.Motion.Random()
57  v2 = pin.Motion.Random()
58  self.assertTrue(np.allclose((v1 + v2).vector, v1.vector + v2.vector))
59  self.assertTrue(np.allclose((v1 - v2).vector, v1.vector - v2.vector))
60 
61  def test_se3_action(self):
62  m = pin.SE3.Random()
63  v = pin.Motion.Random()
64  self.assertTrue(np.allclose((m * v).vector, m.action.dot(v.vector)))
65  self.assertTrue(np.allclose(m.act(v).vector, m.action.dot(v.vector)))
66  self.assertTrue(
67  np.allclose((m.actInv(v)).vector, np.linalg.inv(m.action).dot(v.vector))
68  )
69  self.assertTrue(np.allclose((v ^ v).vector, zero(6)))
70 
71  def test_conversion(self):
72  m = pin.Motion.Random()
73  m_array = np.array(m)
74 
75  m_from_array = pin.Motion(m_array)
76 
77  self.assertTrue(m_from_array == m)
78 
79  def test_several_init(self):
80  for _ in range(100000):
81  v = pin.Motion.Zero() + pin.Motion.Zero()
82  self.assertTrue(np.allclose(v.vector, zero(6)))
83 
84 
85 if __name__ == "__main__":
86  unittest.main()
bindings_motion.TestMotionBindings.test_se3_action
def test_se3_action(self)
Definition: bindings_motion.py:61
bindings_motion.TestMotionBindings.test_set_linear
def test_set_linear(self)
Definition: bindings_motion.py:31
bindings_motion.TestMotionBindings.test_setZero
def test_setZero(self)
Definition: bindings_motion.py:23
bindings_motion.TestMotionBindings.test_several_init
def test_several_init(self)
Definition: bindings_motion.py:79
bindings_motion.TestMotionBindings.test_setRandom
def test_setRandom(self)
Definition: bindings_motion.py:16
bindings_motion.TestMotionBindings.test_set_vector
def test_set_vector(self)
Definition: bindings_motion.py:49
pinocchio.utils
Definition: bindings/python/pinocchio/utils.py:1
bindings_motion.TestMotionBindings.test_set_angular
def test_set_angular(self)
Definition: bindings_motion.py:40
bindings_motion.TestMotionBindings.test_conversion
def test_conversion(self)
Definition: bindings_motion.py:71
bindings_motion.TestMotionBindings.test_internal_sums
def test_internal_sums(self)
Definition: bindings_motion.py:55
bindings_motion.TestMotionBindings.test_zero_getters
def test_zero_getters(self)
Definition: bindings_motion.py:9
bindings_motion.TestMotionBindings
Definition: bindings_motion.py:8
pinocchio.utils.rand
def rand(n)
Definition: bindings/python/pinocchio/utils.py:41
pinocchio.utils.zero
def zero(n)
Definition: bindings/python/pinocchio/utils.py:37


pinocchio
Author(s):
autogenerated on Tue Jan 7 2025 03:41:40