grasp_obj_button.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
00019 
00020 class GraspObjButton:
00021     def __init__(self):
00022         self.arm = rospy.get_param("arm", "r")
00023         self.tl = TransformListener()
00024         self.perception_srv = rospy.Service("/clickable_world/detect_objects",
00025                                             PerceiveButtons,
00026                                             self.do_perception)
00027         self.action_srv = rospy.Service("/clickable_world/grasp_object",
00028                                         ButtonAction,
00029                                         self.do_action)
00030 
00031         self.obj_seg_srv = rospy.ServiceProxy("/object_button_detect",
00032                                               ObjectButtonDetect)
00033         self.grasp_client = actionlib.SimpleActionClient(self.arm + '_overhead_grasp', OverheadGraspAction)
00034         self.grasp_client.wait_for_server()
00035         self.grasp_setup_client = actionlib.SimpleActionClient(self.arm + '_overhead_grasp_setup', OverheadGraspSetupAction)
00036         self.grasp_setup_client.wait_for_server()
00037 
00038     def do_perception(self, req):
00039         rospy.loginfo("[grasp_obj_button] Perceiving object buttons...")
00040         # perceive object on table
00041         self.objects = self.obj_seg_srv().objects
00042         for i in range(len(self.objects)):
00043             self.objects[i].color.r = 256
00044             self.objects[i].color.g = 0
00045             self.objects[i].color.b = 0
00046             self.objects[i].color.a = 256
00047 
00048         # return object buttons
00049         resp = PerceiveButtonsResponse()
00050         resp.buttons = self.objects
00051         return resp
00052 
00053     def do_action(self, req):
00054         rospy.loginfo("[grasp_obj_button] Table clicked, grasping object...")
00055         # put 3d pt in grasping frame
00056         req.pixel3d.header.stamp = rospy.Time(0)
00057         grasp_pt = self.tl.transformPoint("/torso_lift_link", req.pixel3d)
00058 
00059         # move to grasp setup position
00060         setup_goal = OverheadGraspSetupGoal()
00061         setup_goal.disable_head = False
00062         setup_goal.open_gripper = True
00063         self.grasp_setup_client.send_goal(setup_goal)
00064         self.grasp_setup_client.wait_for_result()
00065 
00066         ############################################################
00067         # Creating grasp goal
00068         grasp_goal = OverheadGraspGoal()
00069         grasp_goal.is_grasp = True
00070         grasp_goal.disable_head = False
00071         grasp_goal.disable_coll = False
00072         grasp_goal.grasp_type=OverheadGraspGoal.VISION_GRASP
00073         grasp_goal.x = grasp_pt.point.x
00074         grasp_goal.y = grasp_pt.point.y
00075         grasp_goal.behavior_name = "overhead_grasp"
00076         grasp_goal.sig_level = 0.999
00077         ############################################################
00078 
00079         # grasp object
00080         self.grasp_client.send_goal(grasp_goal)
00081         self.grasp_client.wait_for_result()
00082         result = self.grasp_client.get_result()
00083         rospy.loginfo("[grasp_obj_button] Grasp result: %s" % result)
00084         obj_in_hand = result.grasp_result == "Object grasped"
00085 
00086         # go back to grasp setup
00087         setup_goal.open_gripper = False
00088         self.grasp_setup_client.send_goal(setup_goal)
00089         self.grasp_setup_client.wait_for_result()
00090 
00091         return ButtonActionResponse()
00092 
00093 def main():
00094     rospy.init_node('grasp_obj_button')
00095     gob = GraspObjButton()
00096     rospy.spin()
00097 
00098 if __name__ == "__main__":
00099     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