object_fetching.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 import random
00003 import sys
00004 
00005 import roslib; roslib.load_manifest("hrl_object_fetching")
00006 import rospy
00007 import actionlib
00008 
00009 from pr2_overhead_grasping.msg import *
00010 #from pr2_playpen.srv import *
00011 from hrl_lib.keyboard_input import KeyboardInput
00012 from pr2_overhead_grasping.helpers import log
00013 from tabletop_object_detector.srv import TabletopSegmentation
00014 from tabletop_object_detector.msg import TabletopDetectionResult
00015 
00016 ##
00017 # Uses the object_detection service detect objects on the table. Returns a list
00018 # of pairs [ [ x, y, z], rot ] which represent the centers and z orientation of
00019 # each object detected on the table.
00020 def detect_tabletop_objects():
00021     DETECT_ERROR = 0.
00022     #cbbf = ClusterBoundingBoxFinder(tf_listener=self.oger.cm.tf_listener)
00023     object_detector = rospy.ServiceProxy("/tabletop_segmentation", TabletopSegmentation)
00024     table = object_detector().table
00025     object_detector.close()
00026     return table
00027     #if detects.result != 4:
00028     #    err("Detection failed (err %d)" % (detects.result))
00029     #    return []
00030     #table_z = detects.table.pose.pose.position.z
00031     #objects = []
00032     #for cluster in detects.clusters:
00033     #    (object_points, 
00034     #     object_bounding_box_dims, 
00035     #     object_bounding_box, 
00036     #     object_to_base_link_frame, 
00037     #     object_to_cluster_frame) = cbbf.find_object_frame_and_bounding_box(cluster)
00038     #    # log("bounding box:", object_bounding_box)
00039     #    (object_pos, object_quat) = cf.mat_to_pos_and_quat(object_to_cluster_frame)
00040     #    angs = euler_from_quaternion(object_quat)
00041     #    log("angs:", angs)
00042     #    # position is half of height
00043     #    object_pos[2] = table_z + object_bounding_box[1][2] / 2. + DETECT_ERROR
00044     #    log("pos:", object_pos)
00045     #    log("table_z:", table_z)
00046     #    objects += [[object_pos, angs[2]]]
00047     #return objects
00048             
00049 
00050 if __name__ == '__main__':
00051     args = sys.argv
00052     rospy.init_node('object_fetching')
00053     print detect_tabletop_objects()
00054 #    ki = KeyboardInput()
00055 #    grasp_client = actionlib.SimpleActionClient('overhead_grasp', OverheadGraspAction)
00056 #    grasp_client.wait_for_server()
00057 #    grasp_setup_client = actionlib.SimpleActionClient('overhead_grasp_setup', OverheadGraspSetupAction)
00058 #    grasp_setup_client.wait_for_server()
00059 #    print "grasp_client ready"
00060 #    if args[1] == 'reg_test':
00061 #        results_dict = {}
00062 #        ki.kbhit()
00063 #        while not rospy.is_shutdown():
00064 #            goal = OverheadGraspSetupGoal()
00065 #            grasp_setup_client.send_goal(goal)
00066 #            #grasp_setup_client.wait_for_result()
00067 #            rospy.sleep(1.0)
00068 #
00069 #            print "Grasp started"
00070 #            goal = OverheadGraspGoal()
00071 #            goal.is_grasp = True
00072 #            goal.grasp_type=OverheadGraspGoal.VISION_GRASP
00073 #            goal.x = 0.5 + random.uniform(-0.1, 0.1)
00074 #            goal.y = 0.0 + random.uniform(-0.1, 0.1)
00075 #            grasp_client.send_goal(goal)
00076 #            grasp_client.wait_for_result()
00077 #            result = grasp_client.get_result()
00078 #            goal = OverheadGraspGoal()
00079 #            if result.grasp_result == "Table collision" or True:
00080 #                goal.is_grasp = False
00081 #                goal.grasp_type=OverheadGraspGoal.MANUAL_GRASP
00082 #                goal.x = 0.5 + random.uniform(-0.1, 0.1)
00083 #                goal.y = 0.0 + random.uniform(-0.1, 0.1)
00084 #                grasp_client.send_goal(goal)
00085 #                grasp_client.wait_for_result()
00086 #                result = grasp_client.get_result()
00087 #            if result.grasp_result not in results_dict:
00088 #                results_dict[result.grasp_result] = 0
00089 #            results_dict[result.grasp_result] += 1
00090 #
00091 #            print results_dict
00092 #            try:
00093 #                print float(results_dict["No collision"]) / results_dict["Regular collision"]
00094 #            except:
00095 #                pass
00096 #    
00097 #    elif args[1] == 'playpen_demo':
00098 #        rospy.wait_for_service('conveyor')
00099 #        conveyor = rospy.ServiceProxy('conveyor', Conveyor)
00100 #        print "conveyor ready"
00101 #        rospy.wait_for_service('playpen')
00102 #        playpen = rospy.ServiceProxy('playpen', Playpen)
00103 #        print "playpen ready"
00104 #        print "waiting for setup"
00105 #        rospy.sleep(20.0)
00106 #        while not rospy.is_shutdown():
00107 #            conveyor(0.10 * 2.)
00108 #
00109 #            print "Grasp started"
00110 #            goal = OverheadGraspGoal()
00111 #            goal.is_grasp = True
00112 #            goal.grasp_type=OverheadGraspGoal.VISION_GRASP
00113 #            goal.x = 0.5
00114 #            goal.y = 0.0
00115 #            grasp_client.send_goal(goal)
00116 #            grasp_client.wait_for_result()
00117 #            result = grasp_client.get_result()
00118 #            goal = OverheadGraspGoal()
00119 #            goal.is_grasp = False
00120 #            goal.grasp_type=OverheadGraspGoal.MANUAL_GRASP
00121 #            goal.x = 0.5 + random.uniform(-0.1, 0.1)
00122 #            goal.y = 0.0 + random.uniform(-0.1, 0.1)
00123 #            grasp_client.send_goal(goal)
00124 #            grasp_client.wait_for_result()
00125 #            result = grasp_client.get_result()
00126 #
00127 #            # do playpen stuff
00128 #
00129 #            log("Opening trap door")
00130 #            playpen(1)
00131 #            rospy.sleep(0.2)
00132 #            log("Closing trap door")
00133 #            playpen(0)
00134 #            rospy.sleep(0.2)
00135 
00136 
00137 


hrl_object_fetching
Author(s): Kelsey Hawkins. Advisor: Prof. Charlie Kemp. Healthcare Robotics Lab, Georgia Tech
autogenerated on Wed Nov 27 2013 11:33:13