44 This is a basic MoveIt tutorial with minor modifications for displaying multiple poses, 45 target poses in space and approximate IK solutions using the MoveIt API. 47 The original tutorial can be found here: http://docs.ros.org/indigo/api/moveit_tutorials/html/doc/pr2_tutorials/planning/scripts/doc/move_group_python_interface_tutorial.html 51 roslaunch svenzva_moveit demo.launch simulation:=true 53 in the RViz window that appears, you can add a pose plugin and fill in its topic parameter to /target_pose 54 to visualize the poses published on /target_pose. Then, run this tutorial file: 56 rosrun svenzva_demo moveit_tutorial.py 64 import moveit_commander
65 import moveit_msgs.msg
66 import geometry_msgs.msg
70 from std_msgs.msg
import String
80 print "============ Starting tutorial setup" 81 moveit_commander.roscpp_initialize(sys.argv)
82 rospy.init_node(
'move_group_python_interface_tutorial',
87 robot = moveit_commander.RobotCommander()
91 scene = moveit_commander.PlanningSceneInterface()
97 group = moveit_commander.MoveGroupCommander(
"svenzva_arm")
102 display_trajectory_publisher = rospy.Publisher(
103 '/move_group/display_planned_path',
104 moveit_msgs.msg.DisplayTrajectory)
106 target_pose_publisher = rospy.Publisher(
"/target_pose", geometry_msgs.msg.PoseStamped, queue_size=2)
109 print "============ Waiting for RVIZ..." 111 print "============ Starting tutorial " 117 print "============ Reference frame: %s" % group.get_planning_frame()
120 print "============ Reference frame: %s" % group.get_end_effector_link()
123 print "============ Robot Groups:" 124 print robot.get_group_names()
128 print "============ Printing robot state" 129 print robot.get_current_state()
137 number_of_samples = 5
138 for i
in range(0, number_of_samples):
140 print "============ Generating plan " + str(i)
141 print "pose is chosen randomly, pose may be inherently unreachable." 142 pose_target = geometry_msgs.msg.Pose()
143 pose_target.orientation.w = 1.0
144 pose_target.position.x = random.uniform(-0.5, 0.5)
145 pose_target.position.y = random.uniform(-0.5, 0.5)
146 pose_target.position.z = random.uniform(0.3, 0.6)
148 pub_pose = geometry_msgs.msg.PoseStamped()
149 pub_pose.header.frame_id =
"base_link" 150 pub_pose.pose = pose_target
153 target_pose_publisher.publish(pub_pose)
156 Builds with fewer than 6 DOF will only be able to plan using approximate IK solutions with the standard 157 URDF. Running the MoveIt demo, there is a checkbox for 'allow approximate IK solutions' which permits 158 dragging the interactive marker and planning. 159 If allow_approx_soln is set to True here, we enable approximate IK solutions programmatically. 160 See details on the MoveIt commander API 162 allow_approx_soln =
True 164 if allow_approx_soln:
166 group.set_joint_value_target(pose_target,
"link_5",
True)
168 group.set_pose_target(pose_target)
176 print "============ Waiting while RVIZ displays plan1..." 183 print "============ Visualizing plan1" 184 display_trajectory = moveit_msgs.msg.DisplayTrajectory()
186 display_trajectory.trajectory_start = robot.get_current_state()
187 display_trajectory.trajectory.append(plan1)
188 display_trajectory_publisher.publish(display_trajectory);
191 print "============ Waiting while plan1 is visualized (again)..." 215 group.clear_pose_targets()
218 group_variable_values = group.get_current_joint_values()
219 print "============ Joint values: ", group_variable_values
223 group_variable_values[0] = 1.0
224 group.set_joint_value_target(group_variable_values)
228 print "============ Waiting while RVIZ displays plan2..." 239 waypoints.append(group.get_current_pose().pose)
242 wpose = geometry_msgs.msg.Pose()
243 wpose.orientation.w = 1.0
244 wpose.position.x = waypoints[0].position.x + 0.1
245 wpose.position.y = waypoints[0].position.y
246 wpose.position.z = waypoints[0].position.z
247 waypoints.append(copy.deepcopy(wpose))
250 wpose.position.z -= 0.10
251 waypoints.append(copy.deepcopy(wpose))
254 wpose.position.y += 0.05
255 waypoints.append(copy.deepcopy(wpose))
261 (plan3, fraction) = group.compute_cartesian_path(
266 print "============ Waiting while RVIZ displays plan3..." 273 collision_object = moveit_msgs.msg.CollisionObject()
278 moveit_commander.roscpp_shutdown()
282 print "============ STOPPING" 285 if __name__==
'__main__':
288 except rospy.ROSInterruptException:
def move_group_python_interface_tutorial()
Setup ^^^^^ CALL_SUB_TUTORIAL imports.