both_arm_cmder.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 #
00003 # Copyright (c) 2010, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are met:
00008 #
00009 #     * Redistributions of source code must retain the above copyright
00010 #       notice, this list of conditions and the following disclaimer.
00011 #     * Redistributions in binary form must reproduce the above copyright
00012 #       notice, this list of conditions and the following disclaimer in the
00013 #       documentation and/or other materials provided with the distribution.
00014 #     * Neither the name of the Willow Garage, Inc. nor the names of its
00015 #       contributors may be used to endorse or promote products derived from
00016 #       this software without specific prior written permission.
00017 #
00018 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 # POSSIBILITY OF SUCH DAMAGE.
00029 
00030 ##\author Kevin Watts
00031 ##\brief Sends goals to arm to move it in collision free way
00032 
00033 PKG = 'life_test'
00034 import roslib; roslib.load_manifest(PKG)
00035 import rospy
00036 import actionlib
00037 import random
00038 import copy
00039 import math
00040 from time import sleep
00041 
00042 from pr2_controllers_msgs.msg import *
00043 from trajectory_msgs.msg import JointTrajectoryPoint
00044 from arm_navigation_msgs.msg import Shape, CollisionObject, CollisionObjectOperation, AttachedCollisionObject, PlanningScene
00045 from arm_navigation_msgs.srv import SetPlanningSceneDiffRequest, SetPlanningSceneDiff
00046 from geometry_msgs.msg import Pose
00047 from actionlib_msgs.msg import GoalStatus
00048 
00049 from life_test.commanders.arm_cmder import ArmCmder
00050 
00051 COLLISION_TOPIC = "collision_object"
00052 
00053 # Shoulder pan joints are limited in position to prevent contact
00054 ranges = {
00055     'r_shoulder_pan_joint': (-2.0, -0.4),
00056     'r_shoulder_lift_joint': (-0.3, 1.25),
00057     'r_upper_arm_roll_joint': (-3.1, 0),
00058     'r_elbow_flex_joint': (-2.0, -0.2),
00059     'r_forearm_roll_joint': (-3.14, 3.14),
00060     'r_wrist_flex_joint': (-1.8, -0.2),
00061     'r_wrist_roll_joint': (-3.14, 3.14),
00062     'l_shoulder_pan_joint': (0.4, 2.0),
00063     'l_shoulder_lift_joint': (-0.3, 1.25),
00064     'l_upper_arm_roll_joint': (0, 3.1),
00065     'l_elbow_flex_joint': (-2.0, -0.2),
00066     'l_forearm_roll_joint': (-3.14, 3.14),
00067     'l_wrist_flex_joint': (-1.8, -0.2),
00068     'l_wrist_roll_joint': (-3.14, 3.14)
00069 }
00070 
00071 recovery_positions = {
00072     'r_shoulder_pan_joint': - math.pi / 4,
00073     'r_shoulder_lift_joint': 0.0,
00074     'r_upper_arm_roll_joint': 0.0,
00075     'r_elbow_flex_joint': -.25,
00076     'r_forearm_roll_joint': 0.0,
00077     'r_wrist_flex_joint': -.25,
00078     'r_wrist_roll_joint': 0.0,
00079     'l_shoulder_pan_joint': math.pi / 4,
00080     'l_shoulder_lift_joint': 0.0,
00081     'l_upper_arm_roll_joint': 0.0,
00082     'l_elbow_flex_joint': -.25,
00083     'l_forearm_roll_joint': 0.0,
00084     'l_wrist_flex_joint': -.25,
00085     'l_wrist_roll_joint': 0.0
00086 }
00087 
00088 def get_virtual_gloves():
00089     r_glove = AttachedCollisionObject()
00090     r_glove.object.header.stamp = rospy.get_rostime()
00091     r_glove.object.header.frame_id = '/r_gripper_palm_link'
00092     r_glove.link_name = 'r_gripper_palm_link'
00093 
00094     r_glove.object.id = 'r_gripper_glove'
00095     r_glove.object.operation.operation = CollisionObjectOperation.ADD
00096     
00097     glove_shape = Shape()
00098     glove_shape.type = Shape.BOX
00099     glove_shape.dimensions = [ 0.25, 0.18, 0.1 ]
00100     glove_pose = Pose()
00101     glove_pose.orientation.w = 1
00102     glove_pose.position.x = 0.1
00103     
00104     # Pose will be zero
00105 
00106     r_glove.touch_links = ['r_end_effector',
00107                            'r_wrist_roll_link',
00108                            'r_wrist_flex_link',
00109                            'r_forearm_link']
00110 
00111     r_glove.object.shapes.append(glove_shape)
00112     r_glove.object.poses.append(glove_pose)
00113 
00114     l_glove = copy.deepcopy(r_glove)
00115     l_glove.object.id = 'l_gripper_glove'
00116     l_glove.object.header.frame_id = '/l_gripper_palm_link'
00117     l_glove.link_name = 'l_gripper_palm_link'
00118     l_glove.touch_links = ['l_end_effector',
00119                            'l_wrist_roll_link',
00120                            'l_wrist_flex_link',
00121                            'l_forearm_link']
00122 
00123     return r_glove, l_glove
00124     
00125 
00126 ##\brief Sets up a virtual table in front of the robot
00127 def get_virtual_table(height = 0.42):
00128     table_msg = CollisionObject()
00129 
00130     table_msg.id = "table"
00131     table_msg.operation.operation = CollisionObjectOperation.ADD    
00132 
00133     table_msg.header.stamp = rospy.get_rostime()
00134     table_msg.header.frame_id = "base_footprint"
00135     
00136     side_box = Shape()
00137     side_box.type = Shape.BOX
00138     side_box.dimensions = [ 3.0, 1.0, height ]
00139 
00140     front_box = Shape()
00141     front_box.type = Shape.BOX
00142     front_box.dimensions = [ 1.0, 3.0, height ]
00143 
00144     pose = Pose()
00145     pose.position.x = 0.0
00146     pose.position.y = 0.0
00147     pose.position.z = height / 2
00148     pose.orientation.x = 0
00149     pose.orientation.y = 0
00150     pose.orientation.z = 0
00151     pose.orientation.w = 1
00152 
00153     l_side_pose = copy.deepcopy(pose)
00154     l_side_pose.position.y = 0.85
00155 
00156     r_side_pose = copy.deepcopy(pose)
00157     r_side_pose.position.y = -0.85
00158 
00159     front_pose = copy.deepcopy(pose)
00160     front_pose.position.x = 0.85
00161 
00162     table_msg.shapes = [ side_box, side_box, front_box ]
00163     table_msg.poses = [ l_side_pose, r_side_pose, front_pose ]
00164 
00165     return table_msg
00166 
00167 if __name__ == '__main__':
00168     rospy.init_node('arm_cmder_client')
00169     client = actionlib.SimpleActionClient('collision_free_arm_trajectory_action_arms', 
00170                                           JointTrajectoryAction)
00171     rospy.loginfo('Waiting for server for collision free arm commander')
00172     client.wait_for_server()
00173 
00174     rospy.loginfo('Right, left arm commanders ready')
00175 
00176     rospy.loginfo('Waiting for environment server')
00177 
00178     rospy.wait_for_service('environment_server/set_planning_scene_diff')
00179 
00180     set_planning_scene_diff_client = rospy.ServiceProxy('environment_server/set_planning_scene_diff',
00181                                                         SetPlanningSceneDiff)
00182 
00183     planning_scene_diff_request = SetPlanningSceneDiffRequest()
00184     planning_scene_diff_request.planning_scene_diff.collision_objects.append(get_virtual_table())
00185     r_glove, l_glove = get_virtual_gloves()
00186     #planning_scene_diff_request.planning_scene_diff.attached_collision_objects.append(r_glove)
00187     #planning_scene_diff_request.planning_scene_diff.attached_collision_objects.append(l_glove)
00188 
00189     set_planning_scene_diff_client.call(planning_scene_diff_request)
00190 
00191     # Recovery trajectory client
00192     recovery_client = actionlib.SimpleActionClient('both_arms_controller/joint_trajectory_action',
00193                                                 JointTrajectoryAction)
00194     
00195     cmder = ArmCmder(client, ranges, recovery_client, recovery_positions)
00196 
00197     while not rospy.is_shutdown():
00198         rospy.logdebug('Sending goal to arms.')
00199         cmder.send_cmd()
00200 
00201         #sleep(2.0)
00202 


life_test
Author(s): Kevin Watts
autogenerated on Sat Dec 28 2013 17:56:37