simple_pick_and_place_example.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib
00003 roslib.load_manifest('pr2_tabletop_manipulation_gazebo_demo')
00004 import rospy
00005 from pr2_pick_and_place_demos.pick_and_place_manager import *
00006 from object_manipulator.convert_functions import *
00007 
00008 class SimplePickAndPlaceExample():
00009 
00010     def __init__(self):
00011 
00012         rospy.loginfo("initializing pick and place manager")
00013         self.papm = PickAndPlaceManager()
00014         rospy.loginfo("finished initializing pick and place manager")
00015 
00016 
00017     #pick up the nearest object to PointStamped target_point with whicharm 
00018     #(0=right, 1=left)
00019     def pick_up_object_near_point(self, target_point, whicharm):
00020 
00021         rospy.loginfo("moving the arms to the side")
00022         self.papm.move_arm_to_side(0)  #right arm
00023         self.papm.move_arm_to_side(1)  #left arm
00024 
00025         rospy.loginfo("pointing the head at the target point")
00026         self.papm.point_head(get_xyz(target_point.point),
00027                              target_point.header.frame_id)
00028 
00029         rospy.loginfo("detecting the table and objects")
00030         self.papm.call_tabletop_detection(take_static_collision_map = 1,
00031                              update_table = 1, clear_attached_objects = 1)
00032 
00033         rospy.loginfo("picking up the nearest object to the target point")
00034         success = self.papm.pick_up_object_near_point(target_point,
00035                                                       whicharm)
00036 
00037         if success:
00038             rospy.loginfo("pick-up was successful!  Moving arm to side")
00039             self.papm.move_arm_to_side(whicharm)
00040         else:
00041             rospy.loginfo("pick-up failed.")
00042 
00043         return success
00044 
00045 
00046     #place the object held in whicharm (0=right, 1=left) down in the 
00047     #place rectangle defined by place_rect_dims (x,y) 
00048     #and place_rect_center (PoseStamped)
00049     def place_object(self, whicharm, place_rect_dims, place_rect_center):
00050 
00051         self.papm.set_place_area(place_rect_center, place_rect_dims)
00052 
00053         rospy.loginfo("putting down the object in the %s gripper"\
00054                       %self.papm.arm_dict[whicharm])
00055         success = self.papm.put_down_object(whicharm,
00056                       max_place_tries = 25,
00057                       use_place_override = 1)
00058 
00059         if success:
00060             rospy.loginfo("place returned success")
00061         else:
00062             rospy.loginfo("place returned failure")
00063 
00064         return success
00065 
00066 
00067 if __name__ == "__main__":
00068     rospy.init_node('simple_pick_and_place_example')
00069     sppe = SimplePickAndPlaceExample()
00070 
00071     #adjust for your table 
00072     table_height = .50
00073 
00074     #.5 m in front of robot, centered
00075     target_point_xyz = [.7, 0, table_height]
00076     target_point = create_point_stamped(target_point_xyz, 'base_link')
00077     success = sppe.pick_up_object_near_point(target_point, 0)   #right arm
00078 
00079     if success:
00080 
00081         #square of size 30 cm by 30 cm
00082         place_rect_dims = [.06, .06]
00083 
00084         #.5 m in front of robot, to the right
00085         center_xyz = [.6, -.15, table_height]
00086 
00087         #aligned with axes of frame_id
00088         center_quat = [0,0,0,1]
00089         place_rect_center = create_pose_stamped(center_xyz+center_quat,
00090                                                     'base_link')
00091 
00092         sppe.place_object(0, place_rect_dims, place_rect_center)
00093 


pr2_tabletop_manipulation_gazebo_demo
Author(s): John Hsu
autogenerated on Mon Jan 6 2014 12:09:50