16 from __future__
import print_function
19 from math
import radians
22 from urdf_parser_py.urdf
import URDF
23 from actionlib
import SimpleActionClient
24 from control_msgs.msg
import FollowJointTrajectoryAction, FollowJointTrajectoryGoal, FollowJointTrajectoryResult
25 from trajectory_msgs.msg
import JointTrajectory, JointTrajectoryPoint
26 from sensor_msgs.msg
import JointState
28 _CONTROLLER_ACTION_NAME =
'/prbt/manipulator_joint_trajectory_controller/follow_joint_trajectory' 29 _ACTION_SERVER_TIMEOUT_SEC = 5
30 _JOINT_STATES_TOPIC_NAME =
'/joint_states' 31 _WAIT_FOR_MESSAGE_TIMEOUT_SEC = 1
34 _JOINT_LIMITS_DEGREE = {
42 _JOINT_POSITIONS_TOLERANCE = 0.001
44 _JOINT_LIMIT_OVERSTEP = 0.1
48 """ Test that each joint can be moved exactly to its limits and not further. 52 """ Initialize a client for sending trajectories to the controller. 55 if not self.client.wait_for_server(timeout=rospy.Duration(_ACTION_SERVER_TIMEOUT_SEC)):
56 self.fail(
'Timed out waiting for action server ' + _CONTROLLER_ACTION_NAME)
63 robot = URDF.from_parameter_server(
"robot_description")
65 for joint
in robot.joints:
67 index = self.joint_names.index(joint.name)
73 s = raw_input(
'Perform ' + test_name +
' [(y)es, (n)o]?: ')
75 print(
'\n\nSkip ' + test_name +
'\n___TEST-END___\n')
77 print(
'\n\nStart ' + test_name +
'\n')
81 """ Return the current joint state positions in the order given by self.joint_names. 86 msg = rospy.wait_for_message(_JOINT_STATES_TOPIC_NAME, JointState, timeout =_WAIT_FOR_MESSAGE_TIMEOUT_SEC)
87 except rospy.ROSException:
88 self.fail(
'Could not retrieve message from topic ' + _JOINT_STATES_TOPIC_NAME)
92 index = msg.name.index(name)
93 positions.append(msg.position[index])
95 self.fail(
'Could not retrieve joint state position for ' + name)
100 """ Check if current joint positions are within the limits. 105 position = positions[i]
107 limit = radians(_JOINT_LIMITS_DEGREE[name])+_JOINT_POSITIONS_TOLERANCE
109 self.assertGreater(position, -limit,
'Joint ' + name +
' violates lower limit. Position: ' + str(position))
110 self.assertLess(position, limit,
'Joint ' + name +
' violates upper limit. Position: ' + str(position))
113 """ Move the robot to the home position. 117 for i
in range(len(positions)):
120 if any(diff > _JOINT_POSITIONS_TOLERANCE
for diff
in diffs):
124 """ Execute a single point trajectory given through joint positions (in the order given by self.joint_names). Return true on success and 127 self.assertEqual(len(positions), len(self.
joint_names))
133 for i
in range(len(current_positions)):
134 distance = abs(positions[i] - current_positions[i])
137 duration = max(durations)/_VELOCITY_SCALE
140 traj_point = JointTrajectoryPoint()
141 traj_point.positions = positions
142 traj_point.time_from_start = rospy.Duration(duration)
144 traj = JointTrajectory()
146 traj.points.append(traj_point)
148 goal = FollowJointTrajectoryGoal()
149 goal.trajectory = traj
152 self.client.send_goal(goal)
153 self.client.wait_for_result()
156 result = self.client.get_result()
157 success = (result.error_code == FollowJointTrajectoryResult.SUCCESSFUL)
159 rospy.loginfo(
'Failure executing: ' + str(goal))
163 """ Test if the robot can be commanded to move exactly to the limits 166 1. Command a movement to the home position. 167 2. Command a movement to the lower limit. 168 3. Command a movement to the upper limit. 169 4. Command a movement to the home position. 172 1. Trajectory is executed successfully. 173 2. Trajectory is executed successfully. 174 3. Trajectory is executed successfully. 175 4. Trajectory is executed successfully. 179 index = self.joint_names.index(joint_name)
180 limit = _JOINT_LIMITS_DEGREE[joint_name]
183 lower_positions[index] = -radians(limit)
188 upper_positions[index] = radians(limit)
195 """ Test if the robot does not overstep the limits 198 1. Command a movement to the home position. 199 2. Command a movement overstepping the lower limit. 200 3. Command a movement overstepping the upper limit. 201 4. Command a movement to the home position. 204 1. Trajectory is executed successfully. 205 2. Trajectory execution is aborted and the robot does not overstep the limits. 206 3. Trajectory execution is aborted and the robot does not overstep the limits. 207 4. Trajectory is executed successfully. 211 index = self.joint_names.index(joint_name)
212 limit = _JOINT_LIMITS_DEGREE[joint_name]
215 lower_positions[index] = -(radians(limit) + _JOINT_LIMIT_OVERSTEP)
221 upper_positions[index] = radians(limit) + _JOINT_LIMIT_OVERSTEP
229 """ Perform all reaching tests. Before each test ask the user if he wants to skip it. 236 """ Perform all overstepping tests. Before each test ask the user if he wants to skip it. 243 if __name__ ==
"__main__":
245 rospy.init_node(
'acceptance_test_joint_limits_node')
def test_joint_limits_reaching(self)
def _ask_for_permission(self, test_name)
def _joint_limit_reaching_test(self, joint_name)
def _current_joint_state_positions(self)
def _check_joint_limits(self)
def test_joint_limits_overstepping(self)
def _joint_limit_overstepping_test(self, joint_name)
def _execute_trajectory(self, positions)