22#
33# SPDX-License-Identifier: Apache-2.0
44
5+ import numpy as np
56import pytest
7+ import xmltodict
68from alliander_utilities .config_objects import Arm
9+ from control_msgs .msg import JointTrajectoryControllerState
710from rclpy .node import Node
811from sensor_msgs .msg import JointState
912
1316 call_trigger_action ,
1417 check_joint_positions ,
1518 follow_joint_trajectory_goal ,
19+ get_message ,
20+ get_parameter ,
1621 wait_until_reached_joint ,
1722)
1823
19- arm = Arm ("franka" , gripper = True , moveit = True )
20- PLATFORMS = [arm ]
21-
2224
2325class _TestArm :
2426 """Base class for arm tests.
2527
2628 Attributes:
27- platforms (dict): A dictionary of the platforms to launch.
29+ platforms (dict): A dictionary of the platforms to launch.
2830 """
2931
3032 platforms : dict
@@ -56,6 +58,8 @@ def test_gripper_action(
5658 finger_joint_fault_tolerance (float): The tolerance for the finger joint position.
5759 timeout (int): The timeout in seconds before stopping the test.
5860 """
61+ if self .platforms ["arm" ].name == "ur" :
62+ pytest .skip ("Gripper is not yet implemented for UR arm." )
5963 assert (
6064 call_trigger_action (
6165 test_node ,
@@ -85,18 +89,27 @@ def test_follow_joint_trajectory_goal(
8589 joint_movement_tolerance (float): The tolerance for joint movement.
8690 timeout (int): The timeout in seconds to wait for the joint trajectory goal to be followed.
8791 """
88- expected_positions = [0.15 , - 0.39 , 0.1 , - 2.06 , 0.0 , 1.68 , 1.01 ]
92+ # Get joint names and current position and define a goal position:
93+ controller_state = get_message (
94+ JointTrajectoryControllerState ,
95+ f"/{ self .platforms ['arm' ].namespace } /joint_trajectory_controller/controller_state" ,
96+ timeout = timeout ,
97+ )
98+ current_positions = list (controller_state .reference .positions )
99+ goal_positions = [position + np .deg2rad (10 ) for position in current_positions ]
100+
101+ # Call the follow_joint_trajectory action and check if the joints reached the expected positions:
89102 follow_joint_trajectory_goal (
90103 test_node ,
91- positions = expected_positions ,
92- controller = f"{ self .platforms ['arm' ].namespace } /fr3_arm_controller" ,
104+ controller_state .joint_names ,
105+ goal_positions ,
106+ controller = f"{ self .platforms ['arm' ].namespace } /joint_trajectory_controller" ,
93107 timeout = timeout ,
94108 )
95- joint_names = [f"fr3_joint{ i + 1 } " for i in range (7 )]
96109 check_joint_positions (
97110 self .platforms ["arm" ].namespace ,
98- joint_names ,
99- expected_positions ,
111+ controller_state . joint_names ,
112+ goal_positions ,
100113 joint_movement_tolerance ,
101114 timeout ,
102115 )
@@ -111,21 +124,43 @@ def test_move_to_drop_configuration(
111124 joint_movement_tolerance (float): The tolerance for joint movement.
112125 timeout (int): The timeout in seconds before stopping the test.
113126 """
127+ # Get the robot_description_semantic and convert to a dictionary:
128+ robot_description_semantic_str = get_parameter (
129+ test_node ,
130+ f"/{ self .platforms ['arm' ].namespace } /move_group" ,
131+ "robot_description_semantic" ,
132+ timeout = timeout ,
133+ ).string_value
134+ robot_description_semantic = xmltodict .parse (robot_description_semantic_str )
135+
136+ # Extract the configurations from the robot_description_semantic:
137+ configurations = {}
138+ group_states = robot_description_semantic ["robot" ]["group_state" ]
139+ for group_state in group_states :
140+ configurations [group_state ["@name" ]] = {"names" : [], "positions" : []}
141+ for joint in group_state ["joint" ]:
142+ configurations [group_state ["@name" ]]["names" ].append (joint ["@name" ])
143+ configurations [group_state ["@name" ]]["positions" ].append (
144+ joint ["@value" ]
145+ )
146+
147+ # Call the move_to_configuration service and check if the joints reached the expected positions:
148+ configuration = "drop"
149+ names = configurations [configuration ]["names" ]
150+ positions = [float (pos ) for pos in configurations [configuration ]["positions" ]]
114151 assert call_move_to_configuration_service (
115- test_node , self .platforms ["arm" ].namespace , "drop" , timeout = timeout
152+ test_node , self .platforms ["arm" ].namespace , configuration , timeout = timeout
116153 ), "Failed to call move_to_configuration service."
117- joint_names = [f"fr3_joint{ i + 1 } " for i in range (7 )]
118- expected_positions = [- 1.57079632679 , - 0.65 , 0 , - 2.4 , 0 , 1.75 , 0.78539816339 ]
119154 check_joint_positions (
120155 self .platforms ["arm" ].namespace ,
121- joint_names ,
122- expected_positions ,
156+ names ,
157+ positions ,
123158 joint_movement_tolerance ,
124159 timeout ,
125160 )
126161
127162
128- for arm in ["franka" ]:
163+ for arm in ["franka" , "ur" ]:
129164 arm_platform = Arm (arm , (0 , 0 , 0.5 ), gripper = True , moveit = True )
130165 test_class = type (
131166 f"Test{ arm .capitalize ()} " ,
0 commit comments