bindings.py
Go to the documentation of this file.
1 import unittest
2 import pinocchio as pin
3 from pinocchio.utils import np, npl, rand, zero
4 
5 from test_case import PinocchioTestCase as TestCase
6 
7 # This whole file seems to be outdated and superseded by more recent tests
8 # Probably it should be removed and its contents moved or split somewhere else
9 
10 class TestSE3(TestCase):
11  def setUp(self):
12  self.R = rand([3, 3])
13  self.R, _, _ = npl.svd(self.R)
14  self.p = rand(3)
15  self.m = pin.SE3(self.R, self.p)
16 
17  def test_se3(self):
18  R, p, m = self.R, self.p, self.m
19  X = np.vstack([np.hstack([R, pin.skew(p).dot(R)]), np.hstack([zero([3, 3]), R])])
20  self.assertApprox(m.action, X)
21  M = np.vstack([np.hstack([R, np.expand_dims(p,1)]), np.array([[0., 0., 0., 1.]])])
22  self.assertApprox(m.homogeneous, M)
23  m2 = pin.SE3.Random()
24  self.assertApprox((m * m2).homogeneous, m.homogeneous.dot(m2.homogeneous))
25  self.assertApprox((~m).homogeneous, npl.inv(m.homogeneous))
26 
27  p = rand(3)
28  self.assertApprox(m * p, m.rotation.dot(p) + m.translation)
29  self.assertApprox(m.actInv(p), m.rotation.T.dot(p) - m.rotation.T.dot(m.translation))
30 
31  # Currently, the different cases do not throw the same exception type.
32  # To have a more robust test, only Exception is checked.
33  # In the comments, the most specific actual exception class at the time of writing
34  p = rand(5)
35  with self.assertRaises(Exception): # RuntimeError
36  m * p
37  with self.assertRaises(Exception): # RuntimeError
38  m.actInv(p)
39  with self.assertRaises(Exception): # Boost.Python.ArgumentError (subclass of TypeError)
40  m.actInv('42')
41 
42  def test_motion(self):
43  m = self.m
44  self.assertApprox(pin.Motion.Zero().vector, zero(6))
45  v = pin.Motion.Random()
46  self.assertApprox((m * v).vector, m.action.dot(v.vector))
47  self.assertApprox((m.actInv(v)).vector, npl.inv(m.action).dot(v.vector))
48  vv = v.linear
49  vw = v.angular
50  self.assertApprox(v.vector, np.concatenate([vv, vw]))
51  self.assertApprox((v ^ v).vector, zero(6))
52 
53  def test_force(self):
54  m = self.m
55  self.assertApprox(pin.Force.Zero().vector, zero(6))
56  f = pin.Force.Random()
57  ff = f.linear
58  ft = f.angular
59  self.assertApprox(f.vector, np.concatenate([ff, ft]))
60 
61  self.assertApprox((m * f).vector, npl.inv(m.action.T).dot(f.vector))
62  self.assertApprox((m.actInv(f)).vector, m.action.T.dot(f.vector))
63  v = pin.Motion.Random()
64  f = pin.Force(np.concatenate([v.vector[3:], v.vector[:3]]))
65  self.assertApprox((v ^ f).vector, zero(6))
66 
67  def test_inertia(self):
68  m = self.m
69  Y1 = pin.Inertia.Random()
70  Y2 = pin.Inertia.Random()
71  Y = Y1 + Y2
72  self.assertApprox(Y1.matrix() + Y2.matrix(), Y.matrix())
73  v = pin.Motion.Random()
74  self.assertApprox((Y * v).vector, Y.matrix().dot(v.vector))
75  self.assertApprox((m * Y).matrix(), m.inverse().action.T.dot(Y.matrix()).dot(m.inverse().action))
76  self.assertApprox((m.actInv(Y)).matrix(), m.action.T.dot(Y.matrix()).dot(m.action))
77 
78  def test_cross(self):
79  m = pin.Motion.Random()
80  f = pin.Force.Random()
81  self.assertApprox(m ^ m, m.cross(m))
82  self.assertApprox(m ^ f, m.cross(f))
83  with self.assertRaises(TypeError):
84  m ^ 2
85 
86 if __name__ == '__main__':
87  unittest.main()
def test_motion(self)
Definition: bindings.py:42
def test_inertia(self)
Definition: bindings.py:67
def setUp(self)
Definition: bindings.py:11
def test_se3(self)
Definition: bindings.py:17
def test_cross(self)
Definition: bindings.py:78
def test_force(self)
Definition: bindings.py:53


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