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 -Vin 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 - Pathin 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 is- C:\Users\, where- username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\- Python N.N- usernameis your Windows user profile name and- Python N.Nis the currently installed version of Python, such as- Python 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 - pipby 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 - RoadRunnerInstall\bin\win64\Tools\CARLA\examples\setup.bat- RoadRunnerInstall- RoadRunnerInstall\bin\win64\Proto\mathworks- RoadRunnerInstall\bin\win64\Tools\CARLA\SimulationClient\sse- Note - If you install RoadRunner in the - Program Filesdirectory, you must have administrator access to edit- setup.bat.
- Create a new Windows environment variable that adds - CARLA_ROOTto the path for- CarlaUE4.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_ROOTand Variable value to the path where the- CarlaUE4.exefile is located. By default, the path to- CarlaUE4.exeis- C:\, where- CarlaInstall\WindowsNoEditor- CARLAInstall
- Update the platform settings in the - SimulationConfiguration.xmlfile to point to the CARLA executable, and restart RoadRunner to apply the changes. By default,- SimulationConfiguration.xmlis located at- C:\Users\, where- username\AppData\Roaming\MathWorks\RoadRunner\- R20NNa\Scenario\Config\SimulationConfiguration.xml- username- R20NNa- R2023a.- This code shows an example of updated - SimulationConfiguration.xmlsettings where the CARLA executable location is- C:\- CARLAInstall- \WindowsNoEditor\CarlaUE4.exe.- <Platform name="CARLA"> <ExecutablePath>C:\- 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 -Vin the Terminal.- For more information on building Python on Linux systems, see Building Python in the Python documentation. 
- Update - pipby 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/ - RoadRunnerInstall- $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 run- RoadRunnerInstall/bin/glnxa64/Tools/CARLA/- python ./SimulationClient/setup.py. This runs the protobuf compiler on the proto files located in- RoadRunnerInstall/bin/glnxa64/Proto/mathworks- RoadRunnerInstall/bin/glnxa64/Tools/CARLA/SimulationClient/sse
- Add - CARLA_ROOTto the path for- CarlaUE4.shby running this code:- export CARLA_ROOT="/CarlaInstall/" - CarlaInstall- ~/.bashrcfile.
- Update the platform settings in the - SimulationConfiguration.xmlfile to point to- CarlaUE4.sh, then restart RoadRunner to apply the changes.- By default - SimulationConfiguration.xmlis located at- ~/.local/share/MathWorks/RoadRunner/, where- R20NNa/Scenario/Config/SimulationConfiguration.xml- R20NNa- R2023a.- This code shows an example of updated - SimulationConfiguration.xmlsettings, where the CARLA executable location is- /Downloads/- CarlaInstall- /CarlaUE4.sh.- <Platform name="CARLA"> <ExecutablePath>/Downloads/- 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