16 from __future__
import print_function
19 from math
import radians
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_NAMES = [
'prbt_joint_1',
'prbt_joint_2',
'prbt_joint_3',
'prbt_joint_4',
'prbt_joint_5',
'prbt_joint_6']
35 _JOINT_LIMITS_DEGREE = {
43 _JOINT_POSITIONS_TOLERANCE = 0.001
45 _JOINT_LIMIT_OVERSTEP = 0.1
46 _COLLISION_JOINT_NAMES = [
55 """ Test that each joint can be moved exactly to its limits and not further.
59 """ Initialize a client for sending trajectories to the controller.
62 if not self.
client.wait_for_server(timeout=rospy.Duration(_ACTION_SERVER_TIMEOUT_SEC)):
63 self.fail(
'Timed out waiting for action server ' + _CONTROLLER_ACTION_NAME)
70 robot = URDF.from_parameter_server(
"robot_description")
72 for joint
in robot.joints:
80 s = input(
'Perform ' + test_name +
' [(y)es, (n)o]?: ')
82 print(
'\n\nSkip ' + test_name +
'\n___TEST-END___\n')
84 print(
'\n\nStart ' + test_name +
'\n')
88 """ Return the current joint state positions in the order given by self.joint_names.
93 msg = rospy.wait_for_message(_JOINT_STATES_TOPIC_NAME, JointState, timeout=_WAIT_FOR_MESSAGE_TIMEOUT_SEC)
94 except rospy.ROSException:
95 self.fail(
'Could not retrieve message from topic ' + _JOINT_STATES_TOPIC_NAME)
99 index = msg.name.index(name)
100 positions.append(msg.position[index])
102 self.fail(
'Could not retrieve joint state position for ' + name)
107 """ Check if current joint positions are within the limits.
112 position = positions[i]
114 limit = radians(_JOINT_LIMITS_DEGREE[name])+_JOINT_POSITIONS_TOLERANCE
116 self.assertGreater(position, -limit,
'Joint ' + name +
' violates lower limit. Position: ' + str(position))
117 self.assertLess(position, limit,
'Joint ' + name +
' violates upper limit. Position: ' + str(position))
120 """ Move the robot to the home position.
124 for i
in range(len(positions)):
127 if any(diff > _JOINT_POSITIONS_TOLERANCE
for diff
in diffs):
131 """ Execute a single point trajectory given through joint positions (in the order given by self.joint_names).
132 Return true on success and false otherwise.
134 self.assertEqual(len(positions), len(self.
joint_names))
140 for i
in range(len(current_positions)):
141 distance = abs(positions[i] - current_positions[i])
145 duration = 2*max(durations)/_VELOCITY_SCALE
148 traj_point = JointTrajectoryPoint()
149 traj_point.positions = positions
150 traj_point.velocities = [0.0]*len(positions)
151 traj_point.time_from_start = rospy.Duration(duration)
153 traj = JointTrajectory()
155 traj.points.append(traj_point)
157 goal = FollowJointTrajectoryGoal()
158 goal.trajectory = traj
161 self.
client.send_goal(goal)
162 self.
client.wait_for_result()
165 result = self.
client.get_result()
166 success = (result.error_code == FollowJointTrajectoryResult.SUCCESSFUL)
168 rospy.loginfo(
'Failure executing: ' + str(goal))
172 """ Test if the robot can be commanded to move exactly to the limits
175 1. Command a movement to the home position.
176 2. Command a movement to the lower limit.
177 3. Command a movement to the upper limit.
178 4. Command a movement to the home position.
181 1. Trajectory is executed successfully.
182 2. Trajectory is executed successfully.
183 3. Trajectory is executed successfully.
184 4. Trajectory is executed successfully.
189 limit = _JOINT_LIMITS_DEGREE[joint_name]
192 lower_positions[index] = -radians(limit)
197 upper_positions[index] = radians(limit)
204 """ Test if the robot does not overstep the limits
207 1. Command a movement to the home position.
208 2. Command a movement overstepping the lower limit.
209 3. Command a movement overstepping the upper limit.
210 4. Command a movement to the home position.
213 1. Trajectory is executed successfully.
214 2. Trajectory execution is aborted and the robot does not overstep the limits.
215 3. Trajectory execution is aborted and the robot does not overstep the limits.
216 4. Trajectory is executed successfully.
221 limit = _JOINT_LIMITS_DEGREE[joint_name]
224 lower_positions[index] = -(radians(limit) + _JOINT_LIMIT_OVERSTEP)
230 upper_positions[index] = radians(limit) + _JOINT_LIMIT_OVERSTEP
238 """ Perform all reaching tests. Before each test ask the user if he wants to skip it.
241 if name
not in _COLLISION_JOINT_NAMES:
246 """ Perform all overstepping tests. Before each test ask the user if he wants to skip it.
249 if name
not in _COLLISION_JOINT_NAMES:
254 if __name__ ==
"__main__":
256 rospy.init_node(
'acceptance_test_joint_limits_node')