bindings_force.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 TestForceBindings(unittest.TestCase):
9  def test_zero_getters(self):
10  f = pin.Force.Zero()
11  self.assertTrue(np.allclose(zero(3), f.linear))
12  self.assertTrue(np.allclose(zero(3), f.angular))
13  self.assertTrue(np.allclose(zero(6), f.vector))
14 
15  # TODO: this is not nice, since a random vector can *in theory* be zero
16  def test_setRandom(self):
17  f = pin.Force.Zero()
18  f.setRandom()
19  self.assertFalse(np.allclose(zero(3), f.linear))
20  self.assertFalse(np.allclose(zero(3), f.angular))
21  self.assertFalse(np.allclose(zero(6), f.vector))
22 
23  def test_setZero(self):
24  f = pin.Force.Zero()
25  f.setRandom()
26  f.setZero()
27  self.assertTrue(np.allclose(zero(3), f.linear))
28  self.assertTrue(np.allclose(zero(3), f.angular))
29  self.assertTrue(np.allclose(zero(6), f.vector))
30 
31  def test_set_linear(self):
32  f = pin.Force.Zero()
33  lin = rand(3)
34  f.linear = lin
35  self.assertTrue(np.allclose(f.linear, lin))
36 
37  f.linear[1] = 1.0
38  self.assertTrue(f.linear[1] == 1.0)
39 
40  def test_set_angular(self):
41  f = pin.Force.Zero()
42  ang = rand(3)
43  f.angular = ang
44  self.assertTrue(np.allclose(f.angular, ang))
45 
46  f.angular[1] = 1.0
47  self.assertTrue(f.angular[1] == 1.0)
48 
49  def test_set_vector(self):
50  f = pin.Force.Zero()
51  vec = rand(6)
52  f.vector = vec
53  self.assertTrue(np.allclose(f.vector, vec))
54 
55  def test_internal_sums(self):
56  f1 = pin.Force.Random()
57  f2 = pin.Force.Random()
58  self.assertTrue(np.allclose((f1 + f2).vector, f1.vector + f2.vector))
59  self.assertTrue(np.allclose((f1 - f2).vector, f1.vector - f2.vector))
60 
61  def test_se3_action(self):
62  f = pin.Force.Random()
63  m = pin.SE3.Random()
64  self.assertTrue(
65  np.allclose((m * f).vector, np.linalg.inv(m.action.T).dot(f.vector))
66  )
67  self.assertTrue(
68  np.allclose(m.act(f).vector, np.linalg.inv(m.action.T).dot(f.vector))
69  )
70  self.assertTrue(np.allclose((m.actInv(f)).vector, m.action.T.dot(f.vector)))
71  v = pin.Motion(np.concatenate([f.vector[3:], f.vector[:3]]))
72  self.assertTrue(np.allclose((v ^ f).vector, zero(6)))
73 
74  def test_conversion(self):
75  f = pin.Force.Random()
76  f_array = np.array(f)
77 
78  f_from_array = pin.Force(f_array)
79 
80  self.assertTrue(f_from_array == f)
81 
82  def test_several_init(self):
83  for _ in range(100000):
84  f = pin.Force.Zero() + pin.Force.Zero()
85  self.assertTrue(np.allclose(f.vector, zero(6)))
86 
87 
88 if __name__ == "__main__":
89  unittest.main()
bindings_force.TestForceBindings
Definition: bindings_force.py:8
bindings_force.TestForceBindings.test_set_vector
def test_set_vector(self)
Definition: bindings_force.py:49
bindings_force.TestForceBindings.test_internal_sums
def test_internal_sums(self)
Definition: bindings_force.py:55
bindings_force.TestForceBindings.test_conversion
def test_conversion(self)
Definition: bindings_force.py:74
bindings_force.TestForceBindings.test_setZero
def test_setZero(self)
Definition: bindings_force.py:23
bindings_force.TestForceBindings.test_set_linear
def test_set_linear(self)
Definition: bindings_force.py:31
pinocchio.utils
Definition: bindings/python/pinocchio/utils.py:1
bindings_force.TestForceBindings.test_zero_getters
def test_zero_getters(self)
Definition: bindings_force.py:9
bindings_force.TestForceBindings.test_several_init
def test_several_init(self)
Definition: bindings_force.py:82
bindings_force.TestForceBindings.test_se3_action
def test_se3_action(self)
Definition: bindings_force.py:61
bindings_force.TestForceBindings.test_set_angular
def test_set_angular(self)
Definition: bindings_force.py:40
bindings_force.TestForceBindings.test_setRandom
def test_setRandom(self)
Definition: bindings_force.py:16
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 Thu Dec 19 2024 03:41:25