place_obj.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 
00003 import numpy as np
00004 
00005 import roslib; roslib.load_manifest('hrl_clickable_behaviors')
00006 import rospy
00007 import std_srvs.srv
00008 import actionlib
00009 from tf.listener import TransformListener
00010 
00011 from hrl_clickable_world.srv import PerceiveButtons, ButtonAction, DisplayButtons
00012 from hrl_clickable_world.srv import PerceiveButtonsResponse, ButtonActionResponse
00013 from geometry_msgs.msg import Point
00014 from visualization_msgs.msg import Marker
00015 
00016 from pr2_grasp_behaviors.msg import OverheadGraspSetupAction, OverheadGraspSetupGoal
00017 from pr2_grasp_behaviors.msg import OverheadGraspAction, OverheadGraspGoal
00018 from hrl_table_detect.srv import ObjectButtonDetect, SegmentSurfaces
00019 
00020 class PlaceObject:
00021     def __init__(self):
00022         self.arm = rospy.get_param("arm", "r")
00023         self.tl = TransformListener()
00024         self.perception_srv = rospy.Service("/clickable_world/place_table_perceive",
00025                                             PerceiveButtons,
00026                                             self.do_perception)
00027         self.action_srv = rospy.Service("/clickable_world/place_object",
00028                                         ButtonAction,
00029                                         self.do_action)
00030 
00031         self.pc_capture_srv = rospy.ServiceProxy("/table_detection/surf_seg_capture_pc",
00032                                                  std_srvs.srv.Empty)
00033         self.table_seg_srv = rospy.ServiceProxy("/table_detection/segment_surfaces",
00034                                                 SegmentSurfaces)
00035         self.grasp_client = actionlib.SimpleActionClient(self.arm + '_overhead_grasp', OverheadGraspAction)
00036         self.grasp_client.wait_for_server()
00037         self.grasp_setup_client = actionlib.SimpleActionClient(self.arm + '_overhead_grasp_setup', OverheadGraspSetupAction)
00038         self.grasp_setup_client.wait_for_server()
00039 
00040     def do_perception(self, req):
00041         rospy.loginfo("[place_object] Perceiving table...")
00042         # capture a few clouds
00043         rate = rospy.Rate(5)
00044         for i in range(5):
00045             self.pc_capture_srv()
00046             rate.sleep()
00047             
00048         # segment surfaces
00049         self.surfaces = self.table_seg_srv().surfaces
00050         for i in range(len(self.surfaces)):
00051             self.surfaces[i].color.r = 256
00052             self.surfaces[i].color.g = 0
00053             self.surfaces[i].color.b = 256
00054             self.surfaces[i].color.a = 256
00055 
00056         resp = PerceiveButtonsResponse()
00057         resp.buttons = self.surfaces
00058         return resp
00059 
00060     def do_action(self, req):
00061         rospy.loginfo("[place_object] Table clicked, placing object...")
00062         # put 3d pt in grasping frame
00063         req.pixel3d.header.stamp = rospy.Time(0)
00064         place_pt = self.tl.transformPoint("/torso_lift_link", req.pixel3d)
00065 
00066         # move to place setup position
00067         setup_goal = OverheadGraspSetupGoal()
00068         setup_goal.disable_head = False
00069         setup_goal.open_gripper = False
00070         self.grasp_setup_client.send_goal(setup_goal)
00071         self.grasp_setup_client.wait_for_result()
00072 
00073         ############################################################
00074         # Creating place goal
00075         grasp_goal = OverheadGraspGoal()
00076         grasp_goal.is_grasp = False
00077         grasp_goal.disable_head = False
00078         grasp_goal.disable_coll = False
00079         grasp_goal.grasp_type=OverheadGraspGoal.MANUAL_GRASP
00080         grasp_goal.x = place_pt.point.x
00081         grasp_goal.y = place_pt.point.y
00082         grasp_goal.behavior_name = "overhead_grasp"
00083         grasp_goal.sig_level = 0.999
00084         ############################################################
00085 
00086         # place object
00087         self.grasp_client.send_goal(grasp_goal)
00088         self.grasp_client.wait_for_result()
00089         result = self.grasp_client.get_result()
00090         rospy.loginfo("[place_object] Place result: %s" % result)
00091         obj_in_hand = result.grasp_result == "Object placed"
00092         
00093         # go back to grasp setup
00094         setup_goal.open_gripper = True
00095         self.grasp_setup_client.send_goal(setup_goal)
00096         self.grasp_setup_client.wait_for_result()
00097 
00098         return ButtonActionResponse()
00099 
00100 def main():
00101     rospy.init_node('place_object')
00102     po = PlaceObject()
00103     rospy.spin()
00104 
00105 if __name__ == "__main__":
00106     main()


hrl_clickable_behaviors
Author(s): Author: Kelsey Hawkins, Advisor: Prof. Charlie Kemp (Healthcare Robotics Lab at Georgia Tech)
autogenerated on Wed Nov 27 2013 12:24:35