Skip to content

Commit 3990ca7

Browse files
added loop to spawn ego for redunancy
1 parent 7c83653 commit 3990ca7

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎cawsr.py‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,23 @@ def run_scenario(
161161
# update the world
162162
CarlaDataProvider.set_world(self.carla_world)
163163

164-
logger.info("Spawning ego...")
165-
ego = EgoVehicle(env_config)
166-
actor = ego.spawn()
167-
self.ego_vehicles.append(actor)
168-
logger.info(f"Spawned ego with id: {actor.id}")
164+
# attempt to spawn the ego 3 times for redundancy
165+
max_attempts = 3
166+
for attempt in range(max_attempts):
167+
try:
168+
logger.info("Spawning ego...")
169+
ego = EgoVehicle(env_config)
170+
actor = ego.spawn()
171+
self.ego_vehicles.append(actor)
172+
logger.info(f"Spawned ego with id: {actor.id}")
173+
except Exception as e:
174+
logger.error(f"Failed to spawn ego on attempt {attempt + 1}: {e}")
175+
if attempt == max_attempts - 1:
176+
logger.error(
177+
"Failed to spawn ego: Terminating scenario. This is most likely an issue with CARLA"
178+
)
179+
raise
180+
time.sleep(2)
169181

170182
# client must tick to spawn actors
171183
self._tick_carla()

‎srunner/tools/route_parser.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ def is_scenario_at_route(trigger_transform, route):
147147
"""
148148
Check if the scenario is affecting the route.
149149
This is true if the trigger position is very close to any route point
150+
151+
TODO:
152+
- Add logging to inform if a scenario is not part of the route (debug)
150153
"""
151154

152155
def is_trigger_close(trigger_transform, route_transform):

0 commit comments

Comments
 (0)