Skip to content

Commit

Permalink
Add Docker with ROS Melodic + Gazebo 9 + nvidia-docker2 (#16)
Browse files Browse the repository at this point in the history
* Docker container: first commit

* Fix Error in Dockerfile

* Start testing vcstool

* Add Github dependencies using vcstool

* Edit building instructions

* Delete

* Clean up package.xml in ca_move_base

* Delete unnecessary kobuki_msgs dependency

* Edit Docker instructions

* Fix Dockerfile

* Docker container: first commit

* Delete kobuki_msgs dependency

* Fix Dockerfile

* Add EOL

* Edit README
  • Loading branch information
eborghi10 authored Mar 5, 2019
1 parent 2f61d69 commit 9a6e06e
Show file tree
Hide file tree
Showing 13 changed files with 463 additions and 24 deletions.
38 changes: 23 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,12 @@ $ sudo apt-get install python-rosdep python-catkin-tools
$ mkdir -p ~/create_ws/src
```

2. Clone this repo and its dependencies
2. Clone this repo
``` bash
$ cd ~/create_ws/src
$ git clone https://github.com/RoboticaUtnFrba/create_autonomy.git && \
git clone https://github.com/RoboticaUtnFrba/libcreate.git && \
git clone https://github.com/RoboticaUtnFrba/RTIMULib2.git && \
git clone https://github.com/RoboticaUtnFrba/i2c_imu.git && \
git clone https://github.com/RoboticaUtnFrba/viso2.git && \
git clone https://github.com/RoboticaUtnFrba/gscam.git
$ git clone https://github.com/RoboticaUtnFrba/create_autonomy.git
```

**Note:** this approach will be changed with a next PR using `vcstool`.

3. Compile RTIMULib2
```bash
$ cd ~/create_ws/src/RTIMULib2/Linux && mkdir build && cd build
Expand All @@ -81,14 +74,29 @@ $ sudo apt-get install python-rosdep python-catkin-tools
``` bash
$ sudo apt-get install -y gstreamer1.0-tools libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev
$ cd ~/create_ws
$ rosdep install --from-path src/ -y -i
$ sudo apt install -y python3-vcstool
$ vcs import src < src/create_autonomy/<DEVICE>.repos
$ rosdep update
$ rosdep install --from-paths src -i
```

4. Build
``` bash
$ cd ~/create_ws
$ catkin_make
```
4. Build

4.1. Build RTIMULib2 for Raspberry Pi

$ cd ~/create_ws/src/RTIMULib2/Linux
$ mkdir build
$ cd build
$ cmake ..
$ make -j4
$ sudo make install
$ sudo ldconfig

4.2. Build workspace

$ cd ~/create_ws
$ catkin_make -DCMAKE_BUILD_TYPE=Release

#### USB Permissions
5. In order to connect to Create over USB, ensure your user is in the dialout group
``` bash
Expand Down
11 changes: 5 additions & 6 deletions ca_bumper2pc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
cmake_minimum_required(VERSION 2.8.3)
project(ca_bumper2pc)
find_package(catkin REQUIRED COMPONENTS
roscpp
nodelet
pluginlib
find_package(catkin REQUIRED COMPONENTS
roscpp
nodelet
pluginlib
ca_msgs
sensor_msgs
kobuki_msgs
sensor_msgs
)

catkin_package(
Expand Down
4 changes: 1 addition & 3 deletions ca_bumper2pc/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
<build_depend>pluginlib</build_depend>
<build_depend>ca_msgs</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>kobuki_msgs</build_depend>

<run_depend>roscpp</run_depend>
<run_depend>nodelet</run_depend>
<run_depend>pluginlib</run_depend>
<run_depend>ca_msgs</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>kobuki_msgs</run_depend>


<export>
<nodelet plugin="${prefix}/plugins/nodelet_plugins.xml"/>
</export>
Expand Down
18 changes: 18 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# If you want to rebuild all images, set this to --no-cache from the commandline
DOCKER_ARGS?=

.PHONY: create_ubuntu_bionic
create_ubuntu_bionic:
docker build ${DOCKER_ARGS} -t create_ubuntu_bionic create_ubuntu_bionic

.PHONY: create_ros_melodic
create_ros_melodic: create_ubuntu_bionic
docker build ${DOCKER_ARGS} -t create_ros_melodic create_ros_melodic

.PHONY: create_gazebo9
create_gazebo9: create_ros_melodic
docker build ${DOCKER_ARGS} -t create_gazebo9 create_gazebo9

.PHONY: create_nvidia
create_nvidia: create_gazebo9
docker build ${DOCKER_ARGS} -t create_nvidia create_nvidia
95 changes: 95 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# ROS Melodic + Gazebo 9 on Docker

## Step 1: Install Docker
[Install docker](https://docs.docker.com/engine/installation/linux/ubuntu/) and [configure after postintalling it](https://docs.docker.com/install/linux/linux-postinstall/).

To run docker without super user:

```bash
$ sudo groupadd docker
$ sudo gpasswd -a ${USER} docker
$ sudo service docker restart
```

## Step 2: Use NVIDIA acceleration

### Install [nvidia-docker2](https://github.com/nvidia/nvidia-docker/wiki/Installation-(version-2.0))

#### Prerequisites

1. GNU/Linux x86_64 with kernel version > 3.10
2. Docker >= 1.12
3. NVIDIA GPU with Architecture > Fermi (2.1)
4. NVIDIA drivers ~= 361.93 (untested on older versions)

#### Removing nvidia-docker 1.0

Version 1.0 of the nvidia-docker package must be cleanly removed before continuing.
You must stop and remove all containers started with nvidia-docker 1.0.

```bash
$ docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
$ sudo apt-get purge nvidia-docker
```

#### Installing version 2.0

Make sure you have installed the [NVIDIA driver](https://github.com/NVIDIA/nvidia-docker/wiki/Frequently-Asked-Questions#how-do-i-install-the-nvidia-driver).

If you have a custom `/etc/docker/daemon.json`, the `nvidia-docker2` package might override it.

Install the repository for your distribution by following the instructions here.

```bash
$ wcurl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
sudo apt-key add -
$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
sudo tee /etc/apt/sources.list.d/nvidia-docker.list
$ sudo apt-get update
```

Add Docker's official GPG key.

```bash
$ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
sudo apt-key add -
```

Install the `nvidia-docker2` package and reload the Docker daemon configuration:

```bash
$ sudo apt-get install nvidia-docker2
$ sudo pkill -SIGHUP dockerd
```

## Step 3: Creating the container

This repository contain the Dockerfile. Move into the directory containing the file and type

The command below will **create** the container from the base image if it doesn't exist and log you in.

```bash
$ make create-melodic-gazebo9
```

## Step 4: Start the container

To make it easier, I created the launcher **launch_docker.sh** (you might need to call **chmod +x ./launch_docker.sh** first).

```bash
$ ./launch_docker.sh -d create_nvidia
```

Every time you launch the Docker container, you'll need to compile the workspace and source:

```bash
$ catkin_make -DCMAKE_BUILD_TYPE=Release -j4
$ source devel/setup.bash
```

# References

* http://wiki.ros.org/docker/Tutorials/Docker
* http://wiki.ros.org/docker/Tutorials/Hardware%20Acceleration
* http://wiki.ros.org/docker/Tutorials/GUI
114 changes: 114 additions & 0 deletions docker/create-melodic-gazebo9/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
FROM ros:melodic-ros-base
LABEL maintainer="Emiliano Borghi"

ENV ROS_DISTRO melodic

RUN apt-get update && \
apt-get install --no-install-recommends -y \
apt-utils \
curl \
dialog \
software-properties-common \
tmux \
wget

# Setup environment
ENV \
LANG=en_US.UTF-8 \
DEBIAN_FRONTEND=noninteractive \
TERM=xterm
RUN apt-get update && apt-get install -y locales
RUN locale-gen en_US.UTF-8

# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
ros-${ROS_DISTRO}-gazebo-* \
&& rm -rf /var/lib/apt/lists/*

# ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# Setup sources.list for ROS
RUN echo "deb http://packages.ros.org/ros/ubuntu bionic main" > /etc/apt/sources.list.d/ros-latest.list

# Setup keys for ROS
RUN apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

# Setup sources.list for Gazebo
RUN echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable bionic main" > /etc/apt/sources.list.d/gazebo-stable.list

# Setup keys for Gazebo
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys D2486D2DD83DB69272AFE98867170598AF249743

# Install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
python-rosdep \
python-rosinstall \
python3-vcstool

# Install ROS packages
RUN apt-get update && \
apt-get install -y \
gazebo9 \
libgazebo9-dev

RUN apt-get clean -y && \
apt-get autoremove -y && \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /usr/share/doc

# Install dependencies for gscam and visual odometry
RUN apt-get update && \
apt-get install -y \
gstreamer1.0-tools \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-good1.0-dev

# Install ROS dependencies
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
ros-${ROS_DISTRO}-amcl \
ros-${ROS_DISTRO}-camera-calibration \
ros-${ROS_DISTRO}-controller-manager \
ros-${ROS_DISTRO}-ecl-threads \
ros-${ROS_DISTRO}-gazebo-ros-pkgs \
ros-${ROS_DISTRO}-joint-state-publisher \
ros-${ROS_DISTRO}-joy-teleop \
ros-${ROS_DISTRO}-map-server \
ros-${ROS_DISTRO}-move-base \
ros-${ROS_DISTRO}-pcl-ros \
ros-${ROS_DISTRO}-robot-localization \
ros-${ROS_DISTRO}-robot-state-publisher \
ros-${ROS_DISTRO}-yocs-controllers \
ros-${ROS_DISTRO}-xacro \
&& \
apt-get clean && \
apt-get autoremove && \
apt-get autoclean && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /usr/share/doc

# Compile RTIMULib2 and IMU dependencies
RUN mkdir -p /home/${USER}/catkin_ws/src
WORKDIR /home/${USER}/catkin_ws/src
RUN git clone https://github.com/RoboticaUtnFrba/RTIMULib2.git && \
git clone https://github.com/RoboticaUtnFrba/i2c_imu.git
WORKDIR /home/${USER}/catkin_ws/src/RTIMULib2/Linux
RUN apt-get update && apt-get install -y libqt4-dev
RUN mkdir build && \
cd build && \
cmake .. && \
make -j4 && \
make install && \
ldconfig

ENV PATH /usr/local/nvidia/bin:${PATH}
ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH}

RUN echo ". /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/${USER}/.bashrc

WORKDIR /home/${USER}/catkin_ws

CMD [ "tmux" ]
21 changes: 21 additions & 0 deletions docker/create_gazebo9/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM create_ros_melodic
LABEL maintainer="Emiliano Borghi"

ENV ROS1_DISTRO=melodic

USER root

# Setup sources.list for Gazebo
RUN echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable bionic main" > /etc/apt/sources.list.d/gazebo-stable.list

# Setup keys for Gazebo
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys D2486D2DD83DB69272AFE98867170598AF249743

RUN apt-get update && \
apt-get install -y \
gazebo9 \
libgazebo9-dev \
ros-$ROS1_DISTRO-gazebo-ros-pkgs \
ros-$ROS1_DISTRO-gazebo-ros-control

CMD tmux
15 changes: 15 additions & 0 deletions docker/create_nvidia/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu16.04 as nvidia
FROM create_gazebo9
LABEL maintainer="Emiliano Borghi"

# Installing OpenGL for nvidia-docker2
# https://stackoverflow.com/a/53823600

COPY --from=nvidia /usr/local /usr/local
COPY --from=nvidia /etc/ld.so.conf.d/glvnd.conf /etc/ld.so.conf.d/glvnd.conf

ENV NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=all

RUN apt-get update

USER create
Loading

0 comments on commit 9a6e06e

Please sign in to comment.