bindings_liegroups.py
Go to the documentation of this file.
1 import unittest
2 import pinocchio as pin
3 import numpy as np
4 
5 from test_case import PinocchioTestCase as TestCase
6 
7 class TestLiegroupBindings(TestCase):
8 
9  def test_basic(self):
10  R3 = pin.liegroups.R3()
11  SO3 = pin.liegroups.SO3()
12  R3xSO3 = R3 * SO3
13  R10 = pin.liegroups.Rn(10)
14 
15  self.assertEqual(R3.name, "R^3")
16  self.assertEqual(R10.name, "R^10")
17  self.assertEqual(SO3.name, "SO(3)")
18  self.assertEqual(R3xSO3.name, R3.name + " x " + SO3.name)
19 
20  self.assertEqual(R3.nq+SO3.nq, R3xSO3.nq)
21  self.assertEqual(R3.nv+SO3.nv, R3xSO3.nv)
22 
23  def test_dIntegrate(self):
24  SELF = 0
25 
26  for lg in [ pin.liegroups.R3(),
27  pin.liegroups.SO3(),
28  pin.liegroups.SE3(),
29  pin.liegroups.R3() * pin.liegroups.SO3(),
30  ]:
31  q = lg.random()
32  v = np.random.rand(lg.nv)
33 
34  q_int = lg.integrate(q,v)
35 
36  q_interpolate = lg.interpolate(q,q_int,0.5)
37 
38  v_diff = lg.difference(q,q_int)
39  self.assertApprox(v,v_diff)
40 
41  J = lg.dIntegrate_dq(q, v)
42 
43  J0 = np.random.rand(lg.nv,lg.nv)
44 
45  J1 = lg.dIntegrate_dq(q, v, SELF, J0)
46  self.assertTrue(np.allclose(np.dot(J, J0),J1))
47 
48  J1 = lg.dIntegrate_dq(q, v, J0, SELF)
49  self.assertTrue(np.allclose(np.dot(J0, J),J1))
50 
51  J = lg.dIntegrate_dv(q, v)
52 
53  J0 = np.random.rand(lg.nv,lg.nv)
54 
55  J1 = lg.dIntegrate_dv(q, v, SELF, J0)
56  self.assertTrue(np.allclose(np.dot(J, J0),J1))
57 
58  J1 = lg.dIntegrate_dv(q, v, J0, SELF)
59  self.assertTrue(np.allclose(np.dot(J0, J),J1))
60 
61  def test_dDifference(self):
62  for lg in [ pin.liegroups.R3(),
63  pin.liegroups.SO3(),
64  pin.liegroups.SE3(),
65  pin.liegroups.R3() * pin.liegroups.SO3(),
66  ]:
67  q0 = lg.random()
68  q1 = lg.random()
69 
70  for arg in [ pin.ARG0, pin.ARG1 ]:
71  J = lg.dDifference(q0, q1, arg)
72 
73  SELF = 0
74  J0 = np.random.rand(lg.nv,lg.nv)
75 
76 
77  J1 = lg.dDifference(q0, q1, arg, SELF, J0)
78  self.assertTrue(np.allclose(np.dot(J, J0),J1))
79 
80  J1 = lg.dDifference(q0, q1, arg, J0, SELF)
81  self.assertTrue(np.allclose(np.dot(J0, J),J1))
82 
84  for lg in [ pin.liegroups.R3(),
85  pin.liegroups.SO3(),
86  pin.liegroups.SE3(),
87  pin.liegroups.R3() * pin.liegroups.SO3(),
88  ]:
89  q = lg.random()
90  v = np.random.rand(lg.nv)
91 
92  for arg in [ pin.ARG0, pin.ARG1 ]:
93 
94  Jint = lg.dIntegrate(q, v, arg)
95  J0 = np.random.rand(lg.nv,lg.nv)
96  Jout1 = lg.dIntegrateTransport(q, v, J0, arg)
97  Jout1_ref = Jint.dot(J0)
98  self.assertApprox(Jout1,Jout1_ref)
99 
100 if __name__ == '__main__':
101  unittest.main()


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:28