Skip to content

Commit d5d3cfa

Browse files
committed
refine naming and doc; add test
1 parent 686b67a commit d5d3cfa

File tree

3 files changed

+171
-116
lines changed

3 files changed

+171
-116
lines changed

src/rotools/simulation/webots.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ def get_tcp_pose(self):
6565
# w: world frame, s: robot base frame, b: tcp frame
6666
p_wb = np.array(self.eef_node.getPosition())
6767
R_wb = np.array(self.eef_node.getOrientation()).reshape((3, -1))
68-
T_wb = kinematics.rp_to_homo_trans(R_wb, p_wb)
68+
T_wb = kinematics.Rp_to_SE3(R_wb, p_wb)
6969

7070
p_ws = np.array(self.base_node.getPosition())
7171
R_ws = np.array(self.base_node.getOrientation()).reshape((3, -1))
72-
T_ws = kinematics.rp_to_homo_trans(R_ws, p_ws)
72+
T_ws = kinematics.Rp_to_SE3(R_ws, p_ws)
7373

74-
return np.dot(kinematics.homo_trans_inv(T_ws), T_wb)
74+
return np.dot(kinematics.SE3_inv(T_ws), T_wb)
7575

7676
def go_to_joint_state(self, joint_goal, tolerance=1e-4):
7777
"""Set the joint states as desired.
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)