unittest/python/utils.py
Go to the documentation of this file.
1 import unittest
2 from math import sqrt
3 
4 import numpy as np
5 import pinocchio as pin
6 from pinocchio.utils import isapprox
7 from test_case import PinocchioTestCase as TestCase
8 
9 
10 class TestUtils(TestCase):
12  m = pin.SE3.Identity()
13  m.translation = np.array([1.0, 2.0, 3.0])
14  m.rotation = np.array(
15  [[1.0, 0.0, 0.0], [0.0, 0.0, -1.0], [0.0, 1.0, 0.0]]
16  ) # rotate('x', pi / 2)
17  self.assertApprox(
18  pin.SE3ToXYZQUAT(m).T, [1.0, 2.0, 3.0, sqrt(2) / 2, 0, 0, sqrt(2) / 2]
19  )
20  self.assertApprox(
21  pin.XYZQUATToSE3([1.0, 2.0, 3.0, sqrt(2) / 2, 0, 0, sqrt(2) / 2]), m
22  )
23  self.assertApprox(
24  pin.XYZQUATToSE3(np.array([1.0, 2.0, 3.0, sqrt(2) / 2, 0, 0, sqrt(2) / 2])),
25  m,
26  )
27  with self.assertRaises(ValueError):
28  pin.XYZQUATToSE3([1.0, 2.0, 3.0])
29  with self.assertRaises(ValueError):
30  pin.XYZQUATToSE3(np.array([1.0, 2.0, 3.0, sqrt(2) / 2]))
31 
32  def test_isapprox(self):
33  self.assertFalse(isapprox(1, 2))
34  self.assertTrue(isapprox(1, 2, 10))
35  self.assertFalse(isapprox([1e10, 1e-7], [1.00001e10, 1e-8]))
36  self.assertTrue(isapprox([1e10, 1e-8], [1.00001e10, 1e-9], 1e-5))
37 
38 
39 if __name__ == "__main__":
40  unittest.main()
pinocchio.utils
Definition: bindings/python/pinocchio/utils.py:1
utils.TestUtils
Definition: unittest/python/utils.py:10
utils.TestUtils.test_isapprox
def test_isapprox(self)
Definition: unittest/python/utils.py:32
utils.TestUtils.test_se3ToXYZQUAT_XYZQUATToSe3
def test_se3ToXYZQUAT_XYZQUATToSe3(self)
Definition: unittest/python/utils.py:11


pinocchio
Author(s):
autogenerated on Fri Jan 10 2025 03:41:36