README.md 4.45 KB
Newer Older
Moritz Klischat's avatar
Moritz Klischat committed
1 2
# SUMO - CommonRoad Interface

Moritz Klischat's avatar
Moritz Klischat committed
3
This package implements the interface between the framework for motion planning of automated vehicles [CommonRoad_io](https://pypi.org/project/commonroad-io/) and the traffic simulator [SUMO](https://sumo.dlr.de). The interface is presented in detail in our [paper](https://mediatum.ub.tum.de/doc/1486856/344641.pdf) [1] and a documentation of the API can be found [here]( https://commonroad.in.tum.de/static/docs/commonroad-sumo-interface/index.html).
Moritz Klischat's avatar
Moritz Klischat committed
4 5 6 7 8 9 10 11 12 13

# Prerequisites
The package is written in Python 3.6 and tested on Linux.
Install required packages:
```console
cd sumo-interface
pip install -r requirements.txt
sudo apt-get install ffmpeg
```

Moritz Klischat's avatar
Moritz Klischat committed
14 15
And add the absolute path of `commonroad-sumo-interface` to your Python interpreter.

Moritz Klischat's avatar
Moritz Klischat committed
16 17
## Install SUMO

Moritz Klischat's avatar
Moritz Klischat committed
18
Clone a customized version of SUMO for smooth lane changes from https://github.com/octavdragoi/sumo and check out branch `smooth-lane-change`.
Moritz Klischat's avatar
Moritz Klischat committed
19
For installation we recommend building with:
Moritz Klischat's avatar
Moritz Klischat committed
20

Moritz Klischat's avatar
Moritz Klischat committed
21
```
Moritz Klischat's avatar
Moritz Klischat committed
22
sudo apt-get install cmake python g++ libxerces-c-dev libfox-1.6-dev libgdal-dev libproj-dev libgl2ps-dev swig
Moritz Klischat's avatar
Moritz Klischat committed
23
cd sumo
Moritz Klischat's avatar
Moritz Klischat committed
24
export SUMO_HOME="$PWD/sumo"
Moritz Klischat's avatar
Moritz Klischat committed
25 26 27 28
mkdir build && cd build
cmake ..
make -j8
```
Moritz Klischat's avatar
Moritz Klischat committed
29

Moritz Klischat's avatar
Moritz Klischat committed
30 31 32
More options on the installation can be found here: https://sumo.dlr.de/wiki/Installing/Linux_Build .

## Configure SUMO and local environment
Moritz Klischat's avatar
Moritz Klischat committed
33
copy the file `pathConfig_DEFAULT.py` and rename it to `pathConfig.py`. Add local paths, if required.
Moritz Klischat's avatar
Moritz Klischat committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

# Integrating the SUMO-interface into CommonRoad
- 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/default.py`.

## Convert maps
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_scenario_files.py`.

## Create .rou.xml files
.rou.xml files specify all vehicles for the simulation. An introduction can be found here: https://sumo.dlr.de/wiki/Tutorials/quick_start#Traffic_demand.
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 https://sumo.dlr.de/wiki/Tools/Trip is implemented in the function
`ScenarioWrapper.recreate_route_file()`. See `example_scripts/create_scenario_files.py` for an example.

## Configure SUMO and sumo-interface
To use smooth lane changes, add
~~~~
<processing>
	<time-to-teleport value="-1"/>
	<lanechange-output value="output_lanechange.txt"/>
	<lanechange.duration value="10"/>
	<lanechange.smooth-change value="1"/>
</processing>
~~~~
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/default.py`.

## Minimal example for using the interface:
Moritz Klischat's avatar
Moritz Klischat committed
63
The file `example_scripts/minimal_example.py` gives an example how the interface can be integrated into an existing trajectory planner.
Moritz Klischat's avatar
Moritz Klischat committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
Plug in a trajectory planner and run:
```python
from sumo2cr.interface.sumo_simulation import SumoSimulation
from sumo2cr.visualization.video import create_video
from scenarios.a9.scenario_config import Conf as conf

sumo_sim = SumoSimulation()
sumo_sim.initialize(conf)

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
        ego_vehicle.set_planned_trajectory(ego_trajectory)

    sumo_sim.simulate_step()

Moritz Klischat's avatar
Moritz Klischat committed
87
sumo_sim.stop()
Moritz Klischat's avatar
Moritz Klischat committed
88 89
create_video(sumo_sim, conf.video_start, conf.video_end, output_folder)
```
Moritz Klischat's avatar
Moritz Klischat committed
90

Moritz Klischat's avatar
Moritz Klischat committed
91 92 93
## Troubleshooting
*    `Error: No option with the name 'lanechange.smooth-change' exists.`: Make SUMO is installed correctly and the SUMO_HOME variable is set to the path where SUMO is installed. If you don't want to use the continous lane change, delete the corresponding line from the *.cfg file.

Moritz Klischat's avatar
Moritz Klischat committed
94
[1] Moritz Klischat, Octav Dragoi, Mostafa Eissa, and Matthias Althoff, Coupling SUMO with a Motion Planning Framework for Automated Vehicles, SUMO 2019: Simulating Connected Urban Mobility