|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: UTF-8 -*- |
| 3 | + |
| 4 | +from __future__ import print_function |
| 5 | + |
| 6 | +import unittest |
| 7 | +import math |
| 8 | +import numpy as np |
| 9 | + |
| 10 | +import geometry_msgs.msg as geo_msg |
| 11 | + |
| 12 | +import rotools.utility.robotics as robotics |
| 13 | + |
| 14 | + |
| 15 | +class Test(unittest.TestCase): |
| 16 | + |
| 17 | + def test_adjoint_T(self): |
| 18 | + T = np.array([[1, 0, 0, 0], |
| 19 | + [0, 0, -1, 0], |
| 20 | + [0, 1, 0, 3], |
| 21 | + [0, 0, 0, 1]], dtype=float) |
| 22 | + Ad_T = np.array([[1, 0, 0, 0, 0, 0], |
| 23 | + [0, 0, -1, 0, 0, 0], |
| 24 | + [0, 1, 0, 0, 0, 0], |
| 25 | + [0, 0, 3, 1, 0, 0], |
| 26 | + [3, 0, 0, 0, 0, -1], |
| 27 | + [0, 0, 0, 0, 1, 0]], dtype=float) |
| 28 | + self.assertTrue(np.allclose(robotics.Adjoint(T), Ad_T)) |
| 29 | + |
| 30 | + def test_adjoint_V(self): |
| 31 | + V = np.array([1, 2, 3, 4, 5, 6]) |
| 32 | + ad_V = np.array([[0, -3, 2, 0, 0, 0], |
| 33 | + [3, 0, -1, 0, 0, 0], |
| 34 | + [-2, 1, 0, 0, 0, 0], |
| 35 | + [0, -6, 5, 0, -3, 2], |
| 36 | + [6, 0, -4, 3, 0, -1], |
| 37 | + [-5, 4, 0, -2, 1, 0]]) |
| 38 | + self.assertTrue(np.allclose(robotics.ad(V), ad_V)) |
| 39 | + |
| 40 | + def test_axis_angle3(self): |
| 41 | + exp_coord3 = np.array([1, 2, 3]) |
| 42 | + result = np.array([0.26726124, 0.53452248, 0.80178373]), 3.7416573867739413 |
| 43 | + self.assertTrue(np.allclose(robotics.axis_angle3(exp_coord3)[0], result[0])) |
| 44 | + self.assertTrue(np.allclose(robotics.axis_angle3(exp_coord3)[1], result[1])) |
| 45 | + |
| 46 | + def test_axis_angle6(self): |
| 47 | + exp_c6 = np.array([1, 0, 0, 1, 2, 3]) |
| 48 | + result = np.array([1.0, 0.0, 0.0, 1.0, 2.0, 3.0]), 1.0 |
| 49 | + self.assertTrue(np.allclose(robotics.axis_angle6(exp_c6)[0], result[0])) |
| 50 | + self.assertTrue(np.allclose(robotics.axis_angle6(exp_c6)[1], result[1])) |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == '__main__': |
| 54 | + unittest.main() |
0 commit comments