overhead_manipulation.py
Go to the documentation of this file.
00001 #
00002 # Copyright (c) 2009, Georgia Tech Research Corporation
00003 # All rights reserved.
00004 #
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are met:
00007 #     * Redistributions of source code must retain the above copyright
00008 #       notice, this list of conditions and the following disclaimer.
00009 #     * Redistributions in binary form must reproduce the above copyright
00010 #       notice, this list of conditions and the following disclaimer in the
00011 #       documentation and/or other materials provided with the distribution.
00012 #     * Neither the name of the Georgia Tech Research Corporation nor the
00013 #       names of its contributors may be used to endorse or promote products
00014 #       derived from this software without specific prior written permission.
00015 #
00016 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00017 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00020 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00021 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00022 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00023 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00024 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 #
00027 #Based on some code by Kaijen, modified heavily by Marc Killpack
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     #pick up the nearest object to PointStamped target_point with whicharm 
00059     #(0=right, 1=left)
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         # TODO add success checking
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     #place the object held in whicharm (0=right, 1=left) down in the 
00088     #place rectangle defined by place_rect_dims (x,y) 
00089     #and place_rect_center (PoseStamped)
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     #adjust for your table 
00117     table_height = 0.529
00118 
00119 ############here is where we put the loop and service calls to know if successful or not...., when done write success rate/statistics to pkl file
00120 ############and call service to advance to next object, etc.
00121 
00122     #.5 m in front of robot, centered
00123     target_point_xyz = [.625, 0, table_height]   #this is currently an approximation/hack should us ar tag
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 #            print "target _point is ", target_point.x
00134             success = sppe.pick_up_object_near_point(target_point_xyz, arm)   #right arm
00135 
00136             if success:
00137                 sppe.successes=sppe.successes + 1
00138                 #square of size 30 cm by 30 cm
00139                 place_rect_dims = [.1, .1]
00140 
00141                 
00142                 #.5 m in front of robot, to the right
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 #    sppe.playpen(0)


pr2_playpen
Author(s): Marc Killpack / mkillpack3@gatech.edu, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 12:18:32