@@ -76,16 +76,13 @@ def __init__(self,
7676 supervisor_address = 'http://' + DEFAULT_ADDRESS + ':' +
7777 str (DEFAULT_PORT ) + '/' ,
7878 auto_start = True ):
79- if agent is not None and not isinstance (agent , Agent ):
80- raise ValueError ("BenchBot received an agent of type '%s' "
81- "which is not an instance of '%s'." %
82- (agent .__class__ .__name__ , Agent .__name__ ))
83- self .agent = agent
84-
79+ self .agent = None
8580 self .supervisor_address = supervisor_address
8681 self ._connection_callbacks = {}
82+
8783 if auto_start :
8884 self .start ()
85+ self .set_agent (agent )
8986
9087 def _build_address (self , route_name , route_type = RouteType .CONNECTION ):
9188 """Builds an address for communication with a running instance of
@@ -245,8 +242,8 @@ def empty_results(self):
245242 self ._query ('task' , BenchBot .RouteType .CONFIG ),
246243 'environment_details' :
247244 self ._query ('environments' , BenchBot .RouteType .CONFIG ),
248- 'results' :
249- self ._query ( 'create' , BenchBot . RouteType . RESULTS )
245+ 'results' : ( self . _query ( 'create' , BenchBot . RouteType . RESULTS )
246+ if self .config [ 'results' ] else {} )
250247 }
251248
252249 def next_scene (self ):
@@ -261,7 +258,7 @@ def next_scene(self):
261258 # Bail if next is not a valid operation
262259 if (self ._query ('is_collided' ,
263260 BenchBot .RouteType .ROBOT )['is_collided' ]):
264- raise RuntimeError ("Collision stated detected for robot; "
261+ raise RuntimeError ("Collision state detected for robot; "
265262 "cannot proceed to next scene" )
266263
267264 # Move to the next scene
@@ -304,11 +301,13 @@ def results_functions(self):
304301 for r in self ._query ('/' , BenchBot .RouteType .RESULTS )
305302 }
306303
307- def run (self ):
304+ def run (self , agent = None ):
308305 """Helper function that runs the robot according to the agent given.
309306 Generally, you should use this function and implement your object in
310307 your own custom agent class.
311308 """
309+ if agent is not None :
310+ self .set_agent (agent )
312311 if self .agent is None :
313312 raise RuntimeError (
314313 "Can't call Benchbot.run() without an agent attached. Either "
@@ -332,6 +331,19 @@ def scene_fn():
332331 self .agent .save_result (self .result_filename , self .empty_results (),
333332 self .results_functions ())
334333
334+ def set_agent (self , agent ):
335+ """Updates the current agent, and starts its connection with a BenchBot
336+ Supervisor if requested"""
337+ if agent is None :
338+ self .agent = None
339+ return
340+
341+ if agent is not None and not isinstance (agent , Agent ):
342+ raise ValueError ("BenchBot received an agent of type '%s' "
343+ "which is not an instance of '%s'." %
344+ (agent .__class__ .__name__ , Agent .__name__ ))
345+ self .agent = agent
346+
335347 def start (self ):
336348 """Establishes a connect to the Supervisor, and then uses this to
337349 establish a connection with a running robot. It then initialises all
0 commit comments