Skip to content

LimSim, SUMO, CARLA Co-Simulation

CARLA is an open-source autonomous driving simulator with multiple functions including perception, positioning, etc., which can be used to help train various modules of autonomous driving. The SUMO co-simulation function provided by CARLA official allows users to use SUMO to manage the background traffic flow of the simulation, making it possible for LimSim, SUMO, and CARLA to co-simulate.

Co-simulation is mainly achieved through SUMO's Parallel simulation function. After this function is turned on, the main program can simulate as a Server, while the subprogram can receive data as a Client. Therefore, we can run LimSim as the main program and run CARLA's co-simulation as a subprogram.

Step 0: Install CARLA

⚠️ All the instructions are based on Linux, Windows support is not tested and guaranteed.

You need to first install CARLA through package installation, the version of Carla is prefered to 0.9.12+. Please ref the link below:

Quick start package installation - CARLA Simulator

Then, please make sure SUMO co-simulation with CARLA has configured. Please ref the link below:

SUMO - CARLA Simulator

Now, you should have a Carla folder besides LimSim folder, and the Carla folder structure should look like:

├── CarlaUE4
   ├── AssetRegistry.bin
   ├── Binaries
   ├── CarlaUE4.uproject
   ├── Config
   ├── Content
   └── Plugins
├── CarlaUE4.sh
├── Co-Simulation
   ├── PTV-Vissim
   └── Sumo
├── PythonAPI
   ├── carla
   ├── examples
   ├── python_api.md
   └── util
├── README
├── ......
├── ......
└── VERSION

Step 1: Run CARLA Co-simulation

You should open two terminal.

# Terminal 1
cd path-to-carla/
./CarlaUE4.sh  -world-port=2000 -resx=400 -resy=300  -quality-level=Epic

Now you should see CARLA GUI. Then switch to another terminal:

# Termnial 2
cd path-to-carla/
cd PythonAPI/util/
python3 config.py --map Town05

Now the map in Carla is successfully switch to Town05 map.

# Terminal 2
cd ../.. #back to carla root dir
cd Co-Simulation/Sumo
python3 run_synchronization.py examples/Town05.sumocfg --sumo-host 127.0.0.1 --sumo-port 8813 --client-order 2

The terminal should continuly output Could not connect to TraCI server at 127.0.0.1:8813 [Errno 111] Connection refused Retrying in 1 seconds, don't panic, it means your set up is all done. Now continue to next step!

Step 2: Run LimSim Co-simulation

Modify the code in main function in ModelExample.py:

if __name__ == "__main__":
    net_file, rou_file = file_paths['CarlaTown05']
    run_model(net_file, rou_file, ego_veh_id="4", carla_cosim=True)

Then open a third terminal:

# Terminal 3
cd path-to-limsim/
python ./ModelExample.py

Then you should see all LimSim/Sumo/CARLA GUIs are start co-simulation.

You can use the w,a,s,d,q,e to control the view moving in CARLA.

Step 3: (Optional) Change the Bird-eye view in CARLA

If you want to make the view in CARLA follow ego car, the file run_synchronization.py in Co-Simulation/Sumo folder needs to be slightly modified.

Just download this file to replace the original run_synchronization.py in your folder and make sure the ego_id = '4' in line 222 the id of ego car.

Enjoy!