Installation


Requirements

To get started, the following requirements should be fulfilled.

  • System requirements. Any 64-bits OS should run OpenCDA. We highly recommends Ubuntu 16.04/18.04/20.04.

  • Adequate GPU. CARLA is a realistic simulation platform based on Unreal Engine 4, which requires at least a 3GB GPU for smooth scene rendering, though 8GB is recommended.

  • Disk Space. Estimate 100GB of space is recommended to install CARLA and Unreal Engine.

  • Python Python3.7 or higher version is required for full functions.


Local Installation

To get OpenCDA v0.1 running with complete functionality, you will need four things: CARLA, OpenCDA, and Pytorch (optional). Pytorch is required only when you want to activate the perception module; otherwise OpenCDA will retrieve all perception information from the simulation server directly.

1. CARLA Installation (>= 0.9.11 required)

There are two different recommended ways to install the CARLA simulator and either way is fine for using OpenCDA.
Note: If you want to use the customized highway map with full assets (.fbx, .xml and .xodr) in OpenCDA, you have to build from source. Visit CARLA’s tutorial ADD a new map for more information.

1.1 Package Installation

OpenCDA is tested both at 0.9.11 and 0.9.12. To install CARLA as a precompiled package, download and extract the release file. It contains a precompiled version of the simulator, the Python API module and some scripts to be used as examples.

Note: The AdditionalMaps_0.9.1x.tar.gz also need to be downloaded and extract to the CARLA repo to support scenario testings in Town06.

1.2 Build From Source

For advanced CARLA usage that involves extensive customizations, Build CARLA from Source is also supported by OpenCDA. Though source build in Windows OS is supported by CARLA, Ubuntu is the preferred OS as the OpenCDA was developoed in Ubuntu 18.04.

Note: OpenCDA do not require CARLA source build. However, customized map with building/lane/traffic light/road surface materials assets in CARLA require source build. Visit CARLA’s tutorial ADD a new map for more information.


2. OpenCDA Installation

First, download OpenCDA github to your local folder if you haven’t done it yet.

git clone https://github.com/ucla-mobility/OpenCDA.git
cd OpenCDA

Make sure you are in the root dir of OpenCDA, and next let’s install the dependencies. We highly recommend use conda environment to install.

conda env create -f environment.yml
conda activate opencda
python setup.py develop

If conda install failed, install through pip

pip install -r requirements.txt

After dependencies are installed, we need to install the CARLA python library into opencda conda environment. You can do this by running this script:

export CARLA_HOME=/path/to/your/CARLA_ROOT
export CARLA_VERSION=0.9.11 #or 0.9.12 depends on your CARLA
. setup.sh

If everything works correctly, you will see a cache folder is created in your OpenCDA root dir, and the terminal shows “Successful Setup!”. To double check the carla package is correctly installed, run the following command and there should be no error.

python -c "import carla" # check whether carla is installed correctly.

Note: If you are using Python other than 3.7 and CARLA < 0.9.11 then you have to change the setup.sh to your carla version’s egg file or manually installed carla to your conda environment.

3. Install Pytorch and Yolov5 (Optional)

This section is only needed for the users who want to test perception algorithms. By default, OpenCDA does not require pytorch installed and it retrieves the object positions from the server directly. Once perception module is activated, then OpenCDA will use yolov5 with pytorch to run object detection.
To install pytorch based on your GPU and cuda version, go to the official pytorch website and install with conda command. Make sure you install pytorch >= 1.7.0. GPU Version highly recommended!

The command belows shows an example of installing pytorch v1.8.0 with cuda 11.1 in opencda environment.

conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge

After pytorch installation, install the requirements for Yolov5.

pip install -qr https://raw.githubusercontent.com/ultralytics/yolov5/master/requirements.txt  # install dependencies

4. Install SUMO (Optional)

SUMO installation is only required for the users who require to conduct co-simulation testing and use future release of SUMO-only mode.

You can install SUMO directly by apt-get:

sudo add-apt-repository ppa:sumo/stable
sudo apt-get update
sudo apt-get install sumo sumo-tools sumo-doc

After that, install the traci python package.

pip install traci

Finally, add the following path to your ~/.bashrc:

export SUMO_HOME=/usr/share/sumo

Docker Installation

OpenCDA provides docker image for users to run directly.

1. Prerequisite

First, make sure that you have installed docker in your ubuntu system. If you have nvidia gpu, it is recommended to install nvidia-docker as well.

2. Dockerfile Modification

Next, modify the Dockerfile based on your system. Some parameters you may want to pay attentions are:

  • CARLA_VERSION: Change to the version you want. Notice after(including) OpenCDA 0.1.4, only CARLA >= 0.9.14 will be supported.

  • FROM nvidia/vulkan:1.3-470: If you want the carla run with rendering in the docker, make sure the graphics driver is set to the same as your local computer. For instance, mine is FROM nvidia/cuda-11.4.2.0-ase-ubuntu2004

  • OPENCDA_FULL_INSTALL: If set true, it will run the setup.sh in OpenCDA automatically during building up the docker to install carla api into the python environment. if set to false, then you need to go to your docker container after building to manually run setup.sh

3. Build up the docker

cd OpenCDA
docker build -t opencda_container .

4. Run the docker

The following command will allow you run Carla with rendering in your docker. If the rendering is the black, then you probably build up the wrong nvidia graphics driver.

xhost +local: 

docker run -it --rm \
  -e DISPLAY=$DISPLAY \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  -v $HOME/.Xauthority:/root/.Xauthority \
  --name opencda_container opencda_docker /bin/bash