unittest/python/explog.py
Go to the documentation of this file.
1 import unittest
2 import math
3 
4 import numpy as np
5 import pinocchio as pin
6 
7 from pinocchio.utils import rand, zero, eye
8 from pinocchio.explog import exp, log
9 
10 from test_case import PinocchioTestCase as TestCase
11 
12 
13 class TestExpLog(TestCase):
14  def test_exp3(self):
15  v = zero(3)
16  m = pin.exp3(v)
17  self.assertApprox(m, eye(3))
18 
19  def test_Jexp3(self):
20  v = zero(3)
21  m = pin.Jexp3(v)
22  self.assertApprox(m, eye(3))
23 
24  def test_log3(self):
25  m = eye(3)
26  v = pin.log3(m)
27  self.assertApprox(v, zero(3))
28 
29  def test_Jlog3(self):
30  m = eye(3)
31  J = pin.Jlog3(m)
32  self.assertApprox(J, eye(3))
33 
34  def test_exp6(self):
35  v = pin.Motion.Zero()
36  M = pin.exp6(v)
37  self.assertTrue(M.isIdentity())
38 
39  M2 = pin.exp6(np.array(v))
40  self.assertTrue(M2.isIdentity())
41 
42  def test_Jexp6(self):
43  v = pin.Motion.Zero()
44  J = pin.Jexp6(v)
45  self.assertApprox(J,eye(6))
46 
47  J2 = pin.Jexp6(np.array(v))
48  self.assertApprox(J,J2)
49 
50  def test_log6(self):
51  m = pin.SE3.Identity()
52  v = pin.log6(m)
53  self.assertApprox(v.vector, zero(6))
54 
56  m = eye(4)
57  v = pin.log6(m)
58  self.assertApprox(v.vector, zero(6))
59 
60  def test_Jlog6(self):
61  m = pin.SE3.Identity()
62  J = pin.Jlog6(m)
63  self.assertApprox(J, eye(6))
64 
65  def test_skew(self):
66  u = np.random.rand((3))
67  v = np.random.rand((3))
68 
69  u_skew = pin.skew(u)
70  u_unskew = pin.unSkew(u_skew)
71 
72  self.assertApprox(u,u_unskew)
73 
74  v_skew = pin.skew(v)
75  u_v_square = pin.skewSquare(u,v)
76 
77  self.assertApprox(u_v_square,u_skew.dot(v_skew))
78 
79  def test_explog(self):
80  self.assertApprox(exp(42), math.exp(42))
81  self.assertApprox(log(42), math.log(42))
82  self.assertApprox(exp(log(42)), 42)
83  self.assertApprox(log(exp(42)), 42)
84 
85  m = rand(3)
86  self.assertLess(np.linalg.norm(m), np.pi) # necessary for next test
87  self.assertApprox(log(exp(m)), m)
88 
89  m = np.random.rand(3)
90  self.assertLess(np.linalg.norm(m), np.pi) # necessary for next test
91  self.assertApprox(log(exp(m)), m)
92 
93  m = pin.SE3.Random()
94  self.assertApprox(exp(log(m)), m)
95 
96  m = rand(6)
97  self.assertLess(np.linalg.norm(m), np.pi) # necessary for next test (actually, only angular part)
98  self.assertApprox(log(exp(m)), m)
99 
100  m = np.random.rand(6)
101  self.assertLess(np.linalg.norm(m), np.pi) # necessary for next test (actually, only angular part)
102  self.assertApprox(log(exp(m)), m)
103 
104  m = eye(4)
105  self.assertApprox(exp(log(m)).homogeneous, m)
106 
107  with self.assertRaises(ValueError):
108  exp(eye(4))
109  with self.assertRaises(ValueError):
110  exp(list(range(3)))
111  with self.assertRaises(ValueError):
112  log(list(range(3)))
113  with self.assertRaises(ValueError):
114  log(zero(5))
115  with self.assertRaises(ValueError):
116  log(zero((3,1)))
117 
118 
119 if __name__ == '__main__':
120  unittest.main()


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