33
44from geometry_msgs .msg import Pose
55
6- from moveit_py .core import RobotState , RobotModel
6+ from test_moveit .core .robot_state import RobotState
7+ from test_moveit .core .robot_model import RobotModel
8+
9+
10+ # TODO (peterdavidfagan): depend on moveit_resources package directly.
11+ # (https://github.com/peterdavidfagan/moveit2/blob/moveit_py/moveit_core/utils/src/robot_model_test_utils.cpp)
12+
13+ import os
14+
15+ dir_path = os .path .dirname (os .path .realpath (__file__ ))
16+ URDF_FILE = "{}/fixtures/panda.urdf" .format (dir_path )
17+ SRDF_FILE = "{}/fixtures/panda.srdf" .format (dir_path )
18+
19+
20+ def get_robot_model ():
21+ """Helper function that returns a RobotModel instance."""
22+ return RobotModel (urdf_xml_path = URDF_FILE , srdf_xml_path = SRDF_FILE )
723
824
925class TestRobotState (unittest .TestCase ):
1026 def test_initialization (self ):
1127 """
1228 Test that RobotState can be initialized with a RobotModel
1329 """
14- robot_model = RobotModel (
15- urdf_xml_path = "./fixtures/panda.urdf" , srdf_xml_path = "./fixtures/panda.srdf"
16- )
30+ robot_model = get_robot_model ()
1731 robot_state = RobotState (robot_model )
1832
1933 self .assertIsInstance (robot_state , RobotState )
@@ -22,9 +36,7 @@ def test_robot_model_property(self):
2236 """
2337 Test that the robot_model property returns the correct RobotModel
2438 """
25- robot_model = RobotModel (
26- urdf_xml_path = "./fixtures/panda.urdf" , srdf_xml_path = "./fixtures/panda.srdf"
27- )
39+ robot_model = get_robot_model ()
2840 robot_state = RobotState (robot_model )
2941
3042 self .assertEqual (robot_state .robot_model , robot_model )
@@ -33,11 +45,9 @@ def test_get_frame_transform(self):
3345 """
3446 Test that the frame transform is correct
3547 """
36- robot_model = RobotModel (
37- urdf_xml_path = "./fixtures/panda.urdf" , srdf_xml_path = "./fixtures/panda.srdf"
38- )
48+ robot_model = get_robot_model ()
3949 robot_state = RobotState (robot_model )
40-
50+ robot_state . update ()
4151 frame_transform = robot_state .get_frame_transform ("panda_link0" )
4252
4353 self .assertIsInstance (frame_transform , np .ndarray )
@@ -47,10 +57,9 @@ def test_get_pose(self):
4757 """
4858 Test that the pose is correct
4959 """
50- robot_model = RobotModel (
51- urdf_xml_path = "./fixtures/panda.urdf" , srdf_xml_path = "./fixtures/panda.srdf"
52- )
60+ robot_model = get_robot_model ()
5361 robot_state = RobotState (robot_model )
62+ robot_state .update ()
5463 pose = robot_state .get_pose (link_name = "panda_link8" )
5564
5665 self .assertIsInstance (pose , Pose )
@@ -60,10 +69,9 @@ def test_get_jacobian_1(self):
6069 """
6170 Test that the jacobian is correct
6271 """
63- robot_model = RobotModel (
64- urdf_xml_path = "./fixtures/panda.urdf" , srdf_xml_path = "./fixtures/panda.srdf"
65- )
72+ robot_model = get_robot_model ()
6673 robot_state = RobotState (robot_model )
74+ robot_state .update ()
6775 jacobian = robot_state .get_jacobian (
6876 joint_model_group_name = "panda_arm" ,
6977 reference_point_position = np .array ([0.0 , 0.0 , 0.0 ]),
@@ -76,10 +84,9 @@ def test_get_jacobian_2(self):
7684 """
7785 Test that the jacobian is correct
7886 """
79- robot_model = RobotModel (
80- urdf_xml_path = "./fixtures/panda.urdf" , srdf_xml_path = "./fixtures/panda.srdf"
81- )
87+ robot_model = get_robot_model ()
8288 robot_state = RobotState (robot_model )
89+ robot_state .update ()
8390 jacobian = robot_state .get_jacobian (
8491 joint_model_group_name = "panda_arm" ,
8592 link_name = "panda_link6" ,
@@ -93,49 +100,43 @@ def test_set_joint_group_positions(self):
93100 """
94101 Test that the joint group positions can be set
95102 """
96- robot_model = RobotModel (
97- urdf_xml_path = "./fixtures/panda.urdf" , srdf_xml_path = "./fixtures/panda.srdf"
98- )
103+ robot_model = get_robot_model ()
99104 robot_state = RobotState (robot_model )
100-
105+ robot_state . update ()
101106 joint_group_positions = np .array ([1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 1.0 ])
102107 robot_state .set_joint_group_positions (
103108 joint_model_group_name = "panda_arm" , position_values = joint_group_positions
104109 )
105110
106111 self .assertEqual (
107112 joint_group_positions .tolist (),
108- robot_state .copy_joint_group_positions ("panda_arm" ).tolist (),
113+ robot_state .get_joint_group_positions ("panda_arm" ).tolist (),
109114 )
110115
111116 def test_set_joint_group_velocities (self ):
112117 """
113118 Test that the joint group velocities can be set
114119 """
115- robot_model = RobotModel (
116- urdf_xml_path = "./fixtures/panda.urdf" , srdf_xml_path = "./fixtures/panda.srdf"
117- )
120+ robot_model = get_robot_model ()
118121 robot_state = RobotState (robot_model )
119-
122+ robot_state . update ()
120123 joint_group_velocities = np .array ([1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 1.0 ])
121124 robot_state .set_joint_group_velocities (
122125 joint_model_group_name = "panda_arm" , velocity_values = joint_group_velocities
123126 )
124127
125128 self .assertEqual (
126129 joint_group_velocities .tolist (),
127- robot_state .copy_joint_group_velocities ("panda_arm" ).tolist (),
130+ robot_state .get_joint_group_velocities ("panda_arm" ).tolist (),
128131 )
129132
130133 def test_set_joint_group_accelerations (self ):
131134 """
132135 Test that the joint group accelerations can be set
133136 """
134- robot_model = RobotModel (
135- urdf_xml_path = "./fixtures/panda.urdf" , srdf_xml_path = "./fixtures/panda.srdf"
136- )
137+ robot_model = get_robot_model ()
137138 robot_state = RobotState (robot_model )
138-
139+ robot_state . update ()
139140 joint_group_accelerations = np .array ([1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 1.0 ])
140141 robot_state .set_joint_group_accelerations (
141142 joint_model_group_name = "panda_arm" ,
@@ -144,32 +145,32 @@ def test_set_joint_group_accelerations(self):
144145
145146 self .assertEqual (
146147 joint_group_accelerations .tolist (),
147- robot_state .copy_joint_group_accelerations ("panda_arm" ).tolist (),
148+ robot_state .get_joint_group_accelerations ("panda_arm" ).tolist (),
148149 )
149150
150151 # TODO (peterdavidfagan): requires kinematics solver to be loaded
151- def test_set_from_ik (self ):
152- """
153- Test that the robot state can be set from an IK solution
154- """
155- robot_model = RobotModel (
156- urdf_xml_path = "./fixtures/panda.urdf" , srdf_xml_path = "./fixtures/panda.srdf"
157- )
158- robot_state = RobotState (robot_model )
159-
160- pose = Pose ()
161- pose .position .x = 0.5
162- pose .position .y = 0.5
163- pose .position .z = 0.5
164- pose .orientation .w = 1.0
165-
166- robot_state .set_from_ik (
167- joint_model_group_name = "panda_arm" ,
168- geometry_pose = pose ,
169- tip_name = "panda_link8" ,
170- )
171-
172- self .assertEqual (robot_state .get_pose ("panda_link8" ), pose )
152+ # def test_set_from_ik(self):
153+ # """
154+ # Test that the robot state can be set from an IK solution
155+ # """
156+ # robot_model = RobotModel(
157+ # urdf_xml_path="./fixtures/panda.urdf", srdf_xml_path="./fixtures/panda.srdf"
158+ # )
159+ # robot_state = RobotState(robot_model)
160+ # robot_state.update()
161+ # pose = Pose()
162+ # pose.position.x = 0.5
163+ # pose.position.y = 0.5
164+ # pose.position.z = 0.5
165+ # pose.orientation.w = 1.0
166+
167+ # robot_state.set_from_ik(
168+ # joint_model_group_name="panda_arm",
169+ # geometry_pose=pose,
170+ # tip_name="panda_link8",
171+ # )
172+
173+ # self.assertEqual(robot_state.get_pose("panda_link8"), pose)
173174
174175
175176if __name__ == "__main__" :
0 commit comments