From 6f08e0fb3c84d90b81aef5c651a528de076d589f Mon Sep 17 00:00:00 2001 From: Christian Geller Date: Fri, 2 Feb 2024 18:06:30 +0100 Subject: [PATCH] Initial version --- .github/workflows/docker.yml | 59 ++++++++++++++++++ CARLA_VER | 2 +- CARLOS_CHANGELOG.md | 13 ++++ README.md | 30 ++++++++- docker/Dockerfile | 62 +++++++++++++++++++ docker/entrypoint.sh | 8 +++ requirements.txt | 29 ++++----- scenario_runner.py | 2 +- .../actorcontrols/actor_control.py | 1 + .../actorcontrols/carla_autopilot.py | 4 +- 10 files changed, 190 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/docker.yml create mode 100644 CARLOS_CHANGELOG.md create mode 100644 docker/Dockerfile create mode 100755 docker/entrypoint.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..e50eaa7c4 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,59 @@ +name: Docker + +on: [push, pull_request] + +jobs: + + clean-up: + name: Clean up + runs-on: ubuntu-latest + steps: + + - name: Clean up + run: rm -rf * + + create-image: + name: Create docker image + runs-on: ubuntu-latest + needs: clean-up + env: + IMAGE_TAG_SUFFIX: "" + steps: + + - uses: actions/checkout@v4 + name: Checkout repository + with: + path: carla-scenario-runner + submodules: true + + - uses: docker/login-action@v3 + name: Login to Docker Hub + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - uses: robinraju/release-downloader@v1.8 + name: Download PythonAPI + with: + repository: carla-compose/carla-simulator + latest: true + fileName: PythonAPI.tar.gz + extract: true + out-file-path: . + + - name: Remove PythonAPI.tar.gz + run: rm PythonAPI.tar.gz + + - name: Set image tag + run: | + echo "IMAGE_TAG_SUFFIX=_$(echo '${{ github.ref_name }}' | tr / -)_ci" >> $GITHUB_ENV + if: github.ref_name != github.event.repository.default_branch + + - uses: docker/build-push-action@v5 + name: Build and push + with: + push: true + file: carla-scenario-runner/docker/Dockerfile + tags: rwthika/carla-scenario-runner:latest${{env.IMAGE_TAG_SUFFIX}} + no-cache: true + context: . diff --git a/CARLA_VER b/CARLA_VER index d9a555666..7d1d1497e 100644 --- a/CARLA_VER +++ b/CARLA_VER @@ -1,2 +1,2 @@ HOST = https://carla-releases.s3.eu-west-3.amazonaws.com/Linux -RELEASE=CARLA_0.9.13 +RELEASE=CARLA_0.9.15 diff --git a/CARLOS_CHANGELOG.md b/CARLOS_CHANGELOG.md new file mode 100644 index 000000000..361487ae5 --- /dev/null +++ b/CARLOS_CHANGELOG.md @@ -0,0 +1,13 @@ +## Latest : 1.0.0 + +## 1.0.0 - Initial Release + +### Major changes + +* Created GitHub workflow and Dockerfile to automatically build Docker images +* Update to [CARLA 0.9.15](https://carla.org/2023/11/10/release-0.9.15/) +* Update to Ubuntu 22.04 and Python 3.10 including corresponding pip versions + +### Minor changes + +* Small fix related to CARLA autopilot diff --git a/README.md b/README.md index 5e6e47131..609bf1ed7 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,35 @@ +# Control Actor: *carla-scenario-runner* + +

+ + + + + + + + +

+ +> [!IMPORTANT] +> This repository is a minimal fork of the official [scenario_runner](https://github.com/carla-simulator/scenario_runner)! All initial and following modifications to the original repository are documented in [CARLOS_CHANGELOG.md](./CARLOS_CHANGELOG.md). + +> [!TIP] +> We recommend to use the *carla-scenario-runner* as **control actor** in our open, modular and scalable simulation framework **CARLOS**. +> +> The *carla-scenario-runner* is used to enable scenario-based testing and evaluation. It is a powerful engine that follows the OpenSCENARIO standard for scenario definitions. + +> [!NOTE] +> We set up a Continous Integration (CI) pipeline as [GitHub workflow](./github/workflows/docker.yml) to continously build Docker images for the `carla-scenario-runner`, publicly available on [Docker Hub](https://hub.docker.com/r/rwthika/carla-scenario-runner). + +--- +--- +## Original README + [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/carla-simulator/scenario_runner.svg) [![Build Status](https://travis-ci.com/carla-simulator/scenario_runner.svg?branch=master)](https://travis-ci.com/carla/scenario_runner) -ScenarioRunner for CARLA -======================== This repository contains traffic scenario definition and an execution engine for CARLA. It also allows the execution of a simulation of the CARLA Challenge. You can use this system to prepare your agent for the CARLA Challenge. diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..b28c1c316 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,62 @@ +ARG UBUNTU_VERSION="22.04" + + +############ dependencies ############ +FROM "ubuntu:${UBUNTU_VERSION}" + +USER root +SHELL ["/bin/bash", "-c"] + +ARG CARLA_API_PATH=/opt/carla/PythonAPI +ARG SCENARIO_RUNNER_PATH=/opt/carla/carla-scenario-runner + +# Install essentials +RUN apt-get update && \ + apt-get install -y \ + libpng16-16 \ + libtiff5 \ + libjpeg8 \ + build-essential \ + wget \ + git \ + libxerces-c-dev \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +RUN pip3 install --upgrade pip +RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10 + +# Install carla-scenario-runner +COPY ./carla-scenario-runner $SCENARIO_RUNNER_PATH +RUN pip3 install -r $SCENARIO_RUNNER_PATH/requirements.txt + +# Move over PythonAPI +COPY ./artifacts/PythonAPI ${CARLA_API_PATH} + +# Recursively install PythonAPI requirements, keep version of first occurrence +RUN cat $(find ${CARLA_API_PATH} -type f -name "requirements.txt") > /tmp/requirements_raw.txt \ + && awk -F '==' '{print $1}' /tmp/requirements_raw.txt | awk '!visited[$1]++' > /tmp/requirements.txt \ + && pip3 install -r /tmp/requirements.txt + +# Create script that adds API to pythonpath and make .bashrc source it +RUN echo "export PYTHONPATH=\$PYTHONPATH:$CARLA_API_PATH/carla/dist/$(ls $CARLA_API_PATH/carla/dist | grep py$(python --version | awk -F'[ .]' '{print $2"."$3}').)" >> /setup_carla_env.sh; \ + echo "export PYTHONPATH=\$PYTHONPATH:$CARLA_API_PATH/carla/agents" >> /setup_carla_env.sh; \ + echo "export PYTHONPATH=\$PYTHONPATH:$CARLA_API_PATH/carla" >> /setup_carla_env.sh; \ + echo "export CARLA_API_PATH=$CARLA_API_PATH" >> /setup_carla_env.sh; \ + echo "source /setup_carla_env.sh" >> ~/.bashrc + +# Needed for (pygame based) scripts that have a GUI +ENV SDL_VIDEODRIVER=x11 + +USER root +SHELL ["/bin/bash", "-c"] + +ARG WORKSPACE=${SCENARIO_RUNNER_PATH} +ENV WORKSPACE=${WORKSPACE} +WORKDIR ${WORKSPACE} + +# Set entrypoint +COPY ./carla-scenario-runner/docker/entrypoint.sh / +ENTRYPOINT [ "/entrypoint.sh" ] + +CMD [ "python3", "scenario_runner.py", "--help" ] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 000000000..f546ece4e --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +# source CARLA environment setup script +source /setup_carla_env.sh + +# run the actual command +exec "$@" diff --git a/requirements.txt b/requirements.txt index fcbb5da93..62d304cb5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,15 @@ -py-trees==0.8.3 -numpy==1.18.4; python_version >= '3.0' -networkx==2.2 -Shapely==1.7.1 -psutil -xmlschema==1.0.18 -ephem -tabulate -opencv-python==4.2.0.32 -matplotlib -six -simple-watchdog-timer -antlr4-python3-runtime==4.10 -graphviz +# Update all versions to be compatible with Ubuntu 22.04, Python 3.10.6, ROS Humble (at 2023-07-24) +py-trees==0.8.3 # newest version (2.2.3) is not compatible +numpy==1.21.5 +networkx==3.1 +shapely==2.0.1 +psutil==5.9.0 +xmlschema==2.3.1 +ephem==4.1.4 +tabulate==0.9.0 +opencv-python==4.8.0.74 +matplotlib==3.7.2 +six==1.16.0 +simple-watchdog-timer==0.1.1 +antlr4-python3-runtime==4.13.1 +graphviz==0.20.1 diff --git a/scenario_runner.py b/scenario_runner.py index 07e635e19..18ac73147 100755 --- a/scenario_runner.py +++ b/scenario_runner.py @@ -44,7 +44,7 @@ from srunner.scenarioconfigs.osc2_scenario_configuration import OSC2ScenarioConfiguration # Version of scenario_runner -VERSION = '0.9.13' +VERSION = '0.9.15' class ScenarioRunner(object): diff --git a/srunner/scenariomanager/actorcontrols/actor_control.py b/srunner/scenariomanager/actorcontrols/actor_control.py index 333618d6c..00619b298 100644 --- a/srunner/scenariomanager/actorcontrols/actor_control.py +++ b/srunner/scenariomanager/actorcontrols/actor_control.py @@ -79,6 +79,7 @@ def __init__(self, actor, control_py_module, args, scenario_file_path): if ".py" in control_py_module: module_name = os.path.basename(control_py_module).split('.')[0] sys.path.append(os.path.dirname(control_py_module)) + sys.path.append(os.path.dirname(__file__)) module_control = importlib.import_module(module_name) control_class_name = module_control.__name__.title().replace('_', '') else: diff --git a/srunner/scenariomanager/actorcontrols/carla_autopilot.py b/srunner/scenariomanager/actorcontrols/carla_autopilot.py index 5b030119f..37dfdcdf2 100644 --- a/srunner/scenariomanager/actorcontrols/carla_autopilot.py +++ b/srunner/scenariomanager/actorcontrols/carla_autopilot.py @@ -18,7 +18,7 @@ from srunner.scenariomanager.actorcontrols.basic_control import BasicControl -class CarlaAutoPilotControl(BasicControl): +class CarlaAutopilot(BasicControl): """ Controller class for vehicles derived from BasicControl. @@ -33,7 +33,7 @@ class CarlaAutoPilotControl(BasicControl): """ def __init__(self, actor, args=None): - super(CarlaAutoPilotControl, self).__init__(actor) + super(CarlaAutopilot, self).__init__(actor) self._actor.set_autopilot(enabled=True) def reset(self):