Main Content

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®:

  1. 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.

  2. 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 is C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python N.N, where username is your Windows user profile name and Python N.N is 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.

  3. 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.

  4. Run RoadRunnerInstall\bin\win64\Tools\CARLA\examples\setup.bat, where RoadRunnerInstall is the RoadRunner installation directory. This runs the protobuf compiler on the proto files located in RoadRunnerInstall\bin\win64\Proto\mathworks and generates the scenario simulation engine (SSE) library in RoadRunnerInstall\bin\win64\Tools\CARLA\SimulationClient\sse.

    Note

    If you install RoadRunner in the Program Files directory, you must have administrator access to edit setup.bat.

  5. Create a new Windows environment variable that adds CARLA_ROOT to 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_ROOT and Variable value to the path where the CarlaUE4.exe file is located. By default, the path to CarlaUE4.exe is C:\CarlaInstall\WindowsNoEditor, where CARLAInstall is the CARLA installation directory.

  6. 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 at C:\Users\username\AppData\Roaming\MathWorks\RoadRunner\R20NNa\Scenario\Config\SimulationConfiguration.xml, where username is your Windows user profile name and R20NNa is the currently installed version of RoadRunner, such as R2023a.

    This code shows an example of updated SimulationConfiguration.xml settings where the CARLA executable location is C:\CARLAInstall\WindowsNoEditor\CarlaUE4.exe.

          
        <Platform name="CARLA"> 
            <ExecutablePath>C:\CARLAInstall\WindowsNoEditor\CarlaUE4.exe</ExecutablePath>
            <StartTimeOut>60000</StartTimeOut>
        </Platform>

Set Up CARLA on Linux Ubuntu

Follow these steps to generate the cosimulation bridge on Linux®:

  1. 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.

  2. 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.

  3. Enable write permissions for the RoadRunner installation folder. For example:

    sudo chown -R $USER /usr/local/RoadRunnerInstall/bin/glnxa64/Tools/CARLA/

    RoadRunnerInstall is the RoadRunner installation folder and $USER is your Linux user profile name.

    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.

  4. Change your directory to /usr/local/RoadRunnerInstall/bin/glnxa64/Tools/CARLA/, then run python ./SimulationClient/setup.py. This runs the protobuf compiler on the proto files located in RoadRunnerInstall/bin/glnxa64/Proto/mathworks and generates the SSE library in RoadRunnerInstall/bin/glnxa64/Tools/CARLA/SimulationClient/sse.

  5. Add CARLA_ROOT to the path for CarlaUE4.sh by running this code:

    export CARLA_ROOT="/CarlaInstall/"

    CarlaInstall is the CARLA installation directory. To make this change persistent session-wide, add the command to the ~/.bashrc file.

  6. Update the platform settings in the SimulationConfiguration.xml file to point to CarlaUE4.sh, then restart RoadRunner to apply the changes.

    By default SimulationConfiguration.xml is located at ~/.local/share/MathWorks/RoadRunner/R20NNa/Scenario/Config/SimulationConfiguration.xml, where R20NNa is the currently installed version of RoadRunner, such as 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/CarlaInstall/CarlaUE4.sh</ExecutablePath>
            <StartTimeOut>60000</StartTimeOut>
        </Platform>

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

| |

External Websites