|
| 1 | +import numpy.testing as nt |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +import unittest |
| 4 | + |
| 5 | +""" |
| 6 | +we will assume that the primitives rotx,trotx, etc. all work |
| 7 | +""" |
| 8 | +from math import pi |
| 9 | +from spatialmath import SE3, SO3, SE2 |
| 10 | +import numpy as np |
| 11 | +# from spatialmath import super_pose as sp |
| 12 | +from spatialmath.base import * |
| 13 | +from spatialmath.base import argcheck |
| 14 | +import spatialmath as sm |
| 15 | +from spatialmath.baseposematrix import BasePoseMatrix |
| 16 | +from spatialmath.twist import BaseTwist |
| 17 | +import spatialmath.base.transforms3d as t3d |
| 18 | + |
| 19 | + |
| 20 | +class TestTransforms3D(unittest.TestCase): |
| 21 | + @classmethod |
| 22 | + def tearDownClass(cls): |
| 23 | + pass |
| 24 | + |
| 25 | + def test_tr2angvec(self): |
| 26 | + true_ang = 1.51 |
| 27 | + true_vec = np.array([0., 1., 0.]) |
| 28 | + eps = 1e-08 |
| 29 | + |
| 30 | + # show that tr2angvec works on true rotation matrix |
| 31 | + R = SO3.Ry(true_ang) |
| 32 | + ang, vec = t3d.tr2angvec(R.A, check=True) |
| 33 | + nt.assert_equal(ang, true_ang) |
| 34 | + nt.assert_equal(vec, true_vec) |
| 35 | + |
| 36 | + # check a rotation matrix that should fail |
| 37 | + badR = SO3.Ry(true_ang).A[:, :] + eps |
| 38 | + with self.assertRaises(ValueError): |
| 39 | + t3d.tr2angvec(badR, check=True) |
| 40 | + |
| 41 | + # run without check |
| 42 | + ang, vec = t3d.tr2angvec(badR, check=False) |
| 43 | + nt.assert_almost_equal(ang, true_ang) |
| 44 | + nt.assert_equal(vec, true_vec) |
| 45 | + |
| 46 | + |
| 47 | +# ---------------------------------------------------------------------------------------# |
| 48 | +if __name__ == '__main__': |
| 49 | + |
| 50 | + unittest.main() |
0 commit comments