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 PACKAGE='pr2_delivery'
00034
00035 import roslib; roslib.load_manifest(PACKAGE)
00036 import subprocess
00037 import rospy
00038 import actionlib
00039 import geometry_msgs.msg
00040 import pr2_common_action_msgs.msg
00041 from pr2_delivery.msg import DeliverAction, DeliverGoal
00042 from ArmMover import ArmMover
00043 from pr2_gripper_sensor_msgs.msg import PR2GripperEventDetectorAction, PR2GripperEventDetectorGoal
00044 from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
00045
00046 class DeliverServer:
00047
00048 tucked_with_object_pose = [-0.0175476818422744, 1.1720448201611564, -1.3268105758514066, -1.288722079574422, -31.28968470078213, -2.0089650532319836, -5.841424529413016]
00049 tuck_approach_pose = [0.039, 1.1072, 0.0, -2.067, -1.231, -1.998, 0.369]
00050 accept_object_pose = [ -0.07666010001780543, 0.1622352230632809, -0.31320771836735584, -1.374860652847621, -3.1324415863359545, -1.078194355846691, 1.857217828689617]
00051 tucked_with_object_approach_pose = [-0.01829384139848722, 0.6712428753827848, -1.3264898661986668, -0.6078654239376914, 0.601472182148825, -1.3278329090728338, -5.83346239703479]
00052
00053 def __init__(self):
00054 self.tuck_arm_client = actionlib.SimpleActionClient("tuck_arms", pr2_common_action_msgs.msg.TuckArmsAction)
00055 self.gripper_wiggle_detector_client = actionlib.SimpleActionClient('r_gripper_sensor_controller/event_detector', PR2GripperEventDetectorAction)
00056 self.move_base_client = actionlib.SimpleActionClient('move_base', MoveBaseAction)
00057
00058
00059 self.lang = rospy.get_param('~lang', 'en')
00060
00061 self.request_item_phrase = rospy.get_param('~request_item_phrase', 'Please give me the delivery.')
00062 self.item_received_phrase = rospy.get_param('~item_received_phrase', 'Thank you. I will deliver this.')
00063 self.give_item_phrase = rospy.get_param('~give_item_phrase', 'I have a delivery for you.')
00064 self.item_delivered_phrase = rospy.get_param('~item_delivered_phrase', 'Thank you. Have a nice day.')
00065
00066 self.arm_mover = ArmMover()
00067
00068 rospy.loginfo("Waiting for tuck_arms action server")
00069 self.tuck_arm_client.wait_for_server(rospy.Duration(10.0))
00070 rospy.loginfo("Waiting for wiggle_detector action server")
00071 self.gripper_wiggle_detector_client.wait_for_server(rospy.Duration(10.0))
00072 rospy.loginfo("Waiting for move_base action server")
00073 self.move_base_client.wait_for_server(rospy.Duration(10.0))
00074
00075 self.server = actionlib.SimpleActionServer('deliver', DeliverAction, self.execute, False)
00076 self.server.start()
00077
00078 rospy.loginfo("Ready")
00079
00080 def execute(self, goal):
00081 """This is the main sequence of the delivery action."""
00082 self.tuck_arms()
00083 self.navigate_to(goal.get_object_pose)
00084 self.say(self.request_item_phrase)
00085 self.get_object()
00086 self.say(self.item_received_phrase)
00087 self.navigate_to(goal.give_object_pose)
00088 self.say(self.give_item_phrase)
00089 self.give_object()
00090 self.say(self.item_delivered_phrase)
00091 self.tuck_arms()
00092 self.navigate_to(goal.return_home_pose)
00093
00094 self.server.set_succeeded()
00095
00096 def say(self, thing_to_say):
00097
00098
00099 speed = 130
00100 subprocess.call([ 'espeak',
00101 "-v", self.lang,
00102 "-s", "%d"%speed,
00103 thing_to_say ])
00104
00105 def tuck_arms(self):
00106 rospy.loginfo("tucking arms")
00107 goal = pr2_common_action_msgs.msg.TuckArmsGoal()
00108 goal.tuck_left = True
00109 goal.tuck_right = True
00110 self.tuck_arm_client.send_goal_and_wait(goal, rospy.Duration(30.0), rospy.Duration(5.0))
00111
00112 def navigate_to(self, nav_goal_pose):
00113 rospy.loginfo("navigating to %f %f" % (nav_goal_pose.pose.position.x,
00114 nav_goal_pose.pose.position.y))
00115 goal = MoveBaseGoal()
00116 goal.target_pose = nav_goal_pose
00117 self.move_base_client.send_goal_and_wait(goal, rospy.Duration(60*5), rospy.Duration(5))
00118
00119 def wait_for_gripper_wiggle(self, accel):
00120 """Waits for one year. accel is in m/s^2, normal values are 6 and 10"""
00121
00122 goal = PR2GripperEventDetectorGoal()
00123 goal.command.trigger_conditions = 4
00124 goal.command.acceleration_trigger_magnitude = accel
00125 goal.command.slip_trigger_magnitude = 0.008
00126 self.gripper_wiggle_detector_client.send_goal_and_wait(goal, rospy.Duration(3600*24*365), rospy.Duration(5.0))
00127
00128 def get_object(self):
00129 rospy.loginfo("getting object")
00130
00131 self.arm_mover.go('r', self.tuck_approach_pose, 1)
00132 self.arm_mover.go('r', self.accept_object_pose, 2)
00133
00134 object_gripped = False
00135 while not object_gripped:
00136
00137 self.arm_mover.open_right()
00138 rospy.sleep(2)
00139
00140 self.wait_for_gripper_wiggle(10)
00141
00142 self.arm_mover.close_right()
00143
00144 gripper_pos = self.arm_mover.joints['r_gripper_joint'].position
00145 if gripper_pos > 0.02:
00146 rospy.loginfo("gripper has object: %f", gripper_pos)
00147 object_gripped = True
00148 else:
00149 rospy.loginfo("gripper does not have object: %f", gripper_pos)
00150
00151 self.arm_mover.go('r', self.tucked_with_object_approach_pose, 2)
00152 self.arm_mover.go('r', self.tucked_with_object_pose, 1)
00153
00154 def give_object(self):
00155 rospy.loginfo("giving object")
00156
00157 self.arm_mover.go('r', self.tucked_with_object_approach_pose, 2)
00158
00159 self.arm_mover.go('r', self.accept_object_pose, 2) # give-object pose is the same as accept-object pose.
00160
00161 rospy.sleep(2)
00162
00163 self.wait_for_gripper_wiggle(5)
00164
00165 self.arm_mover.open_right()
00166 rospy.sleep(1)
00167
00168
00169
00170