bindings_liegroups.py
Go to the documentation of this file.
1 import unittest
2 
3 import numpy as np
4 import pinocchio as pin
5 from test_case import PinocchioTestCase as TestCase
6 
7 
8 class TestLiegroupBindings(TestCase):
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 [
27  pin.liegroups.R3(),
28  pin.liegroups.SO3(),
29  pin.liegroups.SO2(),
30  pin.liegroups.SE3(),
31  pin.liegroups.SE2(),
32  pin.liegroups.R3() * pin.liegroups.SO3(),
33  ]:
34  q = lg.random()
35  v = np.random.rand(lg.nv)
36 
37  q_int = lg.integrate(q, v)
38 
39  _q_interpolate = lg.interpolate(q, q_int, 0.5)
40 
41  v_diff = lg.difference(q, q_int)
42  self.assertApprox(v, v_diff)
43 
44  J = lg.dIntegrate_dq(q, v)
45 
46  J0 = np.random.rand(lg.nv, lg.nv)
47 
48  J1 = lg.dIntegrate_dq(q, v, SELF, J0)
49  self.assertTrue(np.allclose(np.dot(J, J0), J1))
50 
51  J1 = lg.dIntegrate_dq(q, v, J0, SELF)
52  self.assertTrue(np.allclose(np.dot(J0, J), J1))
53 
54  J = lg.dIntegrate_dv(q, v)
55 
56  J0 = np.random.rand(lg.nv, lg.nv)
57 
58  J1 = lg.dIntegrate_dv(q, v, SELF, J0)
59  self.assertTrue(np.allclose(np.dot(J, J0), J1))
60 
61  J1 = lg.dIntegrate_dv(q, v, J0, SELF)
62  self.assertTrue(np.allclose(np.dot(J0, J), J1))
63 
64  def test_dDifference(self):
65  for lg in [
66  pin.liegroups.R3(),
67  pin.liegroups.SO3(),
68  pin.liegroups.SO2(),
69  pin.liegroups.SE3(),
70  pin.liegroups.SE2(),
71  pin.liegroups.R3() * pin.liegroups.SO3(),
72  ]:
73  q0 = lg.random()
74  q1 = lg.random()
75 
76  for arg in [pin.ARG0, pin.ARG1]:
77  J = lg.dDifference(q0, q1, arg)
78 
79  SELF = 0
80  J0 = np.random.rand(lg.nv, lg.nv)
81 
82  J1 = lg.dDifference(q0, q1, arg, SELF, J0)
83  self.assertTrue(np.allclose(np.dot(J, J0), J1))
84 
85  J1 = lg.dDifference(q0, q1, arg, J0, SELF)
86  self.assertTrue(np.allclose(np.dot(J0, J), J1))
87 
89  for lg in [
90  pin.liegroups.R3(),
91  pin.liegroups.SO3(),
92  pin.liegroups.SO2(),
93  pin.liegroups.SE3(),
94  pin.liegroups.SE2(),
95  pin.liegroups.R3() * pin.liegroups.SO3(),
96  ]:
97  q = lg.random()
98  v = np.random.rand(lg.nv)
99 
100  for arg in [pin.ARG0, pin.ARG1]:
101  Jint = lg.dIntegrate(q, v, arg)
102  J0 = np.random.rand(lg.nv, lg.nv)
103  Jout1 = lg.dIntegrateTransport(q, v, J0, arg)
104  Jout1_ref = Jint.dot(J0)
105  self.assertApprox(Jout1, Jout1_ref)
106 
108  for lg in [
109  pin.liegroups.R3(),
110  pin.liegroups.SO3(),
111  pin.liegroups.SO2(),
112  pin.liegroups.SE3(),
113  pin.liegroups.SE2(),
114  pin.liegroups.R3() * pin.liegroups.SO3(),
115  ]:
116  q0 = lg.random()
117  v = np.random.rand(lg.nv)
118  q1 = lg.integrate(q0, v)
119 
120  # transport random tangent vector from q1 to q0
121  tvec_at_q1 = np.random.rand(lg.nv)
122  tvec_at_q0 = lg.dIntegrateTransport(q0, v, tvec_at_q1, pin.ARG0)
123 
124  # test reverse direction
125  v_r = -v.copy() # reverse path
126  q0_r = lg.integrate(q1, v_r)
127 
128  self.assertApprox(q0, q0_r) # recover init point on manifold
129 
130  tvec_at_q1_r = lg.dIntegrateTransport(q1, v_r, tvec_at_q0, pin.ARG0)
131 
132  self.assertApprox(tvec_at_q1, tvec_at_q1_r)
133 
134  # same test for matrix
135  J_at_q1 = np.random.rand(lg.nv, lg.nv)
136  J_at_q0 = lg.dIntegrateTransport(q0, v, J_at_q1, pin.ARG0)
137  self.assertApprox(
138  J_at_q1, lg.dIntegrateTransport(q1, v_r, J_at_q0, pin.ARG0)
139  )
140 
141 
142 if __name__ == "__main__":
143  unittest.main()
bindings_liegroups.TestLiegroupBindings.test_dIntegrateTransport
def test_dIntegrateTransport(self)
Definition: bindings_liegroups.py:88
bindings_liegroups.TestLiegroupBindings
Definition: bindings_liegroups.py:8
bindings_liegroups.TestLiegroupBindings.test_dDifference
def test_dDifference(self)
Definition: bindings_liegroups.py:64
bindings_liegroups.TestLiegroupBindings.test_dIntegrateTransport_inverse
def test_dIntegrateTransport_inverse(self)
Definition: bindings_liegroups.py:107
bindings_liegroups.TestLiegroupBindings.test_basic
def test_basic(self)
Definition: bindings_liegroups.py:9
bindings_liegroups.TestLiegroupBindings.test_dIntegrate
def test_dIntegrate(self)
Definition: bindings_liegroups.py:23


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:06