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 import roslib
00031 roslib.load_manifest('pr2_playpen')
00032 import rospy
00033 from object_manipulator.convert_functions import *
00034 from pr2_playpen.srv import Playpen
00035 from pr2_playpen.srv import Conveyor
00036 from pr2_overhead_grasping.msg import *
00037 import math
00038 import numpy as np
00039
00040 class SimplePickAndPlaceExample():
00041
00042 def __init__(self):
00043
00044 rospy.loginfo("initializing overhead grasping")
00045 grasp_client = actionlib.SimpleActionClient('overhead_grasp', OverheadGraspAction)
00046 grasp_client.wait_for_server()
00047 grasp_setup_client = actionlib.SimpleActionClient('overhead_grasp_setup', OverheadGraspSetupAction)
00048 grasp_setup_client.wait_for_server()
00049 rospy.loginfo("finished initializing overhead grasping")
00050 rospy.wait_for_service('playpen')
00051 rospy.wait_for_service('conveyor')
00052 self.playpen = rospy.ServiceProxy('playpen', Playpen)
00053 self.conveyor = rospy.ServiceProxy('conveyor', Conveyor)
00054 self.objects_dist = [.135, .26-.135, .405-.26, .545-.405,
00055 .70-.545, .865-.70, .995-.865, 1.24-.995]
00056 self.tries = 0
00057 self.successes = 0
00058
00059
00060 def pick_up_object_near_point(self, target_point, whicharm):
00061
00062 rospy.loginfo("moving the arms to the side")
00063 setup_goal = OverheadGraspSetupGoal()
00064 setup_goal.disable_head = True
00065 grasp_setup_client.send_goal(setup_goal)
00066 rospy.sleep(1.0)
00067
00068 goal = OverheadGraspGoal()
00069 goal.grasp_type = OverheadGraspGoal.VISION_GRASP
00070 goal.x = target_point[0]
00071 goal.y = target_point[1]
00072 grasp_client.send_goal(goal)
00073 grasp_client.wait_for_result()
00074
00075
00076 success = True
00077
00078 if success:
00079 rospy.loginfo("pick-up was successful! Moving arm to side")
00080 self.papm.move_arm_to_side(whicharm)
00081 else:
00082 rospy.loginfo("pick-up failed.")
00083
00084 return success
00085
00086
00087
00088
00089
00090 def place_object(self, whicharm, target_point):
00091
00092 self.papm.set_place_area(place_rect_center, place_rect_dims)
00093
00094 rospy.loginfo("putting down the object in the %d gripper" % whicharm)
00095
00096 goal = OverheadGraspGoal()
00097 goal.grasp_type = OverheadGraspGoal.MANUAL_GRASP
00098 goal.x = target_point[0]
00099 goal.y = target_point[1]
00100 grasp_client.send_goal(goal)
00101 grasp_client.wait_for_result()
00102
00103 if success:
00104 rospy.loginfo("place returned success")
00105 else:
00106 rospy.loginfo("place returned failure")
00107
00108 return success
00109
00110
00111 if __name__ == "__main__":
00112 rospy.init_node('simple_pick_and_place_example')
00113 sppe = SimplePickAndPlaceExample()
00114
00115
00116
00117 table_height = 0.529
00118
00119
00120
00121
00122
00123 target_point_xyz = [.625, 0, table_height]
00124 target_point = create_point_stamped(target_point_xyz, 'base_link')
00125 arm = 0
00126
00127 for i in xrange(len(sppe.objects_dist)):
00128 sppe.playpen(0)
00129 sppe.conveyor(sppe.objects_dist[i])
00130
00131 while sppe.tries<2:
00132 print "arm is ", arm
00133
00134 success = sppe.pick_up_object_near_point(target_point_xyz, arm)
00135
00136 if success:
00137 sppe.successes=sppe.successes + 1
00138
00139 place_rect_dims = [.1, .1]
00140
00141
00142
00143 radius = np.random.uniform(0,0.20, 1)[0]
00144 angle = np.random.uniform(0, 2*math.pi, 1)[0]
00145 center_xyz = [.625+math.cos(angle)*radius, math.sin(angle)*radius, table_height+.2]
00146
00147 sppe.place_object(arm, center_xyz)
00148
00149 arm = arm.__xor__(1)
00150 sppe.tries = sppe.tries+1
00151
00152 sppe.playpen(1)
00153 sppe.successes = 0
00154 sppe.tries = 0
00155
00156