move_arm_simple_pose_goal.py
Go to the documentation of this file.
00001 #
00002 # Copyright (c) 2010, Georgia Tech Research Corporation
00003 # All rights reserved.
00004 # 
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are met:
00007 #     * Redistributions of source code must retain the above copyright
00008 #       notice, this list of conditions and the following disclaimer.
00009 #     * Redistributions in binary form must reproduce the above copyright
00010 #       notice, this list of conditions and the following disclaimer in the
00011 #       documentation and/or other materials provided with the distribution.
00012 #     * Neither the name of the Georgia Tech Research Corporation nor the
00013 #       names of its contributors may be used to endorse or promote products
00014 #       derived from this software without specific prior written permission.
00015 # 
00016 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00017 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00020 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00021 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00022 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00023 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00024 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 #
00027 #
00028 
00029 # Author: Advait Jain (advait@cc.gatech.edu), Healthcare Robotics Lab, Georgia Tech
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 


move_arm_tutorials
Author(s): Advait Jain
autogenerated on Wed Nov 27 2013 12:16:08