Go to the documentation of this file.00001
00002
00003 import roslib;
00004 import sys
00005 roslib.load_manifest('pr2_gripper_grasp_planner_cluster')
00006 import rospy
00007 from object_manipulation_msgs.srv import GraspPlanning, GraspPlanningResponse
00008 from object_manipulation_msgs.msg import GraspableObject
00009 from sensor_msgs.msg import PointCloud
00010
00011 a = 9
00012
00013 def service_caller(pc):
00014 rospy.wait_for_service('plan_point_cluster_grasp')
00015 try:
00016 myproxy = rospy.ServiceProxy('plan_point_cluster_grasp', GraspPlanning)
00017 go = GraspableObject()
00018 go.cluster = pc
00019 go.reference_frame_id = "/base_link"
00020 rospy.loginfo(rospy.get_name()+"I used a pointcloud with %d points as cluster",len(go.cluster.points))
00021
00022 myresponse = myproxy(target=go)
00023 rospy.loginfo(rospy.get_name()+"I got a %d grasps",len(myresponse.grasps))
00024 print myresponse
00025
00026
00027
00028
00029 return myresponse
00030 except rospy.ServiceException, e:
00031 print "Service call failed: %s"%e
00032
00033 def callback(pc):
00034 global a
00035 rospy.loginfo(rospy.get_name()+"Received a pointcloud with %d points",len(pc.points))
00036 if len(pc.points) > 10:
00037 a = service_caller(pc)
00038 rospy.signal_shutdown("done")
00039
00040
00041 if __name__ == '__main__':
00042 rospy.init_node('grasper')
00043 rospy.loginfo(rospy.get_name()+" subscribing to pointclouds, requesting grasp plans for each one received")
00044 rospy.Subscriber("/handle_segment", PointCloud, callback)
00045 rospy.loginfo(rospy.get_name()+" ready")
00046 rospy.spin()
00047