4 Copyright (c) 2016, Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Marek Felix, Meissner Pascal, Trautmann Jeremias, Wittenbeck Valerij 8 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 10 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 12 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. 14 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. 16 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. 29 from actionlib
import *
31 import sensor_msgs.msg
33 from indirect_search.indirect_search_sm
import IndirectSearchStateMachine
34 from direct_search.direct_search_sm
import DirectSearchStateMachine
35 from random_search.random_search_sm
import RandomSearchStateMachine
36 from cropbox_search.cropbox_search_sm
import CropBoxSearchStateMachine
37 from cropbox_search.cropbox_record_sm
import CropBoxRecordStateMachine
38 from direct_search.grid_init_record_sm
import GridInitRecordStateMachine
40 from common.state_acquisition
import GetRobotState
44 from os.path
import expanduser
45 from asr_fake_object_recognition.srv
import ClearAllRecognizers
as FakeObjectClearAllRecognizers
46 from asr_descriptor_surface_based_recognition.srv
import ClearAllRecognizers
as DescriptorSurfaceClearAllRecognizers
47 from asr_aruco_marker_recognition.srv
import ReleaseRecognizer
48 from asr_visualization_server.srv
import DrawAllModelsMild
63 Start automata and introspection server 67 rospy.init_node(
'scene_exploration_sm')
77 rospy.on_shutdown(shutdown_hook)
83 __builtin__.evaluation =
False 85 log_dir = common.init.create_log_folder()
86 __builtin__.log_dir = log_dir
89 rosbag_proc = common.init.start_rosbag(log_dir)
91 rospy.loginfo(
"Waiting for visualization_server-service to become available")
92 rospy.wait_for_service(
'visualization/draw_all_models_mild')
94 draw_all_models_mild = rospy.ServiceProxy(
'visualization/draw_all_models_mild', DrawAllModelsMild)
95 draw_all_models_mild()
96 rospy.loginfo(
"Publishing room model")
97 except rospy.ServiceException, e:
98 rospy.logwarn(
"Error calling the draw all models mild service")
104 initial_objects = common.init.get_initial_objects()
105 rospy.loginfo(
"initial_objects: " + str(initial_objects))
109 with open(__builtin__.log_dir +
'/log.csv',
'a')
as log:
110 logwriter = csv.writer(log, delimiter=
' ',
111 quotechar=
'|', quoting=csv.QUOTE_MINIMAL)
113 logwriter.writerow([time.time()])
115 rospy.loginfo(
"Initial robot state:\n" + str(
GetRobotState().get_robot_state()))
118 rospy.loginfo(
"We are running our state machine in the following mode:")
120 mode = rospy.get_param(
"/scene_exploration_sm/mode")
121 if mode
is not 1
and mode
is not 2
and mode
is not 3
and mode
is not 4
and mode
is not 5
and mode
is not 6
and mode
is not 7:
123 rospy.logwarn(
"Unknown mode was set in params -> informative search will be taken as default")
124 rospy.set_param(
"/scene_exploration_sm/mode", 2)
129 rospy.loginfo(
"Direct Search mode as stand alone")
132 smach_thread = threading.Thread(target = sm_direct_search_as_standalone.execute)
134 rospy.loginfo(
"Indirect Search mode as stand alone")
137 smach_thread = threading.Thread(target=sm_indirect_search.execute)
139 rospy.loginfo(
"Object Search mode")
142 sm_object_search = smach.StateMachine(outcomes=[
'aborted',
144 'found_all_required_scenes',
145 'nowhere_left_to_search'])
147 with sm_object_search:
148 smach.StateMachine.add(
'OBJECT_SEARCH_INIT',
150 transitions={
'succeeded':
'DIRECT_SEARCH',
151 'aborted':
'aborted'})
153 smach.StateMachine.add(
'DIRECT_SEARCH',
155 transitions={
'found_objects':
'INDIRECT_SEARCH',
157 'nowhere_left_to_search':
'nowhere_left_to_search'})
159 smach.StateMachine.add(
'INDIRECT_SEARCH',
161 transitions={
'no_predictions_left':
'DIRECT_SEARCH',
163 'found_all_objects':
'found_all_objects',
164 'found_all_required_scenes':
'found_all_required_scenes'})
167 smach_thread = threading.Thread(target=sm_object_search.execute)
169 rospy.loginfo(
"Random search mode")
170 sm_random_search = RandomSearchStateMachine.sm_random_search
172 smach_thread = threading.Thread(target=sm_random_search.execute)
174 rospy.loginfo(
"Cropbox search mode")
177 smach_thread = threading.Thread(target=sm_cropbox_search.execute)
179 rospy.loginfo(
"Cropbox record mode")
182 smach_thread = threading.Thread(target=sm_cropbox_record.execute)
184 rospy.loginfo(
"Grid init record mode")
187 smach_thread = threading.Thread(target=sm_grid_init_record_search.execute)
195 if rospy.get_param(
"/scene_exploration_sm/enableSmachViewer"):
196 rospy.loginfo(
"Smach viewer enabled")
198 server = smach_ros.IntrospectionServer(
199 'scene_exploration_state_machine',
206 rospy.loginfo(
"Smach viewer disabled")
210 rospy.loginfo(
"Enter shutdown_hook")
211 """ Close rosbag recording, copy nbv logs and leave""" 213 if rosbag_proc
is not None:
214 rospy.loginfo(
"Stop rosbag_proc")
215 rosbag_proc.send_signal(subprocess.signal.SIGINT)
219 if smach_server
is not None:
220 rospy.loginfo(
"Stop smach_server")
223 if __builtin__.log_dir:
224 home = expanduser(
"~")
226 shutil.copy(home +
"/log/nbv.log", __builtin__.log_dir)
230 shutil.copy(home +
"/log/world_model.log", __builtin__.log_dir)
234 shutil.copy(home +
"/log/ism.log", __builtin__.log_dir)
238 shutil.copy(home +
"/log/state_machine.log", __builtin__.log_dir)
242 shutil.copy(home +
"/log/direct_search_manager.log", __builtin__.log_dir)
246 shutil.copy(home +
"/log/viz_server.log", __builtin__.log_dir)
251 if rospy.get_param(
"/scene_exploration_sm/use_sensors")
is False:
253 release_fake_recognizers = rospy.ServiceProxy(
'/asr_fake_object_recognition/clear_all_recognizers', FakeObjectClearAllRecognizers)
254 release_fake_recognizers()
255 except rospy.ServiceException, e:
256 rospy.logwarn(
"Error calling the clear for /asr_fake_object_recognition/clear_all_recognizers service: " + str(e))
259 release_desc_recognizers = rospy.ServiceProxy(
'/asr_descriptor_surface_based_recognition/clear_all_recognizers', DescriptorSurfaceClearAllRecognizers)
260 release_desc_recognizers()
261 except rospy.ServiceException, e:
262 rospy.logwarn(
"Error calling the clear for /asr_descriptor_surface_based_recognition/clear_all_recognizers service: " + str(e))
264 release_marker_recognizers = rospy.ServiceProxy(
'/asr_aruco_marker_recognition/release_recognizer', ReleaseRecognizer)
265 release_marker_recognizers()
266 except rospy.ServiceException, e:
267 rospy.logwarn(
"Error calling the clear for /asr_aruco_marker_recognition/release_recognizer service: " + str(e))
269 rospy.loginfo(
"Finished shutdown_hook")
272 if __name__ ==
'__main__':
275 except rospy.ROSInterruptException:
def startIntrospectionServer(sm, nameOfSearch)