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
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
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
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
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
00187
00188
00189 set_planning_scene_diff_client.call(planning_scene_diff_request)
00190
00191
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
00202