generate_grasps_server.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import rospy
19 
20 import actionlib
21 import moveit_msgs.msg
22 import cob_grasp_generation.msg
23 from cob_grasp_generation import or_grasp_generation, grasp_query_utils
24 
25 class GenerateGraspsServer(object):
26 
27  def __init__(self):
28  self.orgg = or_grasp_generation.ORGraspGeneration()
29 
30  self._as_generate = actionlib.SimpleActionServer('generate_grasps', cob_grasp_generation.msg.GenerateGraspsAction, execute_cb=self.generate_cb, auto_start = False)
31  self._as_generate.start()
32 
33  print("GenerateGraspsServer: action started...")
34 
35  def generate_cb(self, goal):
36  success = False
37  num_grasps = 0
38 
39  rospy.loginfo('Generating grasps for object %s using gripper_type %s' % (goal.object_name, goal.gripper_type))
40 
41  if grasp_query_utils.check_database(goal.object_name, goal.gripper_type):
42  rospy.logwarn('Grasps for object %s exist in the database.', goal.object_name)
43  success = False
44  else:
45  self.orgg.setup_environment(goal.object_name, goal.gripper_type, goal.viewer)
46  rospy.loginfo('GraspTable for object %s does not exist. Now planning Grasps for the object',goal.object_name)
47  num_grasps = self.orgg.generate_grasps(goal.object_name, goal.gripper_type, goal.replan)
48  if (num_grasps > 0):
49  success = True
50 
51  result = cob_grasp_generation.msg.GenerateGraspsResult()
52  result.success = success
53  result.num_grasps = num_grasps
54 
55  if success:
56  rospy.loginfo('Generate: Succeeded')
57  self._as_generate.set_succeeded(result)
58  else:
59  rospy.logwarn('Generate: Failed')
60  self._as_generate.set_aborted(result)
61 
62 
63 if __name__ == '__main__':
64  rospy.init_node('generate_grasps_server')
66  rospy.spin()


cob_grasp_generation
Author(s): Witalij Siebert, Felix Messmer
autogenerated on Sun Dec 6 2020 03:25:46