1111import math
1212import logging
1313import sys
14+ import os
1415
1516log = logging .getLogger (__name__ )
1617
@@ -275,7 +276,7 @@ def check_module_status(self, modules):
275276 "Warning: Apollo module {} is not running!!!" .format (module )
276277 )
277278
278- def setup_apollo (self , dest_x , dest_z , modules ):
279+ def setup_apollo (self , dest_x , dest_z , modules , default_timeout = 60.0 ):
279280 """
280281 Starts a list of Apollo modules and sets the destination. Will wait for Control module to send a message before returning.
281282 Control sending a message indicates that all modules are working and Apollo is ready to continue.
@@ -293,28 +294,32 @@ def setup_apollo(self, dest_x, dest_z, modules):
293294 def on_control_received (agent , kind , context ):
294295 if kind == "checkControl" :
295296 agent .is_control_received = True
296- log .info ("Control message recieved " )
297+ log .info ("Control message received " )
297298
298299 self .ego .on_custom (on_control_received )
299300
300- for i in range (20 ):
301- self .sim .run (2 )
301+ try :
302+ timeout = float (os .environ .get ("DREAMVIEW_CONTROL_MESSAGE_TIMEOUT_SECS" , default_timeout ))
303+ except Exception :
304+ timeout = default_timeout
305+ log .warning ("Invalid DREAMVIEW_CONTROL_MESSAGE_TIMEOUT_SECS, using default {0}s" .format (default_timeout ))
306+
307+ run_time = 2
308+ elapsed = 0
309+ while timeout <= 0.0 or float (elapsed ) < timeout :
310+ self .sim .run (run_time )
302311
303312 if self .ego .is_control_received :
304313 break
305314
306- if i > 0 and i % 2 == 0 :
307- self .check_module_status (modules )
308- log .info (
309- "{} seconds has passed, Ego hasn't received any control messages" .format (
310- i * 2
311- )
312- )
313- log .info (
314- "Please also check if your route has been set correctly in Dreamview."
315- )
315+ if elapsed > 0 and elapsed % (run_time * 5 ) == 0 :
316+ self .checkModuleStatus (modules )
317+ log .info ("{} seconds have passed but Ego hasn't received any control messages." .format (elapsed ))
318+ log .info ("Please also check if your route has been set correctly in Dreamview." )
319+
320+ elapsed += run_time
316321 else :
317- log .error ("No control message from Apollo within 40 seconds. Aborting..." )
322+ log .error ("No control message from Apollo within {} seconds. Aborting..." . format ( timeout ) )
318323 self .disable_apollo ()
319324 raise WaitApolloError ()
320325
@@ -323,7 +328,7 @@ def on_control_received(agent, kind, context):
323328
324329class WaitApolloError (Exception ):
325330 """
326- Raised when Apollo control message is not recieved in time
331+ Raised when Apollo control message is not received in time
327332 """
328333
329334 pass
0 commit comments