Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scenic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/scenic/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 36 additions & 0 deletions src/scenic/simulators/carla/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/scenic/syntax/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down