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


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