Set Up CARLA for Cosimulation
Install CARLA
Download CARLA from the GitHub® release site, https://github.com/carla-simulator/carla/releases/tag/0.9.13. Unzip the release into a folder, which becomes the CARLA installation directory.
Note
RoadRunner Scenario supports only CARLA version 0.9.13.
CARLA 0.9.13 supports several Python® versions depending on the installation method you choose. For more information on CARLA requirements, see the Quick Start Package Installation page on the CARLA website.
The sample code provided in CARLA Cosimulation Workflow uses Python 3.7.
Set Up CARLA Cosimulation Bridge
RoadRunner Scenario and CARLA cosimulation synchronize and communicate using the CARLA cosimulation bridge. For information on the cosimulation bridge, see Overview of RoadRunner Scenario and CARLA Cosimulation.
Set Up CARLA on Microsoft Windows
Follow these steps to generate the cosimulation bridge in Windows®:
Install Python. You can download Python from https://www.python.org/downloads/. If you already have Python installed, you can check the version by entering
python -V
in the Windows Command Prompt.Edit your Windows environment variables to add Python to your path.
To do this, open Windows Settings and click System > About > Advanced System Settings. In the System Properties window, click Environment Variables and, in the System Variables panel, click
Path
in the Variables column to highlight it. Next, click Edit > New and add your Python installation directory to the new active row. By default, the path isC:\Users\
, whereusername
\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python N.N
username
is your Windows user profile name andPython N.N
is the currently installed version of Python, such asPython 3.7
. Click OK to apply the change.For more information on using Python on Windows, see Using Python on Windows in the Python documentation.
Update
pip
by entering this command:python -m pip install --upgrade pip
.Tip
You can test your current setup to determine whether or not you can run simulations with CARLA by opening one of the samples that ships with CARLA. See Running CARLA on the CARLA website for more information.
Run
, whereRoadRunnerInstall
\bin\win64\Tools\CARLA\examples\setup.bat
is the RoadRunner installation directory. This runs the protobuf compiler on the proto files located inRoadRunnerInstall
and generates the scenario simulation engine (SSE) library inRoadRunnerInstall
\bin\win64\Proto\mathworks
.RoadRunnerInstall
\bin\win64\Tools\CARLA\SimulationClient\sseNote
If you install RoadRunner in the
Program Files
directory, you must have administrator access to editsetup.bat
.Create a new Windows environment variable that adds
CARLA_ROOT
to the path forCarlaUE4.exe
.To do this, open the Environment Variables window by following the same steps from step 2 and, in the System Variables panel, click New. Set Variable name to
CARLA_ROOT
and Variable value to the path where theCarlaUE4.exe
file is located. By default, the path toCarlaUE4.exe
isC:\
, whereCarlaInstall
\WindowsNoEditor
is the CARLA installation directory.CARLAInstall
Update the platform settings in the
SimulationConfiguration.xml
file to point to the CARLA executable, and restart RoadRunner to apply the changes. By default,SimulationConfiguration.xml
is located atC:\Users\
, whereusername
\AppData\Roaming\MathWorks\RoadRunner\R20NNa
\Scenario\Config\SimulationConfiguration.xml
is your Windows user profile name andusername
is the currently installed version of RoadRunner, such asR20NNa
R2023a
.This code shows an example of updated
SimulationConfiguration.xml
settings where the CARLA executable location isC:\
CARLAInstall
\WindowsNoEditor\CarlaUE4.exe
.<Platform name="CARLA"> <ExecutablePath>C:\
\WindowsNoEditor\CarlaUE4.exe</ExecutablePath> <StartTimeOut>60000</StartTimeOut> </Platform>CARLAInstall
Set Up CARLA on Linux Ubuntu
Follow these steps to generate the cosimulation bridge on Linux®:
Install Python. You can download Python from https://www.python.org/downloads/. If you already have Python installed, you can check the version by entering
python -V
in the Terminal.For more information on building Python on Linux systems, see Building Python in the Python documentation.
Update
pip
by entering this command:python -m pip install --upgrade pip
.Tip
You can test your current setup to determine whether or not you can run simulations with CARLA by opening one of the samples that ships with CARLA. See Running CARLA on the CARLA website for more information.
Enable write permissions for the RoadRunner installation folder. For example:
sudo chown -R $USER /usr/local/RoadRunnerInstall/bin/glnxa64/Tools/CARLA/
is the RoadRunner installation folder andRoadRunnerInstall
is your Linux user profile name.$USER
Note
You must have administrator access to run
sudo
. If you do not have administrator access, contact your system administrator or install RoadRunner in a location where you already have write permissions.Change your directory to
/usr/local/
, then runRoadRunnerInstall
/bin/glnxa64/Tools/CARLA/python ./SimulationClient/setup.py
. This runs the protobuf compiler on the proto files located in
and generates the SSE library inRoadRunnerInstall
/bin/glnxa64/Proto/mathworks
.RoadRunnerInstall
/bin/glnxa64/Tools/CARLA/SimulationClient/sseAdd
CARLA_ROOT
to the path forCarlaUE4.sh
by running this code:export CARLA_ROOT="/CarlaInstall/"
is the CARLA installation directory. To make this change persistent session-wide, add the command to theCarlaInstall
~/.bashrc
file.Update the platform settings in the
SimulationConfiguration.xml
file to point toCarlaUE4.sh
, then restart RoadRunner to apply the changes.By default
SimulationConfiguration.xml
is located at~/.local/share/MathWorks/RoadRunner/
, whereR20NNa
/Scenario/Config/SimulationConfiguration.xml
is the currently installed version of RoadRunner, such asR20NNa
R2023a
.This code shows an example of updated
SimulationConfiguration.xml
settings, where the CARLA executable location is/Downloads/
CarlaInstall
/CarlaUE4.sh
.<Platform name="CARLA"> <ExecutablePath>/Downloads/
/CarlaUE4.sh</ExecutablePath> <StartTimeOut>60000</StartTimeOut> </Platform>CarlaInstall
Configure Cosimulation Properties
You can optionally modify the cosimulation properties between RoadRunner Scenario and CARLA. The cosimulation properties include parameters such as timing step resolution and network location of the SSE. For information on how to configure the cosimulation properties, see Simulation Configuration.
See Also
CARLA Cosimulation Workflow | Overview of RoadRunner Scenario and CARLA Cosimulation | Simulation Configuration