From 14427649047310c3a92a1cafa75770450bcc2959 Mon Sep 17 00:00:00 2001 From: Saurabh Kamat Date: Sun, 22 Dec 2024 17:23:08 +0800 Subject: [PATCH 1/2] Added dockerfiles and compose with updated README instructions Signed-off-by: Saurabh Kamat --- README.md | 53 ++++++++++++++++++++++++- docker-compose.yaml | 30 ++++++++++++++ docker/dev-overlay.Dockerfile | 61 +++++++++++++++++++++++++++++ docker/nvidia-ros-noetic.Dockerfile | 47 ++++++++++++++++++++++ docker/ros_entrypoint.sh | 5 +++ 5 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yaml create mode 100644 docker/dev-overlay.Dockerfile create mode 100644 docker/nvidia-ros-noetic.Dockerfile create mode 100755 docker/ros_entrypoint.sh diff --git a/README.md b/README.md index 43741023..c5b5beff 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,57 @@ roslaunch me5413_world navigation.launch * `/me5413_world/relative/heading_error` (in degrees, wrt `map` frame, `std_msgs::Float32`) * `/me5413_world/relative/position_error` (in meters wrt `map` frame, `std_msgs::Float32`) +## Docker Support + +This repository provides Docker support for setting up and managing a ROS Noetic environment with GPU acceleration. The `docker` folder contains the following `Dockerfiles` +that can be used to build the container images. + +1. `nvidia-ros-noetic.Dockerfile`: Builds a ROS Noetic image using an NVIDIA CUDA-based Ubuntu base image and includes GPU support for ROS applications. + +```bash + # From the root of the repository build the GPU accelerated ROS Noetic image + docker build -f docker/nvidia-ros-noetic.Dockerfile -t nvidia-ros-noetic . +``` + +1. `dev-overlay.Dockerfile`: Builds on the ROS Noetic base image to create a container environment with volume-mounted `src` folder for development. + +```bash + # From the root of the repository build the development image + docker build -f docker/dev-overlay.Dockerfile -t dev-overlay . +``` + +The root of the repository contains a `docker-compose.yaml` that can be used to launch the development environment using the following command, + +```bash + # Disable access control to X11 server + xhost + + + # Launch the docker environment + docker compose up +``` + +The development environment can be accessed using the following command, + +```bash + # With appuser privilages + docker exec -it dev-overlay bash + + # With root privilages + docker exec -it -u 0 dev-overlay bash +``` + +The development environment can be modified by adding commands in `docker/dev-overlay.Dockerfile` in the following section. + +``` + # Put your code here to run additional commands + ####################################################################### + + + + + ####################################################################### +``` + ## Contribution You are welcome contributing to this repo by opening a pull-request @@ -188,4 +239,4 @@ We are following: ## License -The [ME5413_Final_Project](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project) is released under the [MIT License](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project/blob/main/LICENSE) \ No newline at end of file +The [ME5413_Final_Project](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project) is released under the [MIT License](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project/blob/main/LICENSE) diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..3dff1f98 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,30 @@ +version: "3.9" + +services: + # ROS Noetic image + nvidia-ros-noetic: + image: nvidia-ros-noetic + container_name: nvidia-ros-noetic + build: + context: . + dockerfile: docker/nvidia-ros-noetic.Dockerfile + network_mode: host + environment: + - DISPLAY=${DISPLAY} + - QT_X11_NO_MITSHM=1 + - NVIDIA_DRIVER_CAPABILITIES=all + volumes: + - /tmp/.X11-unix:/tmp/.X11-unix:rw + - ${XAUTHORITY:-$HOME/.Xauthority}:/root/.Xauthority + + dev-overlay: + extends: nvidia-ros-noetic + image: dev-overlay + container_name: dev-overlay + build: + context: . + dockerfile: docker/dev-overlay.Dockerfile + network_mode: host + volumes: + - ./src:/appuser/catkin_ws/src:rw + command: sleep infinity diff --git a/docker/dev-overlay.Dockerfile b/docker/dev-overlay.Dockerfile new file mode 100644 index 00000000..ca06fc9b --- /dev/null +++ b/docker/dev-overlay.Dockerfile @@ -0,0 +1,61 @@ +FROM nvidia-ros-noetic:latest +SHELL [ "/bin/bash", "-c" ] + +# Set env variables for rosdep +ENV ROS_PYTHON_VERSION=3 +ENV ROS_DISTRO=noetic + +# Create new user with full permission to the volume mount +RUN useradd --create-home appuser + +# Copy the src folder for volume mount +USER appuser + +WORKDIR /appuser + +RUN mkdir -p catkin_ws/src + +COPY ./src catkin_ws/src + +# Run rosdep to install dependencies +USER root + +WORKDIR /appuser/catkin_ws + +RUN apt-get update --fix-missing \ + && rosdep update + +RUN rosdep install --from-paths src --ignore-src -r -y + +# Download Gazebo models +USER appuser + +WORKDIR /home/appuser + +RUN git clone https://github.com/osrf/gazebo_models.git + +RUN mkdir -p .gazebo/models \ + && cp -r gazebo_models/* .gazebo/models \ + && cp -r /appuser/catkin_ws/src/me5413_world/models/* .gazebo/models + + +# Put your code here to run additional commands +####################################################################### + + + + +####################################################################### + + +# Build the entire package +USER appuser + +WORKDIR /appuser/catkin_ws + +RUN source /opt/ros/noetic/setup.bash \ + && catkin config --install \ + && catkin build + +RUN echo "source /appuser/catkin_ws/devel/setup.bash" >> ~/.bashrc + diff --git a/docker/nvidia-ros-noetic.Dockerfile b/docker/nvidia-ros-noetic.Dockerfile new file mode 100644 index 00000000..e81a3df0 --- /dev/null +++ b/docker/nvidia-ros-noetic.Dockerfile @@ -0,0 +1,47 @@ +# Ubuntu 20.04 base image with NVIDIA CUDA and ROS Noetic +FROM nvidia/cudagl:11.2.1-base-ubuntu20.04 +SHELL ["/bin/bash", "-c"] + +# Install apt packages +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y \ + locales \ + lsb-release + +RUN dpkg-reconfigure locales + +RUN apt-get update && apt-get install -y \ + git \ + g++ \ + cmake \ + gnupg \ + gnupg1 \ + gnupg2 \ + wget + +# Install ROS Noetic +RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' + +RUN apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 + +RUN apt-get update \ + && apt-get install -y --no-install-recommends ros-noetic-desktop-full + +RUN apt-get install -y --no-install-recommends python3-rosdep + +RUN rosdep init \ + && rosdep fix-permissions \ + && rosdep update + +RUN echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc + +# Install python3 dependencies +RUN apt-get install -y \ + python3-pip \ + python3-catkin-tools \ + python3-opencv + +COPY ./docker/ros_entrypoint.sh / +ENTRYPOINT [ "/ros_entrypoint.sh" ] + diff --git a/docker/ros_entrypoint.sh b/docker/ros_entrypoint.sh new file mode 100755 index 00000000..6385ae1b --- /dev/null +++ b/docker/ros_entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +source /opt/ros/noetic/setup.bash + +exec "$@" From 63b8394c740d07c9fe4808ce38e4600885b82401 Mon Sep 17 00:00:00 2001 From: Saurabh Kamat Date: Sun, 22 Dec 2024 18:04:50 +0800 Subject: [PATCH 2/2] Modified docker section Signed-off-by: Saurabh Kamat --- README.md | 96 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index c5b5beff..615d674d 100644 --- a/README.md +++ b/README.md @@ -148,74 +148,64 @@ roslaunch me5413_world navigation.launch ![rviz_navigation_image](src/me5413_world/media/rviz_navigation.png) -## Student Tasks - -### 1. Map the environment - -* You may use any SLAM algorithm you like, any type: - * 2D LiDAR - * 3D LiDAR - * Vision - * Multi-sensor -* Verify your SLAM accuracy by comparing your odometry with the published `/gazebo/ground_truth/state` topic (`nav_msgs::Odometry`), which contains the gournd truth odometry of the robot. -* You may want to use tools like [EVO](https://github.com/MichaelGrupp/evo) to quantitatively evaluate the performance of your SLAM algorithm. - -### 2. Using your own map, navigate your robot - -* From the starting point, move to the given pose within each area in sequence - * Assembly Line 1, 2 - * Random Box 1, 2, 3, 4 - * Delivery Vehicle 1, 2, 3 -* We have provided you a GUI in RVIZ that allows you to click and publish these given goal poses to the `/move_base_simple/goal` topic: - - ![rviz_panel_image](src/me5413_world/media/rviz_panel.png) - -* We also provides you four topics (and visualized in RVIZ) that computes the real-time pose error between your robot and the selelcted goal pose: - * `/me5413_world/absolute/heading_error` (in degrees, wrt `world` frame, `std_msgs::Float32`) - * `/me5413_world/absolute/position_error` (in meters, wrt `world` frame, `std_msgs::Float32`) - * `/me5413_world/relative/heading_error` (in degrees, wrt `map` frame, `std_msgs::Float32`) - * `/me5413_world/relative/position_error` (in meters wrt `map` frame, `std_msgs::Float32`) - ## Docker Support +This repository provides Docker support for setting up and managing a ROS Noetic environment with GPU acceleration. +The docker folder includes the following Dockerfiles to build container images: -This repository provides Docker support for setting up and managing a ROS Noetic environment with GPU acceleration. The `docker` folder contains the following `Dockerfiles` -that can be used to build the container images. +#### 1. `nvidia-ros-noetic.Dockerfile` +This file creates a ROS Noetic image using an NVIDIA CUDA-based Ubuntu base image, providing GPU support for ROS applications. -1. `nvidia-ros-noetic.Dockerfile`: Builds a ROS Noetic image using an NVIDIA CUDA-based Ubuntu base image and includes GPU support for ROS applications. +To build the image, ```bash # From the root of the repository build the GPU accelerated ROS Noetic image docker build -f docker/nvidia-ros-noetic.Dockerfile -t nvidia-ros-noetic . ``` -1. `dev-overlay.Dockerfile`: Builds on the ROS Noetic base image to create a container environment with volume-mounted `src` folder for development. +#### 2. `dev-overlay.Dockerfile` + +This file extends the ROS Noetic base image, setting up a development container with the volume-mounted `src` folder +containing all the packages. Any new packages created in the `src` folder will automatically appear inside the running container. + +To build the development image, ```bash # From the root of the repository build the development image docker build -f docker/dev-overlay.Dockerfile -t dev-overlay . ``` +### Launching the development environment +The repository includes a `docker-compose.yaml` file in the root directory to simplify launching the development environment. Use the following steps: -The root of the repository contains a `docker-compose.yaml` that can be used to launch the development environment using the following command, +1. Allow X11 access for Gazebo ```bash - # Disable access control to X11 server xhost + +``` - # Launch the docker environment +2. Start the development environment + +```bash docker compose up ``` -The development environment can be accessed using the following command, +### Accessing the development environment + +Once the container is running, you can access it using the following commands: + +- With `appuser` privilages ```bash - # With appuser privilages docker exec -it dev-overlay bash +``` +- With `root` privilages - # With root privilages +```bash docker exec -it -u 0 dev-overlay bash ``` -The development environment can be modified by adding commands in `docker/dev-overlay.Dockerfile` in the following section. +### Customizing the development environment + +The development environment can be extended by adding custom commands to `docker/dev-overlay.Dockerfile` in the designated section: ``` # Put your code here to run additional commands @@ -227,6 +217,34 @@ The development environment can be modified by adding commands in `docker/dev-ov ####################################################################### ``` +## Student Tasks + +### 1. Map the environment + +* You may use any SLAM algorithm you like, any type: + * 2D LiDAR + * 3D LiDAR + * Vision + * Multi-sensor +* Verify your SLAM accuracy by comparing your odometry with the published `/gazebo/ground_truth/state` topic (`nav_msgs::Odometry`), which contains the gournd truth odometry of the robot. +* You may want to use tools like [EVO](https://github.com/MichaelGrupp/evo) to quantitatively evaluate the performance of your SLAM algorithm. + +### 2. Using your own map, navigate your robot + +* From the starting point, move to the given pose within each area in sequence + * Assembly Line 1, 2 + * Random Box 1, 2, 3, 4 + * Delivery Vehicle 1, 2, 3 +* We have provided you a GUI in RVIZ that allows you to click and publish these given goal poses to the `/move_base_simple/goal` topic: + + ![rviz_panel_image](src/me5413_world/media/rviz_panel.png) + +* We also provides you four topics (and visualized in RVIZ) that computes the real-time pose error between your robot and the selelcted goal pose: + * `/me5413_world/absolute/heading_error` (in degrees, wrt `world` frame, `std_msgs::Float32`) + * `/me5413_world/absolute/position_error` (in meters, wrt `world` frame, `std_msgs::Float32`) + * `/me5413_world/relative/heading_error` (in degrees, wrt `map` frame, `std_msgs::Float32`) + * `/me5413_world/relative/position_error` (in meters wrt `map` frame, `std_msgs::Float32`) + ## Contribution You are welcome contributing to this repo by opening a pull-request