Skip to content

Commit

Permalink
Merge pull request #74 from usdot-fhwa-stol/feature/merge_1.0_to_master
Browse files Browse the repository at this point in the history
Feature/merge 1.0 to master
  • Loading branch information
kjrush authored Aug 10, 2022
2 parents 4e4cfdb + ddfc20c commit 9076936
Show file tree
Hide file tree
Showing 1,501 changed files with 650,078 additions and 3,577 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
# Pull docker image from docker hub
# XTERM used for better catkin_make output
docker:
- image: usdotfhwastol/carma-base:carma-system-3.4.0
- image: usdotfhwastoldev/carma-base:develop
user: carma
environment:
TERM: xterm # use xterm to get full display output from build
Expand Down
9 changes: 5 additions & 4 deletions .sonarqube/sonar-scanner.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ sonar.scm.provider=git
sonar.cfamily.cache.enabled=false

# Modules
sonar.modules=carla_ackermann_control_wrapper
#sonar.modules=carla_ackermann_control_wrapper

carla_ackermann_control_wrapper.sonar.projectBaseDir=/opt/carma/src/carma-simulation/carla_ackermann_control_wrapper
#carla_ackermann_control_wrapper.sonar.projectBaseDir=/opt/carma/src/carma-simulation/carla_ackermann_control_wrapper

# C++ Package differences
# Sources
carla_ackermann_control_wrapper.sonar.sources=src
#carla_ackermann_control_wrapper.sonar.sources=src

# Tests
# Note: For C++ setting this field does not cause test analysis to occur. It only allows the test source code to be evaluated.
carla_ackermann_control_wrapper.sonar.tests=test
#carla_ackermann_control_wrapper.sonar.tests=test
151 changes: 126 additions & 25 deletions Dockerfile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,42 +1,143 @@
# Copyright (C) 2018-2020 LEIDOS.
#
# Copyright (C) 2018-2021 LEIDOS.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

FROM usdotfhwastol/carma-base:carma-system-3.4.0 as deps
FROM ubuntu:18.04

FROM deps as setup
MAINTAINER Leidos, Inc.
LABEL Description="Dockerised Simulation of Carla_Sumo_Mosaic"

RUN mkdir ~/src
COPY --chown=carma . /home/carma/src/
RUN ~/src/docker/checkout.sh
RUN ~/src/docker/install.sh
ENV SUMO_HOME /usr/share/sumo
ENV SUMO_USER carla_sumo_mosaic

FROM deps

ARG BUILD_DATE="NULL"
ARG VERSION="NULL"
ARG VCS_REF="NULL"
ENV CARLA_HOME /CARLA_0.9.10/
RUN export CARLA_HOME

LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name="carla-ackermann-control-wrapper-driver"
LABEL org.label-schema.description="carla ackermann control wrapper driver for the CARMA Platform"
LABEL org.label-schema.vendor="Leidos"
LABEL org.label-schema.version=${VERSION}
LABEL org.label-schema.url="https://highways.dot.gov/research/research-programs/operations/CARMA"
LABEL org.label-schema.vcs-url="https://github.com/usdot-fhwa-stol/carma-simulation/"
LABEL org.label-schema.vcs-ref=${VCS_REF}
LABEL org.label-schema.build-date=${BUILD_DATE}
RUN apt-get update && \
apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean && \
rm -rf /var/lib/apt/lists/ && \
rm -rf /var/cache/oracle-jdk8-installer;

COPY --from=deps /home/carma/install /opt/carma/install
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME

CMD [ "wait-for-it.sh", "localhost:11311", "--", "roslaunch", "carla_ackermann_control_wrapper", "carla_ackermann_control_wrapper.launch"]
RUN apt-get -y update

RUN apt-get install x11-xserver-utils dconf-editor dbus-x11 -y

RUN apt-get update && apt-get upgrade -y && apt-get clean

# Python package management and basic dependencies
RUN apt-get install -y curl python3.7 python3.7-dev python3.7-distutils

# Register the version in alternatives
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1

# Set python 3 as the default python
RUN update-alternatives --set python /usr/bin/python3.7

RUN curl -s https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
python get-pip.py --force-reinstall && \
rm get-pip.py

RUN pip3.7 install lxml

# Dependencies for glvnd and X11.
RUN apt-get update \
&& apt-get install -y -qq --no-install-recommends \
libglvnd0 \
libgl1 \
libglx0 \
libegl1 \
libxext6 \
libx11-6 \
&& rm -rf /var/lib/apt/lists/*

# Env vars for the nvidia-container-runtime.
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES graphics,utility,compute

RUN apt-get update && \
apt-get install -y software-properties-common && \
rm -rf /var/lib/apt/lists/*

# Install python3.6 for NS-3 installation
RUN add-apt-repository ppa:deadsnakes/ppa && \
apt update && \
apt install python3.6

# Install other dependencies
RUN apt-get update && \
apt-get install -y g++ gcc unzip tar python3-dev && \
apt-get install -y autoconf automake libtool curl make && \
apt-get install -y libxml2 libsqlite3-dev && \
apt-get install -y libxml2-dev

RUN \
apt-get update && \
apt-get install -y --allow-unauthenticated \
build-essential \
pkg-config \
lbzip2 \
libprotobuf-dev \
libsqlite3-dev \
protobuf-compiler \
patch \
rsync \
wget

# Install vim as text editor
RUN apt-get install -y vim

RUN apt-get install -y nano

RUN apt-get install -y xterm

RUN apt install -y default-jdk

# Install SUMO
RUN add-apt-repository ppa:sumo/stable

RUN apt-get update

RUN apt-get install -y \
sumo \
sumo-tools \
sumo-doc

RUN adduser $SUMO_USER --disabled-password

# Enable sudo
RUN apt-get update && apt-get install -y sudo

RUN adduser $SUMO_USER sudo --disabled-password

COPY co-simulation/traci_update/connection.py ./usr/share/sumo/tools/traci/
COPY co-simulation/traci_update/constants.py ./usr/share/sumo/tools/traci/
COPY co-simulation/traci_update/main.py ./usr/share/sumo/tools/traci/

RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> \
/etc/sudoers


### Docker (Optional) ###
# RUN apt-get update && \
# apt-get -qy full-upgrade && \
# apt-get install -qy curl && \
# apt-get install -qy curl && \
# curl -sSL https://get.docker.com/ | sh

# RUN adduser $SUMO_USER docker --disabled-password
159 changes: 159 additions & 0 deletions Instruction/Build Docker Image Instruction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Running CARLA-SUMO-MOSAIC Co-Simulation Tool with NS-3 Integration in Docker

This is the tutorial to run CARLA-SUMO-MOSAIC co-simulation tool in a docker container. It is recommended to run the co-simulation tool on a **high-performance** computer.

## Test Platform

- Operating System: Ubuntu 20.04.2 LTS
- CPU: Intel(R) Core(TM) i7-9700K CPU @ 3.60 GHz
- RAM: 16 GB
- Graphics: NVIDIA GeForce RTX 2070 Super 8 GB

## Prerequisites

- NVIDIA GPU with at least 8 GB
- NVIDIA drivers > 361.93
- Free Disk Space > 30 GB
- NVIDIA Container Toolkit
- Docker

If you do not have Docker installed, please refer to this [link](https://usdot-carma.atlassian.net/wiki/spaces/CRMPLT/pages/486178841/Setup+CARMA+Platform+Prerequisites#Install-docker-using-docker-install.sh-in-CARMA-Platform-repo) for installation.

If you do not have NVIDIA Container Toolkit installed, please refer to this [link](https://usdot-carma.atlassian.net/wiki/spaces/CRMPLT/pages/486178841/Setup+CARMA+Platform+Prerequisites#CUDA-11.2-(Non-VM-installation)) for installation.

## Build/Pull Docker Image of Co-Simulation Tool

There are two ways to get co-simulation docker image. You can either choose to pull the co-simulation tool docker image from DockerHub or build the image by yourself.

#### Option 1, Pull Docker Image

To pull the co-simulation tool from DockerHub, make sure that you have been installed the docker tool into your system and have been login your personal account.

##### Step 1: Simply type the command to pull the docker image:

```sh
docker pull usdotfhwastol/carma-xil-cosimulation:[tag]
```

The tag information could be found from [usdotfhwastol Dockerhub](https://hub.docker.com/repository/docker/usdotfhwastol/carma-xil-cosimulation/tags?page=1&ordering=last_updated)

##### Step 2: Run docker image with a container:

```sh
cd <path-to-CARMA-simulation>/docker && ./run.sh -v [version]
```

Once you access the conainer, skip the option 2 and go to the `Run carma-xil-cosimulation` step to test the co-simulation

#### Option 2, Build Docker Image
##### Prerequisites

To build the co-simulation tool docker image, the executable `carla_sumo_mosaic` file should be created firstly. The executable zip file located at the co-simulation folder as the name `carla-sumo-mosaic-[version].zip`. Extract the all contents into an empty folder with the name `carla_sumo_mosaic` then remember the directory of the folder for the later usage

##### Step 1: Build image from Dockerfile by using following command:

```sh
cd <path-to-CARMA-simulation>/docker && ./build-image.sh -v [version]
```

##### Step 2: Run docker image with a docker container

```sh
cd <path-to-CARMA-simulation>/docker && ./run.sh -v [version]
```

##### Step 3: Copy CARLA and Co-Simulation tool

Copy `CARLA_0.9.10`, executable `carla_sumo_mosaic` and `bridge` into the container.

```
docker cp <path-to-CARLA-simulation>/CARLA_0.9.10 <container-id>:./
docker cp <path-to-unzipped-carla-sumo-mosaic-folder>/carla_sumo_mosaic <container-id>:./
docker cp <path-to-CARMA-simulation>/co-simulation/bridge <container-id>:./
```

##### Step 4: Unzip scenarios from sample_scenario.zip at co-simulation folder and copy to docker

```
docker cp <path-to-folder>/Town04_20 <container-id>:./carla_sumo_mosaic/scenarios
```

### Modify files in Docker Container

#### Step 1: Modify `ns3_installer.sh`

In Docker container, type:

```sh
cd carla_sumo_mosaic/bin/fed/ns3
```

Then modify `ns3_installer.sh` by:

```
vim ns3_installer.sh
```

(If you see a message `vim: command not found`, please use `sudo apt-get install vim` to install vim as text editor)

In the `build_ns3()` function, after `CXXFLAGS="-Wno-error" python3.6 ./build.py --disable-netanim`, add the following command

```
sudo cp -ar ns-3.28/build/ns3 /usr/include/
```

#### Step 2: Build NS-3

In directory `carla_sumo_mosaic/bin/fed/ns3`, type:

```
./ns3_installer.sh
```

Once all 1947 files are compiled and a successful message shows up, it means NS-3 is successful installed.

#### Step 3: Add NS-3 as environment variable

```
export NS3_HOME='/carla_sumo_mosaic/bin/fed/ns3'
```

Use `printenv` to check if NS-3 is successful added to environment variable.

#### Step 4: Modify `run.sh`

In directory `carla_sumo_mosaic/bin/fed/ns3`, type:

```
vim run.sh
```

Change line 11 to:

```
LD_LIBRARY_PATH=/carla_sumo_mosaic/bin/fed/ns3/ns-allinone-3.28/ns-3.28/build /carla_sumo_mosaic/bin/fed/ns3/ns-allinone-3.28/ns-3.28/build/scratch/mosaic_starter --port=$port --cmdPort=$cmdport --configFile=scratch/ns3_federate_config.xml
```

## Run Co-Simulation Tool

Once everything is ready, under directory `/carla_sumo_mosaic`, simply type:

```
./mosaic.sh -s Town04_20
```

The command will start CARLA, SUMO and x-terminal showing the CALRA-MOSAIC loading status

![carla_sumo_mosaic_ready](../../co-simulation/doc/gif/ready.gif)

When the x-terminal showing the CARLA-MOSAIC status is connected, simply click the SUMO play button to start the program

![carla_sumo_mosaic](../../co-simulation/doc/gif/carla_sumo_mosaic_demo.gif)

***Note: Current CARMA XIL Version has a known issue with a port conflict between NS-3 and CARMA-CARLA integration see [#39](https://github.com/usdot-fhwa-stol/carma-simulation/issues/39). The recommended workaround is to run exclusively one or the other module.***

### Commit the container back to image
After the run if there is no issue, commit docker container to docker image
```
docker container commit <container-id> usdotfhwastol/carma-xil-cosimulation:[tag]
```
Loading

0 comments on commit 9076936

Please sign in to comment.