Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 import roslib
00059 roslib.load_manifest('srs_grasping')
00060 import time
00061 import rospy
00062
00063 import grasping_functions
00064 from srs_grasping.srv import *
00065 from srs_msgs.msg import GraspingErrorCodes
00066
00067
00068 class get_db_grasps():
00069
00070 def __init__(self):
00071 print "-------------------------------------------------------------------------";
00072 rospy.loginfo("Waiting /get_model_grasp service...");
00073 rospy.wait_for_service('/get_model_grasp');
00074 rospy.loginfo("/get_db_grasps service is ready.");
00075
00076
00077 def get_db_grasps(self, server_goal):
00078 x = time.time();
00079 rospy.loginfo("/get_db_grasps service has been called...");
00080
00081
00082 server_result = GetDBGraspsResponse();
00083 server_result.error_code.val = 0;
00084 server_result.grasp_configuration = [];
00085
00086 resp = grasping_functions.databaseutils.get_grasps(server_goal.object_id);
00087 if resp < 0:
00088 resp2 = grasping_functions.openraveutils.generator(server_goal.object_id);
00089 if resp2 is GraspingErrorCodes.SUCCESS:
00090 resp_aux = grasping_functions.databaseutils.get_grasps(server_goal.object_id);
00091 if resp_aux < 0:
00092 server_result.error_code.val = resp_aux;
00093 else:
00094 server_result.error_code.val = GraspingErrorCodes.SUCCESS;
00095 server_result.grasp_configuration = resp_aux.grasp_configuration;
00096 else:
00097 server_result.error_code.val = resp2;
00098 else:
00099 server_result.error_code.val = GraspingErrorCodes.SUCCESS;
00100 server_result.grasp_configuration = resp.grasp_configuration;
00101
00102 print "Time employed: " + str(time.time() - x);
00103 print "---------------------------------------";
00104 return server_result;
00105
00106
00107 def get_db_grasps_server(self):
00108 s = rospy.Service('/get_db_grasps', GetDBGrasps, self.get_db_grasps);
00109
00110
00111 if __name__ == '__main__':
00112 rospy.init_node('get_db_grasps')
00113 SCRIPT = get_db_grasps()
00114 SCRIPT.get_db_grasps_server();
00115 rospy.spin()