show_grasps_or_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 cob_grasp_generation.msg
22 from cob_grasp_generation import or_grasp_generation, grasp_query_utils
23 
24 class ShowGraspsOrServer(object):
25 
26  def __init__(self):
27  self.orgg = or_grasp_generation.ORGraspGeneration()
28 
29  self._as_show = actionlib.SimpleActionServer('show_grasps_or', cob_grasp_generation.msg.ShowGraspsAction, execute_cb=self.show_cb, auto_start = False)
30  self._as_show.start()
31 
32  print("ShowGraspsOrServer: action started...")
33 
34 
35  def show_cb(self, goal):
36  success = False
37 
38  rospy.loginfo('Show grasp %i for object %s using gripper_type %s' % (goal.grasp_id, goal.object_name, goal.gripper_type))
39 
40  if grasp_query_utils.check_database(goal.object_name, goal.gripper_type):
41  self.orgg.setup_environment(goal.object_name, goal.gripper_type, viewer=True)
42  rospy.loginfo('Display Grasp. Object: %s | ID: %i' % (goal.object_name, goal.grasp_id))
43  self.orgg.show_grasp(goal.object_name, goal.gripper_type, goal.grasp_id, goal.sort_by_quality)
44  success = True
45  else:
46  rospy.logerr('GraspTable for Object %s does not exist!' % (goal.object_name))
47 
48  result = cob_grasp_generation.msg.ShowGraspsResult()
49  result.success = success
50 
51  if success:
52  rospy.loginfo('Show: Succeeded')
53  self._as_show.set_succeeded(result)
54  else:
55  rospy.logwarn('Show: Failed')
56  self._as_show.set_aborted(result)
57 
58 
59 if __name__ == '__main__':
60  rospy.init_node('show_grasps_or_server')
62  rospy.spin()


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