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
00032 import roslib; roslib.load_manifest('move_arm_tutorials')
00033
00034 import rospy
00035 import actionlib
00036
00037 import geometric_shapes_msgs
00038
00039 from move_arm_msgs.msg import MoveArmAction
00040 from move_arm_msgs.msg import MoveArmGoal
00041 from motion_planning_msgs.msg import SimplePoseConstraint
00042
00043 from motion_planning_msgs.msg import PositionConstraint
00044 from motion_planning_msgs.msg import OrientationConstraint
00045
00046 from actionlib_msgs.msg import GoalStatus
00047
00048 def pose_constraint_to_position_orientation_constraints(pose_constraint):
00049 position_constraint = PositionConstraint()
00050 orientation_constraint = OrientationConstraint()
00051 position_constraint.header = pose_constraint.header
00052 position_constraint.link_name = pose_constraint.link_name
00053 position_constraint.position = pose_constraint.pose.position
00054
00055 position_constraint.constraint_region_shape.type = geometric_shapes_msgs.msg.Shape.BOX
00056 position_constraint.constraint_region_shape.dimensions.append(2*pose_constraint.absolute_position_tolerance.x)
00057 position_constraint.constraint_region_shape.dimensions.append(2*pose_constraint.absolute_position_tolerance.y)
00058 position_constraint.constraint_region_shape.dimensions.append(2*pose_constraint.absolute_position_tolerance.z)
00059
00060 position_constraint.constraint_region_orientation.x = 0.0
00061 position_constraint.constraint_region_orientation.y = 0.0
00062 position_constraint.constraint_region_orientation.z = 0.0
00063 position_constraint.constraint_region_orientation.w = 1.0
00064
00065 position_constraint.weight = 1.0
00066
00067 orientation_constraint.header = pose_constraint.header
00068 orientation_constraint.link_name = pose_constraint.link_name
00069 orientation_constraint.orientation = pose_constraint.pose.orientation
00070 orientation_constraint.type = pose_constraint.orientation_constraint_type
00071
00072 orientation_constraint.absolute_roll_tolerance = pose_constraint.absolute_roll_tolerance
00073 orientation_constraint.absolute_pitch_tolerance = pose_constraint.absolute_pitch_tolerance
00074 orientation_constraint.absolute_yaw_tolerance = pose_constraint.absolute_yaw_tolerance
00075 orientation_constraint.weight = 1.0
00076
00077 return position_constraint, orientation_constraint
00078
00079 def add_goal_constraint_to_move_arm_goal(pose_constraint, move_arm_goal):
00080 position_constraint, orientation_constraint = pose_constraint_to_position_orientation_constraints(pose_constraint)
00081 move_arm_goal.motion_plan_request.goal_constraints.position_constraints.append(position_constraint)
00082 move_arm_goal.motion_plan_request.goal_constraints.orientation_constraints.append(orientation_constraint)
00083
00084
00085 if __name__ == '__main__':
00086 rospy.init_node('move_arm_pose_goal_test')
00087
00088 move_arm = actionlib.SimpleActionClient('move_right_arm', MoveArmAction)
00089 move_arm.wait_for_server()
00090 rospy.loginfo('Connected to server')
00091
00092 goalA = MoveArmGoal()
00093 goalA.motion_plan_request.group_name = 'right_arm'
00094 goalA.motion_plan_request.num_planning_attempts = 1
00095 goalA.motion_plan_request.planner_id = ''
00096 goalA.planner_service_name = 'ompl_planning/plan_kinematic_path'
00097 goalA.motion_plan_request.allowed_planning_time = rospy.Duration(5.0)
00098
00099 desired_pose = SimplePoseConstraint()
00100 desired_pose.header.frame_id = 'torso_lift_link'
00101 desired_pose.link_name = 'r_gripper_l_fingertip_link'
00102 desired_pose.pose.position.x = 0.75
00103 desired_pose.pose.position.y = -0.188
00104 desired_pose.pose.position.z = 0
00105
00106 desired_pose.pose.orientation.x = 0.0
00107 desired_pose.pose.orientation.y = 0.0
00108 desired_pose.pose.orientation.z = 0.0
00109 desired_pose.pose.orientation.w = 1.0
00110
00111 desired_pose.absolute_position_tolerance.x = 0.02
00112 desired_pose.absolute_position_tolerance.y = 0.02
00113 desired_pose.absolute_position_tolerance.z = 0.02
00114
00115 desired_pose.absolute_roll_tolerance = 0.04
00116 desired_pose.absolute_pitch_tolerance = 0.04
00117 desired_pose.absolute_yaw_tolerance = 0.04
00118
00119 add_goal_constraint_to_move_arm_goal(desired_pose, goalA)
00120
00121 move_arm.send_goal(goalA)
00122 finished_within_time = move_arm.wait_for_result(rospy.Duration(200.0))
00123
00124 if not finished_within_time:
00125 move_arm.cancel_goal()
00126 rospy.loginfo("Timed out achieving goal A")
00127 else:
00128 state = move_arm.get_state()
00129
00130 if state == GoalStatus.SUCCEEDED:
00131 rospy.loginfo('Action finished and was successful.')
00132 else:
00133 rospy.loginfo('Action failed: %d'%(state))
00134
00135
00136