forked from UM-ARM-Lab/pytorch_kinematics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_serial_chain_creation.py
86 lines (75 loc) · 2.99 KB
/
test_serial_chain_creation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
from timeit import default_timer as timer
import torch
import pytorch_kinematics as pk
TEST_DIR = os.path.dirname(__file__)
def test_extract_serial_chain_from_tree():
urdf = "widowx/wx250s.urdf"
full_urdf = os.path.join(TEST_DIR, urdf)
chain = pk.build_chain_from_urdf(open(full_urdf, mode="rb").read())
# full frames
full_frame_expected = """
base_link
└── shoulder_link
└── upper_arm_link
└── upper_forearm_link
└── lower_forearm_link
└── wrist_link
└── gripper_link
└── ee_arm_link
├── gripper_prop_link
└── gripper_bar_link
└── fingers_link
├── left_finger_link
├── right_finger_link
└── ee_gripper_link
"""
full_frame = chain.print_tree()
assert full_frame_expected.strip() == full_frame.strip()
serial_chain = pk.SerialChain(chain, "ee_gripper_link", "base_link")
serial_frame_expected = """
base_link
└── shoulder_link
└── upper_arm_link
└── upper_forearm_link
└── lower_forearm_link
└── wrist_link
└── gripper_link
└── ee_arm_link
└── gripper_bar_link
└── fingers_link
└── ee_gripper_link
"""
serial_frame = serial_chain.print_tree()
assert serial_frame_expected.strip() == serial_frame.strip()
# full chain should have DOF = 8, however since we are creating just a serial chain to ee_gripper_link, should be 6
assert chain.n_joints == 8
assert serial_chain.n_joints == 6
serial_chain = pk.SerialChain(chain, "gripper_prop_link", "base_link")
serial_frame_expected = """
base_link
└── shoulder_link
└── upper_arm_link
└── upper_forearm_link
└── lower_forearm_link
└── wrist_link
└── gripper_link
└── ee_arm_link
└── gripper_prop_link
"""
serial_frame = serial_chain.print_tree()
assert serial_frame_expected.strip() == serial_frame.strip()
serial_chain = pk.SerialChain(chain, "ee_gripper_link", "gripper_link")
serial_frame_expected = """
gripper_link
└── ee_arm_link
└── gripper_bar_link
└── fingers_link
└── ee_gripper_link
"""
serial_frame = serial_chain.print_tree()
assert serial_frame_expected.strip() == serial_frame.strip()
# only gripper_link is the parent frame of a joint in this serial chain
assert serial_chain.n_joints == 1
if __name__ == "__main__":
test_extract_serial_chain_from_tree()