Skip to content

Commit

Permalink
Merge branch 'fix-fails-to-open-scenarios-with-predictionless-obstacl…
Browse files Browse the repository at this point in the history
…es' into 'develop'

fix(gui): fails to open scenario if any of the dynamic obstacles lacks a prediction

See merge request cps/commonroad/commonroad-scenario-designer!444
  • Loading branch information
smaierhofer committed Oct 18, 2024
2 parents 4aaa19a + de62c64 commit bfd7b59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- cr2sumo: Trajectory conversion assigned non-existent edges to routes
- osm2cr: Intersection incoming elements did not reference any incoming lanelets
- Command line interface: Providing no input path
- Scenario fails to be opened, if any of the dynamic obstacles does not contain a prediction

## [0.8.2] - 2024-07-22

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import List, Optional

import numpy as np
from commonroad.scenario.intersection import Intersection
from commonroad.scenario.lanelet import Lanelet, LaneletNetwork
from commonroad.visualization.mp_renderer import MPRenderer
Expand Down Expand Up @@ -226,17 +225,29 @@ def _calc_max_timestep(self) -> int:
if not self.scenario_model.scenario_created():
return 0

if (
len(self.scenario_model.get_dynamic_obstacles()) > 0
and self.scenario_model.get_dynamic_obstacles()[0].prediction is not None
):
time_steps = [
obstacle.prediction.occupancy_set[-1].time_step
for obstacle in self.scenario_model.get_dynamic_obstacles()
]
self.max_timestep = np.max(time_steps) if time_steps else 0
else:
self.max_timestep = 0
# The maximum time step is usually given by the final time step in the prediction
# of one of the dynamic obstacles
max_prediction_final_time_steps = max(
[
dynamic_obstacle.prediction.final_time_step
for dynamic_obstacle in self.scenario_model.get_dynamic_obstacles()
if dynamic_obstacle.prediction is not None
],
default=0,
)
# Additionally, consider the initial time step of each obstacle.
# This makes sure that obstacles, which only have an initial state, no prediction
# and enter the scenario after all other obstacles, are also displayed.
max_initial_time_steps = max(
[
dynamic_obstacle.initial_state.time_step
for dynamic_obstacle in self.scenario_model.get_dynamic_obstacles()
if dynamic_obstacle.prediction is None
],
default=0,
)

self.max_timestep = max(max_prediction_final_time_steps, max_initial_time_steps)

return self.max_timestep

Expand Down

0 comments on commit bfd7b59

Please sign in to comment.