Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 import sys
00032
00033 import rospy
00034 import actionlib
00035 from control_msgs.msg import (FollowJointTrajectoryAction,
00036 FollowJointTrajectoryGoal,
00037 GripperCommandAction,
00038 GripperCommandGoal)
00039 from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint
00040
00041 arm_joint_names = ["shoulder_pan_joint", "shoulder_lift_joint", "upperarm_roll_joint",
00042 "elbow_flex_joint", "forearm_roll_joint", "wrist_flex_joint", "wrist_roll_joint"]
00043
00044 arm_intermediate_positions = [0.0, -0.62, 0, 0, 0.0, 0.62, 0.0]
00045
00046
00047 arm_joint_positions = [1.32, 0.7, 0.0, -2.0, 0.0, -0.57, 0.0]
00048 head_joint_names = ["head_pan_joint", "head_tilt_joint"]
00049 head_joint_positions = [0.0, 0.0]
00050
00051 if __name__ == "__main__":
00052 rospy.init_node("prepare_simulated_robot_pick_place")
00053
00054
00055 if rospy.get_param("robot/serial") != "ABCDEFGHIJKLMNOPQRSTUVWX":
00056 rospy.logerr("This script should not be run on a real robot")
00057 sys.exit(-1)
00058
00059 rospy.loginfo("Waiting for head_controller...")
00060 head_client = actionlib.SimpleActionClient("head_controller/follow_joint_trajectory", FollowJointTrajectoryAction)
00061 head_client.wait_for_server()
00062 rospy.loginfo("...connected.")
00063
00064 rospy.loginfo("Waiting for arm_controller...")
00065 arm_client = actionlib.SimpleActionClient("arm_controller/follow_joint_trajectory", FollowJointTrajectoryAction)
00066 arm_client.wait_for_server()
00067 rospy.loginfo("...connected.")
00068
00069 rospy.loginfo("Waiting for gripper_controller...")
00070 gripper_client = actionlib.SimpleActionClient("gripper_controller/gripper_action", GripperCommandAction)
00071 gripper_client.wait_for_server()
00072 rospy.loginfo("...connected.")
00073
00074 trajectory = JointTrajectory()
00075 trajectory.joint_names = head_joint_names
00076 trajectory.points.append(JointTrajectoryPoint())
00077 trajectory.points[0].positions = head_joint_positions
00078 trajectory.points[0].velocities = [0.0] * len(head_joint_positions)
00079 trajectory.points[0].accelerations = [0.0] * len(head_joint_positions)
00080 trajectory.points[0].time_from_start = rospy.Duration(5.0)
00081
00082 head_goal = FollowJointTrajectoryGoal()
00083 head_goal.trajectory = trajectory
00084 head_goal.goal_time_tolerance = rospy.Duration(0.0)
00085
00086 trajectory = JointTrajectory()
00087 trajectory.joint_names = arm_joint_names
00088 trajectory.points.append(JointTrajectoryPoint())
00089 trajectory.points[0].positions = [0.0] * len(arm_joint_positions)
00090 trajectory.points[0].velocities = [0.0] * len(arm_joint_positions)
00091 trajectory.points[0].accelerations = [0.0] * len(arm_joint_positions)
00092 trajectory.points[0].time_from_start = rospy.Duration(1.0)
00093 trajectory.points.append(JointTrajectoryPoint())
00094 trajectory.points[1].positions = arm_intermediate_positions
00095 trajectory.points[1].velocities = [0.0] * len(arm_joint_positions)
00096 trajectory.points[1].accelerations = [0.0] * len(arm_joint_positions)
00097 trajectory.points[1].time_from_start = rospy.Duration(4.0)
00098 trajectory.points.append(JointTrajectoryPoint())
00099 trajectory.points[2].positions = arm_joint_positions
00100 trajectory.points[2].velocities = [0.0] * len(arm_joint_positions)
00101 trajectory.points[2].accelerations = [0.0] * len(arm_joint_positions)
00102 trajectory.points[2].time_from_start = rospy.Duration(7.5)
00103
00104 arm_goal = FollowJointTrajectoryGoal()
00105 arm_goal.trajectory = trajectory
00106 arm_goal.goal_time_tolerance = rospy.Duration(0.0)
00107
00108 gripper_goal = GripperCommandGoal()
00109 gripper_goal.command.max_effort = 10.0
00110 gripper_goal.command.position = 0.1
00111
00112 rospy.loginfo("Setting positions...")
00113 head_client.send_goal(head_goal)
00114 arm_client.send_goal(arm_goal)
00115 gripper_client.send_goal(gripper_goal)
00116 gripper_client.wait_for_result(rospy.Duration(5.0))
00117 arm_client.wait_for_result(rospy.Duration(6.0))
00118 head_client.wait_for_result(rospy.Duration(6.0))
00119 rospy.loginfo("...done")