diff --git a/src/scenic/__main__.py b/src/scenic/__main__.py index 05f527fba..082450368 100644 --- a/src/scenic/__main__.py +++ b/src/scenic/__main__.py @@ -63,7 +63,7 @@ "--scenario", default=None, help="name of scenario to run (if file contains multiple)" ) mainOptions.add_argument( - "--2d", action="store_true", help="run Scenic in 2D compatibility mode" + "--2d", default=True, action="store_true", help="run Scenic in 2D compatibility mode" ) # Simulation options diff --git a/src/scenic/core/errors.py b/src/scenic/core/errors.py index 6cca51d8a..56e1d0723 100644 --- a/src/scenic/core/errors.py +++ b/src/scenic/core/errors.py @@ -265,8 +265,9 @@ def includeFrame(frame): # we specially allow overwriting excepthooks from the following modules, # which are known to not cause problems: # - exceptiongroup (PEP 654 backport for pre-3.11) +# - apport_python_hook (Ubuntu crash reporting system) if sys.excepthook is not sys.__excepthook__ and not sys.excepthook.__module__.startswith( - "exceptiongroup" + ("exceptiongroup", "apport_python_hook") ): warnings.warn("unable to install sys.excepthook to format Scenic backtraces") else: diff --git a/src/scenic/simulators/carla/simulator.py b/src/scenic/simulators/carla/simulator.py index e69b4f860..847620633 100644 --- a/src/scenic/simulators/carla/simulator.py +++ b/src/scenic/simulators/carla/simulator.py @@ -63,6 +63,9 @@ def __init__( # Set to synchronous with fixed timestep settings = self.world.get_settings() + settings.substepping = True + settings.max_substep_delta_time = 0.01 + settings.max_substeps = 10 settings.synchronous_mode = True settings.fixed_delta_seconds = timestep # NOTE: Should not exceed 0.1 self.world.apply_settings(settings) @@ -79,6 +82,8 @@ def createSimulation(self, scene, *, timestep, **kwargs): "set timestep when creating the CarlaSimulator instead" ) + self._cleanupWorld() + self.scenario_number += 1 return CarlaSimulation( scene, @@ -91,6 +96,31 @@ def createSimulation(self, scene, *, timestep, **kwargs): **kwargs, ) + def _cleanupWorld(self): + """Destroy any actors left over in the CARLA world from a prior run.""" + verbosePrint("Cleaning up existing actors in CARLA world...") + actor_list = self.world.get_actors() + + for actor in actor_list.filter("walker.*"): + if actor.is_alive: + actor.destroy() + + for actor in actor_list.filter("controller.ai.walker"): + if actor.is_alive: + actor.destroy() + + for actor in actor_list.filter("vehicle.*"): + if actor.is_alive: + actor.set_autopilot(False, self.tm.get_port()) + actor.destroy() + + for actor in actor_list.filter("sensor.*"): + if actor.is_alive: + actor.destroy() + + self.world.tick() + verbosePrint("Cleanup complete.") + def destroy(self): super().destroy() settings = self.world.get_settings() @@ -135,6 +165,7 @@ def setup(self): self.displayDim, pygame.HWSURFACE | pygame.DOUBLEBUF ) self.cameraManager = None + self.world.on_tick(self.hud.on_world_tick) if self.record: if not os.path.exists(self.record): @@ -301,6 +332,9 @@ def step(self): # Run simulation for one timestep self.current_frame = self.world.tick() + if self.render: + self.displayClock.tick() + # Wait for sensors to get updates for obj in self.objects: if obj.sensors: @@ -310,7 +344,9 @@ def step(self): # Render simulation if self.render: + self.hud.tick(self.world, self.objects[0], self.displayClock) self.cameraManager.render(self.display) + self.hud.render(self.display) pygame.display.flip() def getProperties(self, obj, properties): diff --git a/src/scenic/syntax/translator.py b/src/scenic/syntax/translator.py index 58e856607..cfc817c38 100644 --- a/src/scenic/syntax/translator.py +++ b/src/scenic/syntax/translator.py @@ -102,7 +102,7 @@ def scenarioFromString( def scenarioFromFile( - path, params={}, model=None, scenario=None, *, mode2D=False, **kwargs + path, params={}, model=None, scenario=None, *, mode2D=True, **kwargs ): """Compile a Scenic file into a `Scenario`.