6 from actionlib
import SimpleActionClient
7 from sensor_msgs.msg
import JointState
8 from trajectory_msgs.msg
import JointTrajectory, JointTrajectoryPoint
9 from control_msgs.msg
import FollowJointTrajectoryAction, \
10 FollowJointTrajectoryGoal, FollowJointTrajectoryResult
12 ros.init_node(
'move_to_start')
14 action = ros.resolve_name(
'~follow_joint_trajectory')
16 ros.loginfo(
"move_to_start: Waiting for '" + action +
"' action to come up")
17 client.wait_for_server()
19 param = ros.resolve_name(
'~joint_pose')
20 pose = ros.get_param(param,
None)
22 ros.logerr(
'move_to_start: Could not find required parameter "' + param +
'"')
25 topic = ros.resolve_name(
'~joint_states')
26 ros.loginfo(
"move_to_start: Waiting for message on topic '" + topic +
"'")
27 joint_state = ros.wait_for_message(topic, JointState)
28 initial_pose = dict(zip(joint_state.name, joint_state.position))
30 max_movement = max(abs(pose[joint] - initial_pose[joint])
for joint
in pose)
32 point = JointTrajectoryPoint()
33 point.time_from_start = ros.Duration.from_sec(
36 max(max_movement / ros.get_param(
'~max_dq', 0.5), 0.5)
38 goal = FollowJointTrajectoryGoal()
40 goal.trajectory.joint_names, point.positions = [list(x)
for x
in zip(*pose.items())]
41 point.velocities = [0] * len(pose)
43 goal.trajectory.points.append(point)
44 goal.goal_time_tolerance = ros.Duration.from_sec(0.5)
46 ros.loginfo(
'Sending trajectory Goal to move into initial config')
47 client.send_goal_and_wait(goal)
49 result = client.get_result()
50 if result.error_code != FollowJointTrajectoryResult.SUCCESSFUL:
51 ros.logerr(
'move_to_start: Movement was not successful: ' + {
52 FollowJointTrajectoryResult.INVALID_GOAL:
54 The joint pose you want to move to is invalid (e.g. unreachable, singularity...). 55 Is the 'joint_pose' reachable? 58 FollowJointTrajectoryResult.INVALID_JOINTS:
60 The joint pose you specified is for different joints than the joint trajectory controller 61 is claiming. Does you 'joint_pose' include all 7 joints of the robot? 64 FollowJointTrajectoryResult.PATH_TOLERANCE_VIOLATED:
66 During the motion the robot deviated from the planned path too much. Is something blocking 70 FollowJointTrajectoryResult.GOAL_TOLERANCE_VIOLATED:
72 After the motion the robot deviated from the desired goal pose too much. Probably the robot 73 didn't reach the joint_pose properly 78 ros.loginfo(
'move_to_start: Successfully moved into start pose')