Skip to content

Commit

Permalink
Add gazebo docker image for curiosity rover demo
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinselva committed Sep 11, 2024
1 parent cd2f1eb commit e68ca4d
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 156 deletions.
76 changes: 76 additions & 0 deletions curiosity_rover/Dockerfile.GUI
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
FROM ros:humble-ros-core-jammy

ARG DEBIAN_FRONTEND=noninteractive

ENV RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
ENV ROS_DISTRO=humble
ENV USERNAME=spaceros-user
ENV HOME=/home/spaceros-user
ENV IGNITION_VERSION=fortress
ENV GZ_VERSION=fortress

# Install dependencies
RUN apt update && apt install -y ros-${ROS_DISTRO}-rmw-cyclonedds-cpp \
wget \
curl \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*

RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg\
&& echo "deb [arch=amd64 signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null

# Install Gazebo
RUN apt-get update -qq \
&& apt-get install -y \
gz-${GZ_VERSION} \
libgz-sim7 \
libgz-transport12 \
libgz-gui7 \
build-essential\
ros-${ROS_DISTRO}-rcl-interfaces\
ros-${ROS_DISTRO}-rclcpp\
ros-${ROS_DISTRO}-builtin-interfaces\
ros-${ROS_DISTRO}-ros-gz\
ros-${ROS_DISTRO}-sdformat-urdf\
ros-${ROS_DISTRO}-vision-msgs\
ros-${ROS_DISTRO}-actuator-msgs\
ros-${ROS_DISTRO}-image-transport\
ros-${ROS_DISTRO}-xacro\
&& rm -rf /var/lib/apt/lists/*


# Install Rviz2
RUN apt-get update -qq \
&& apt-get install -y \
ros-${ROS_DISTRO}-rviz2 \
ros-${ROS_DISTRO}-moveit-ros-visualization \
ros-${ROS_DISTRO}-nav2-rviz-plugins \
&& rm -rf /var/lib/apt/lists/*

# Demo package
RUN mkdir -p ${HOME}/curiosity_ws/src
WORKDIR ${HOME}/curiosity_ws/src
COPY ./curiosity_description ./curiosity_description
COPY ./curiosity_gazebo ./curiosity_gazebo
COPY .defaults.yaml ${HOME}/curiosity_ws/.defaults.yaml

RUN apt update \
&& apt install -y python3-rosdep python3-colcon-common-extensions \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* \
&& rosdep init \
&& rosdep update

RUN . /opt/ros/humble/setup.sh \
&& cd ${HOME}/curiosity_ws \
&& apt update \
&& rosdep install --from-paths src --ignore-src -r -y \
&& colcon build

WORKDIR ${HOME}/curiosity_ws

RUN apt update && apt install -y ros-humble-ros-ign-gazebo
RUN echo "source /opt/ros/humble/setup.bash" >> ${HOME}/.bashrc
RUN echo "source ${HOME}/curiosity_ws/install/setup.bash" >> ${HOME}/.bashrc

CMD ign gazebo
101 changes: 1 addition & 100 deletions curiosity_rover/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,4 @@

set -e

# Define variables
DOCKER_IMAGE="osrf/space-ros:curiosity_demo"
LOCAL_WORKSPACE=$(pwd)
SHELL="/bin/bash"

# Define packages
SIM_PACKAGES="curiosity_description curiosity_gazebo"
CONTROL_PACKAGE="curiosity_rover_demo"
DEMO_PACKAGES="$CONTROL_PACKAGE $SIM_PACKAGES"

####################################################################################################
# High-level functions
####################################################################################################
# Help function to describe each target
help() {
echo "Curiosity Rover Demo Build Script"
echo "Usage: ./build.sh [subcommand] [demo]"
echo "Available subcommands:"
echo " ./build.sh help - Show this help message"
echo " ./build.sh clean - Clean the local workspace"
echo " ./build.sh - Build the demos"
exit 0
}

# Build all
build() {
build-control-demo
}

# Clean the local workspace
clean() {
rm -rf "$LOCAL_WORKSPACE"/install "$LOCAL_WORKSPACE"/log "$LOCAL_WORKSPACE"/build
}

check_docker() {
if ! command -v docker &>/dev/null; then
echo "Docker is not installed. Please install Docker to continue."
exit 1
fi
}

check_xterm() {
if ! command -v xterm &>/dev/null; then
echo "xterm is not installed. Please install xterm to continue."
echo "On Ubuntu, you can install xterm with 'sudo apt install xterm'."
exit 1
fi
}

check_ros2() {
if ! command -v ros2 &>/dev/null; then
echo "ROS 2 is not installed. Please install ROS 2 to continue."
exit 1
fi
}

####################################################################################################
# Low-level functions
####################################################################################################
# Build the Docker image
build-docker() {
docker build -t "$DOCKER_IMAGE" .
}

# Build the Gazebo workspace locally
build-gazebo() {
# shellcheck source=/opt/ros/${ROS_DISTRO}/setup.bash
# shellcheck disable=SC1091
source /opt/ros/"${ROS_DISTRO}"/setup.bash &&
rosdep install --from-paths . -r -y --skip-keys "$DEMO_PACKAGES" &&
colcon build --symlink-install --base-paths "$LOCAL_WORKSPACE" --install-base "$LOCAL_WORKSPACE"/install \
--cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
--packages-select $SIM_PACKAGES
}

####################################################################################################
# Control demo
####################################################################################################
build-control-demo() {
build-docker
build-gazebo
}

####################################################################################################
# Main script logic to call the appropriate function
####################################################################################################
case "$1" in
help)
help
;;
clean)
clean
;;
*)
check_docker
check_ros2

build
;;
esac
docker-compose build
53 changes: 53 additions & 0 deletions curiosity_rover/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: "3"

services:
curiosity_gui:
image: osrf/space-ros:curiosity_gui
build:
context: ./
dockerfile: ./Dockerfile.GUI
# runtime: nvidia
environment:
- PYTHONUNBUFFERED=1 # important to show error messages if a ros service crashes!
- DISPLAY # for UI
- QT_X11_NO_MITSHM=1 #fix some QT bugs
- NVIDIA_VISIBLE_DEVICES=all # for docker-nvidia2
- NVIDIA_DRIVER_CAPABILITIES=all # for docker-nvidia2
- XDG_RUNTIME_DIR
- __NV_PRIME_RENDER_OFFLOAD=1
- __GLX_VENDOR_LIBRARY_NAME=nvidia
- XAUTHORITY=$XAUTHORITY
- RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw # for UI
- /run/user:/run/user:ro # for UI
command:
[
"bash",
"-c",
"source /opt/ros/$ROS_DISTRO/setup.bash && source ~/curiosity_ws/install/setup.bash && ros2 launch curiosity_gazebo curiosity_gazebo.launch.py",
]
network_mode: host
privileged: true # for UI
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
curiosity_demo:
image: osrf/space-ros:canadarm_demo
build:
context: ./
dockerfile: ./Dockerfile
environment:
- PYTHONUNBUFFERED=1 # important to show error messages if a ros service crashes!
- RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
network_mode: host
command:
[
"bash",
"-c",
"source /home/spaceros-user/curiosity_ws/install/setup.bash && ros2 launch curiosity_rover_demo mars_rover.launch.py",
]
58 changes: 2 additions & 56 deletions curiosity_rover/run.sh
Original file line number Diff line number Diff line change
@@ -1,58 +1,4 @@
#!/bin/bash

# shellcheck disable=SC2089
XTERM_CONFIG="-bg black -fg white -fa 'Monospace' -fs 11"
DOCKER_IMAGE="osrf/space-ros:curiosity_demo"
LOCAL_WORKSPACE=$(pwd)

# Run the Curiosity Rover Gazebo simulation locally
run-gazebo() {
# shellcheck disable=SC2090
# shellcheck disable=SC2086
xterm $XTERM_CONFIG -T 'Curiosity Rover Gazebo' -e "source /opt/ros/\${ROS_DISTRO}/setup.bash \
&& source $LOCAL_WORKSPACE/install/setup.bash \
&& ros2 launch curiosity_gazebo curiosity_gazebo.launch.py" &
}

run-control-demo() {
# shellcheck disable=SC2090
# shellcheck disable=SC2086
xterm $XTERM_CONFIG -T 'Curiosity Rover Demo' -e "docker run -it --rm \
-e RMW_IMPLEMENTATION=rmw_cyclonedds_cpp \
$DOCKER_IMAGE \
bash -c 'source /home/spaceros-user/curiosity_ws/install/setup.bash && ros2 launch curiosity_rover_demo mars_rover.launch.py'" &
}

check_docker() {
if ! command -v docker &>/dev/null; then
echo "Docker is not installed. Please install Docker to continue."
exit 1
fi
}

check_xterm() {
if ! command -v xterm &>/dev/null; then
echo "xterm is not installed. Please install xterm to continue."
echo "On Ubuntu, you can install xterm with 'sudo apt install xterm'."
exit 1
fi
}

check_ros2() {
if ! command -v ros2 &>/dev/null; then
echo "ROS 2 is not installed. Please install ROS 2 to continue."
exit 1
fi
}

run() {

check_docker
check_xterm
check_ros2

run-gazebo
run-control-demo
}

run
docker-compose down
docker-compose up -d

0 comments on commit e68ca4d

Please sign in to comment.