diff --git a/turtlebot3_ws/.devcontainer/devcontainer.json b/turtlebot3_ws/.devcontainer/devcontainer.json new file mode 100644 index 00000000..de53a74c --- /dev/null +++ b/turtlebot3_ws/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +/* Reference: https://aka.ms/devcontainer.json */ +{ + "name": "TODO", + "dockerComposeFile": "../docker/compose.yaml", + "service": "turtlebot3-ws", + // Workspace settings + "workspaceFolder": "/home/ros2-essentials/turtlebot3_ws", + // Vscode extensions + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cpptools-themes", + "twxs.cmake", + "donjayamanne.python-extension-pack", + "eamodio.gitlens", + "mhutchie.git-graph", + "streetsidesoftware.code-spell-checker", + "ms-iot.vscode-ros" + ] + } + } +} diff --git a/turtlebot3_ws/.gitignore b/turtlebot3_ws/.gitignore new file mode 100644 index 00000000..2bc3ebb3 --- /dev/null +++ b/turtlebot3_ws/.gitignore @@ -0,0 +1,7 @@ +# Visual Studio Code +.vscode + +# ROS2 basic directories +/build +/install +/log diff --git a/turtlebot3_ws/README.md b/turtlebot3_ws/README.md new file mode 100644 index 00000000..25e7b59c --- /dev/null +++ b/turtlebot3_ws/README.md @@ -0,0 +1 @@ +# turtlebot3_ws diff --git a/turtlebot3_ws/docker/.bashrc b/turtlebot3_ws/docker/.bashrc new file mode 100644 index 00000000..2f0726eb --- /dev/null +++ b/turtlebot3_ws/docker/.bashrc @@ -0,0 +1,52 @@ +# Setup paths in `~/.profile` to allow unified environment variable across login/non-login shells +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/bin" ] ; then + PATH="$HOME/bin:$PATH" +fi +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/.local/bin" ] ; then + PATH="$HOME/.local/bin:$PATH" +fi +# Source global ROS2 environment +source /opt/ros/$ROS_DISTRO/setup.bash +# Optionally perform apt update if it has not been executed yet +if [ -z "$( ls -A '/var/lib/apt/lists' )" ]; then + echo "apt-get update has not been executed yet. Running sudo apt-get update..." + sudo apt-get update +fi +# Optionally perform rosdep update if it has not been executed yet +if [ ! -d $HOME/.ros/rosdep/sources.cache ]; then + echo "rosdep update has not been executed yet. Running rosdep update..." + rosdep update + cd $ROS2_WS + # Ref: https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html + rosdep install --from-paths src --ignore-src -y -r +fi +# Optionally build the workspace if it has not been built yet +if [ ! -f $ROS2_WS/install/setup.bash ]; then + echo "Workspace has not been built yet. Building workspace..." + cd $ROS2_WS + # TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore ` to ignore x86 packages + # Ref: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html + if [ $(arch) == "aarch64" ]; then + colcon build --symlink-install + else + colcon build --symlink-install + fi + echo "Workspace built." +fi +# Source gazebo environment +# Ref: https://classic.gazebosim.org/tutorials?tut=ros2_installing&cat=connect_ros#InstallGazebo +if [ $(arch) == "x86_64" ]; then + source /usr/share/gazebo/setup.bash +fi +# TODO: Source other workspace environments as underlay +# Set Isaac Sim environment variables +# Ref: https://docs.omniverse.nvidia.com/isaacsim/latest/installation/install_python.html#running-isaac-sim +# Ref: https://github.com/NVIDIA-Omniverse/IsaacSim-dockerfiles/blob/e3c09375c2d110b39c3fab3611352870aa3ce6ee/Dockerfile.2023.1.0-ubuntu22.04#L49-L53 +export OMNI_USER=admin +export OMNI_PASS=admin +export OMNI_KIT_ACCEPT_EULA=YES +# Source workspace environment +source $ROS2_WS/install/setup.bash +echo "Successfully built workspace and configured environment variables." diff --git a/turtlebot3_ws/docker/.dockerignore b/turtlebot3_ws/docker/.dockerignore new file mode 100644 index 00000000..4901728d --- /dev/null +++ b/turtlebot3_ws/docker/.dockerignore @@ -0,0 +1,2 @@ +* +!.bashrc diff --git a/turtlebot3_ws/docker/Dockerfile b/turtlebot3_ws/docker/Dockerfile new file mode 100644 index 00000000..168fc24d --- /dev/null +++ b/turtlebot3_ws/docker/Dockerfile @@ -0,0 +1,134 @@ +# Base Image: https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +FROM osrf/ros:humble-desktop-full AS amd64 +# Base Image: https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +FROM arm64v8/ros:humble AS arm64 + +# Use docker automatic platform args to select the base image. +# It may be `arm64` or `amd64` depending on the platform. +# Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope +FROM $TARGETARCH +ARG TARGETARCH + +# Arguments for the default user +ARG USERNAME=user +ARG USER_UID=1000 + +# Keep downloaded packages for caching purposes +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache + +# Upgrade packages +# Ref: https://pythonspeed.com/articles/security-updates-in-docker/ +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1264502398 +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1987107404 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +# Install sudo and create a user with sudo privileges +# Ref: https://stackoverflow.com/a/65434659 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y sudo \ + && useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ + && rm -rf /var/lib/apt/lists/* + +# Install common tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + curl \ + git \ + htop \ + iputils-ping \ + nano \ + net-tools \ + tmux \ + tree \ + unzip \ + vim \ + wget \ + zip \ + && rm -rf /var/lib/apt/lists/* + +# Install Python pip +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Install GUI debugging tools +# - `x11-apps` and `x11-utils` for `xeyes` and `xdpyinfo` +# Ref: https://packages.debian.org/sid/x11-apps +# Ref: https://packages.debian.org/sid/x11-utils +# - `mesa-utils` for `glxgears` and `glxinfo` +# Ref: https://wiki.debian.org/Mesa +# - `vulkan-tools` for `vkcube` and `vulkaninfo` +# Ref: https://docs.vulkan.org/tutorial/latest/02_Development_environment.html#_vulkan_packages +# Ref: https://gitlab.com/nvidia/container-images/vulkan/-/blob/master/docker/Dockerfile.ubuntu +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + x11-apps x11-utils \ + mesa-utils \ + libgl1 vulkan-tools \ + && rm -rf /var/lib/apt/lists/* + +# Setup the required capabilities for the container runtime +# Ref: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/docker-specialized.html#driver-capabilities +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVIDIA_DRIVER_CAPABILITIES=all + +# Install Vulkan config files +# Ref: https://gitlab.com/nvidia/container-images/vulkan +RUN cat > /etc/vulkan/icd.d/nvidia_icd.json <