manager.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 '''
4 Copyright (c) 2016, Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Karrenbauer Oliver, Marek Felix, Meissner Pascal, Stroh Daniel, Trautmann Jeremias
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8 
9 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10 
11 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 '''
17 
18 import roslib
19 import rospy
20 import recognition_for_grasping.srv
21 from asr_msgs.msg import AsrObject
22 from asr_world_model.srv import PushFoundObject, PushFoundObjectList
23 import asr_aruco_marker_recognition.srv
24 import asr_fake_object_recognition.srv
25 from asr_world_model.srv import GetRecognizerName
26 import asr_descriptor_surface_based_recognition.srv
27 
28 
30 
31  def __init__(self):
32  pass
33 
34  def start_recognizers_descriptor(self, search_objects):
35  try:
36  rospy.wait_for_service(
37  '/asr_descriptor_surface_based_recognition/get_recognizer',
38  timeout=3)
39  descriptor_recognizer = rospy.ServiceProxy(
40  '/asr_descriptor_surface_based_recognition/get_recognizer',
41  asr_descriptor_surface_based_recognition.srv.GetRecognizer)
42  except (rospy.exceptions.ROSException, rospy.ServiceException) as e:
43  rospy.logwarn("Service error with descriptor recognizer")
44  return 'aborted'
45  descriptor_recognizer(search_objects, 1, False)
46  rospy.loginfo('Detection started for ' + str(search_objects))
47  return 'succeeded'
48 
49  def start_markers(self):
50  try:
51  rospy.wait_for_service(
52  '/asr_aruco_marker_recognition/get_recognizer',
53  timeout=3)
54  marker_recognizer = rospy.ServiceProxy(
55  '/asr_aruco_marker_recognition/get_recognizer',
56  asr_aruco_marker_recognition.srv.GetRecognizer)
57  marker_recognizer()
58  except (rospy.exceptions.ROSException, rospy.ServiceException) as e:
59  rospy.logwarn("Service error with marker recognizer")
60  return 'aborted'
61  rospy.loginfo('Marker recognition started.')
62  return 'succeeded'
63 
64  def start_recognizers_rfg(self, search_objects, type):
65  recognizer = None
66 
67  # initialize recognition manager
68  try:
69  rospy.wait_for_service('/recognition_manager/get_recognizer',
70  timeout=2)
71  recognizer = rospy.ServiceProxy(
72  '/recognition_manager/get_recognizer',
73  recognition_for_grasping.srv.GetRecognizer)
74  except (rospy.exceptions.ROSException, rospy.ServiceException) as e:
75  rospy.logwarn("Service error with recognition manager")
76  return 'aborted'
77 
78  # start the recognizers
79  # marker recognizer does not have to be started, it's looking for all
80  # object
81  recognizer(str(search_objects), str(type), False)
82  rospy.loginfo('Detection started for ' + str(search_objects))
83  return 'succeeded'
84 
85  def stop_recognizers_descriptor(self, search_objects):
86  release_descriptor_recognizer = None
87  try:
88  release_descriptor_recognizer = rospy.ServiceProxy(
89  '/asr_descriptor_surface_based_recognition/release_recognizer',
90  asr_descriptor_surface_based_recognition.srv.ReleaseRecognizer)
91  except rospy.ServiceException, e:
92  rospy.logwarn("Error calling the release recognizer services for descriptor recognition.")
93  return 'aborted'
94  release_descriptor_recognizer(search_objects)
95  rospy.loginfo(str(search_objects)+" released.")
96  return 'succeeded'
97 
99  clear_all_descriptor_recognizers = None
100  try:
101  clear_all_descriptor_recognizers = rospy.ServiceProxy(
102  '/asr_descriptor_surface_based_recognition/clear_all_recognizers',
103  asr_descriptor_surface_based_recognition.srv.ClearAllRecognizers)
104  except rospy.ServiceException, e:
105  rospy.logwarn("Error calling the clear all recognizers service for descriptor recognition.")
106  return 'aborted'
107  clear_all_descriptor_recognizers()
108  rospy.loginfo("All descriptor recognizers released.")
109  return 'succeeded'
110 
111  def stop_recognizers_rfg(self, search_objects, type):
112  release_recognizer = None
113  try:
114  release_recognizer = rospy.ServiceProxy(
115  '/recognition_manager/release_recognizer',
116  recognition_for_grasping.srv.ReleaseRecognizer)
117  except rospy.ServiceException, e:
118  rospy.logwarn("Error calling the release recognizer services for recognition manager.")
119  return 'aborted'
120  # release recognizer
121  release_recognizer(str(search_objects), str(type), "/stereo/objects")
122  rospy.loginfo(str(search_objects)+" released.")
123  return 'succeeded'
124 
126  clear_all_recognizers = None
127  try:
128  clear_all_recognizers = rospy.ServiceProxy(
129  '/recognition_manager/clear_all_recognizers',
130  recognition_for_grasping.srv.ClearAllRecognizers)
131  except rospy.ServiceException, e:
132  rospy.logwarn("Error calling the clear all recognizers service for recognition manager.")
133  return 'aborted'
134  # clear all recognizers
135  clear_all_recognizers("/stereo/objects")
136  rospy.loginfo("All rfg recognizers released.")
137  return 'succeeded'
138 
139  def stop_markers(self):
140  try:
141  release_marker_recognizer = rospy.ServiceProxy(
142  '/asr_aruco_marker_recognition/release_recognizer',
143  asr_aruco_marker_recognition.srv.ReleaseRecognizer)
144  except rospy.ServiceException, e:
145  rospy.logwarn("Error calling the release recognizer services for marker recognition.")
146  return 'aborted'
147  release_marker_recognizer()
148  rospy.loginfo('Marker recognition stopped.')
149  return 'succeeded'
150 
151 def main():
152  rospy.init_node('recognition_manual_manager')
153  manager = ObjectDetectorsManager()
154  while not rospy.is_shutdown():
155  command_string = raw_input('Enter a valid command, f.e start,Smacks,textured :')
156  command_array = command_string.split(',')
157 
158  if command_array[0] == 'start':
159  if command_array[1] == 'markers':
160  manager.start_markers()
161  elif command_array[2] == 'descriptor':
162  manager.start_recognizers_descriptor(command_array[1])
163  elif command_array[2] in 'textured segmentable':
164  manager.start_recognizers_rfg(command_array[1],command_array[2])
165  else:
166  rospy.loginfo('invalid command')
167 
168  elif command_array[0] == 'stop':
169  if command_array[1] == 'markers':
170  manager.stop_markers()
171  elif command_array[1] == 'all':
172  manager.stop_all_recognizers_rfg()
173  manager.stop_all_recognizers_descriptor()
174  manager.stop_markers()
175  elif command_array[2] == 'descriptor':
176  manager.stop_recognizers_descriptor(command_array[1])
177  elif command_array[2] in 'textured segmentable':
178  manager.stop_recognizers_rfg(command_array[1],command_array[2])
179  else:
180  rospy.loginfo('invalid command')
181 
182  else:
183  rospy.loginfo('invalid command')
184 
185  rospy.spin()
186 
187 if __name__ == '__main__':
188  main()
def main()
Definition: manager.py:151
def stop_recognizers_rfg(self, search_objects, type)
Definition: manager.py:111
def start_recognizers_descriptor(self, search_objects)
Definition: manager.py:34
def stop_all_recognizers_descriptor(self)
Definition: manager.py:98
def stop_recognizers_descriptor(self, search_objects)
Definition: manager.py:85
def stop_all_recognizers_rfg(self)
Definition: manager.py:125
def start_recognizers_rfg(self, search_objects, type)
Definition: manager.py:64


asr_resources_for_active_scene_recognition
Author(s): Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Karrenbauer Oliver, Marek Felix, Meißner Pascal, Stroh Daniel, Trautmann Jeremias
autogenerated on Tue Feb 18 2020 03:14:15