Using the interface

Configuration of scenarios

  • All scenarios are stored in /scenarios. All files for each scenario must be named consistently with the same scenario name as the folder.
  • The default config file with all options for the simulation can be found in /config/

Map conversion

Before using the interface, a map needs to be available in CommonRoad .xml and SUMO’s .net.xml format. Currently only the conversion from .net.xml to commonroad format is implemented. For an example see example_scripts/

Create .rou.xml files

.rou.xml files specify all vehicles for the simulation. An introduction can be found here: To use the interface for planning with ego vehicles, the vehicle ID in the .rou.xml file needs to start with the prefix egoVehicle. A simple script to create .rou.xml files using is implemented in the function ScenarioWrapper.recreate_route_file(). See example_scripts/ for an example.

Smooth lane changes with SUMO

To use smooth lane changes, add

      <time-to-teleport value="-1"/>
      <lanechange-output value="output_lanechange.txt"/>
      <lanechange.duration value="10"/>
      <lanechange.smooth-change value="1"/>

to the .sumo.cfg file of the scenario (activated by default for scenarios generated by the class ScenarioWrapper).

Further options for the interface can be found in the sumo-interface config file sumo-interface/config/

Minimal example for using the interface

The file example_scripts/ gives an example how the interface can be integrated into an existing trajectory planner. For testing, the scenarios cross_example_map and traci_tls are recommended. Plug in a trajectory planner and run:

from sumo2cr.interface.sumo_simulation import SumoSimulation
from import create_video
from scenarios.a9.scenario_config import Conf as conf

sumo_sim = SumoSimulation()

output_folder = "/path/to/output_folder"

for t in range(conf.simulation_steps):
  ego_vehicles = sumo_sim.ego_vehicles
  commonroad_scenario = sumo_sim.commonroad_scenario_at_time_step(sumo_sim.current_time_step)

   # plan trajectories for all ego vehicles
  for id, ego_vehicle in ego_vehicles.items():
      current_state = ego_vehicle.current_state
      ego_trajectory =  # plug in trajectory planner here


create_video(sumo_sim, conf.video_start, conf.video_end, output_folder)