Skip to content

Commit

Permalink
feat(turtlebot3_ws): Create turtlebot3_ws
Browse files Browse the repository at this point in the history
Using the `create_workspace.sh` script, and remove `minimal_pkg`
  • Loading branch information
j3soon committed Oct 23, 2024
1 parent b5c83cd commit 9967043
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 0 deletions.
23 changes: 23 additions & 0 deletions turtlebot3_ws/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
7 changes: 7 additions & 0 deletions turtlebot3_ws/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Visual Studio Code
.vscode

# ROS2 basic directories
/build
/install
/log
1 change: 1 addition & 0 deletions turtlebot3_ws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# turtlebot3_ws
52 changes: 52 additions & 0 deletions turtlebot3_ws/docker/.bashrc
Original file line number Diff line number Diff line change
@@ -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 <package>` 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."
2 changes: 2 additions & 0 deletions turtlebot3_ws/docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.bashrc
134 changes: 134 additions & 0 deletions turtlebot3_ws/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <<EOF
{
"file_format_version" : "1.0.0",
"ICD": {
"library_path": "libGLX_nvidia.so.0",
"api_version" : "1.3.194"
}
}
EOF

# Install ROS2 Gazebo packages for amd64
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
if [ "$TARGETARCH" = "amd64" ]; then \
apt-get update && apt-get install -y \
ros-$ROS_DISTRO-gazebo-ros-pkgs \
ros-$ROS_DISTRO-gazebo-ros2-control \
&& rm -rf /var/lib/apt/lists/*; \
fi

# Install ROS2 RVIZ and other custom ROS2 packages
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
apt-get update && apt-get install -y \
ros-$ROS_DISTRO-rviz2 \
&& rm -rf /var/lib/apt/lists/*

USER $USERNAME

# Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount
RUN mkdir /home/$USERNAME/.gazebo

# Install Isaac Sim (requires Python 3.10)
# Note that installing Isaac Sim with pip is experimental, keep this in mind when unexpected error occurs
# TODO: Remove the note above when it is no longer experimental
# Ref: https://docs.omniverse.nvidia.com/isaacsim/latest/installation/install_python.html#installation-using-pip
RUN --mount=type=cache,target=/home/user/.cache/pip,sharing=private \
if [ "$TARGETARCH" = "amd64" ]; then \
python3 -V | grep "Python 3.10" \
&& pip install isaacsim==4.1.0.0 --extra-index-url https://pypi.nvidia.com \
&& pip install isaacsim-extscache-physics==4.1.0.0 isaacsim-extscache-kit==4.1.0.0 isaacsim-extscache-kit-sdk==4.1.0.0 --extra-index-url https://pypi.nvidia.com; \
fi

# Install custom tools
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
sudo apt-get update && sudo apt-get install -y \
git-extras \
&& sudo rm -rf /var/lib/apt/lists/*

# TODO: Add more commands here
COPY .bashrc /home/$USERNAME/.bashrc
# TODO: Copy additional files here
ENTRYPOINT []
CMD ["/bin/bash"]
143 changes: 143 additions & 0 deletions turtlebot3_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
services:
volume-instantiation:
# Ref: https://github.com/moby/moby/issues/47842#issuecomment-2249050939
image: ubuntu:22.04
container_name: ros2-volume-instantiation
command: bash -c "
mkdir -p /isaac-sim/cache/{kit,ov,pip,glcache,computecache} &&
mkdir -p /isaac-sim/{logs,data,documents} &&
mkdir -p /isaac-sim/standalone/cache/ov &&
mkdir -p /isaac-sim/standalone/{logs,data} &&
chown -R 1000:1000 /isaac-sim"
volumes:
- isaac-sim-cache:/isaac-sim
turtlebot3-ws:
depends_on:
- volume-instantiation
build:
context: .
dockerfile: Dockerfile
# TODO: Specify the target platform to build the image, otherwise it will build for the host platform.
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
image: j3soon/ros2-turtlebot3-ws
container_name: ros2-turtlebot3-ws
stdin_open: true
tty: true
# TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices.
privileged: true
command: /bin/bash
network_mode: host
working_dir: /home/ros2-essentials/turtlebot3_ws
environment:
# Set X11 server environment variable for existing display.
- DISPLAY=$DISPLAY
# References:
# - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html
# - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html
# - https://docs.ros.org/en/humble/Tutorials/Demos/Logging-and-logger-configuration.html#console-output-colorizing
- ROS_LOCALHOST_ONLY=0
# Localhost only is disabled by default to allow communication with external devices.
- ROS_DOMAIN_ID=0
# Domain ID is set to 0 to allow communication through ros1_bridge.
- RCUTILS_COLORIZED_OUTPUT=1
- ROS2_WS=/home/ros2-essentials/turtlebot3_ws
# TODO: Add more environment variables here.
# TODO: Uncomment the lines below to enable GPU support.
# # Reference: https://docs.docker.com/compose/gpu-support/
# deploy:
# resources:
# reservations:
# devices:
# - driver: nvidia
# count: all
# capabilities: [ gpu ]
volumes:
# Mount local timezone into container.
# Reference: https://stackoverflow.com/questions/57607381/how-do-i-change-timezone-in-a-docker-container
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
# Mount X11 server
- /tmp/.X11-unix:/tmp/.X11-unix
# X11-unix is mounted to allow GUI applications to display on host.
- $HOME/.Xauthority:/home/user/.Xauthority
# Xauthority is mounted to allow X11 forwarding for remote display.
# Mount Direct Rendering Infrastructure (DRI) for hardware acceleration support such as OpenGL.
- /dev/dri:/dev/dri
# Mount sound card to prevent Gazebo warning.
- /dev/snd:/dev/snd
# Mount shared memory for ROS2 communication.
- /dev/shm:/dev/shm
# TODO: Uncomment the line below and comment out the three entries above to enable USB support.
# - /dev:/dev
# Mount Gazebo models directory to reuse models downloaded during first launch.
# Reference: https://answers.ros.org/question/365658
# Note that this volume is shared among all workspaces.
- gazebo-cache:/home/user/.gazebo
# Mount Isaac Sim cache directories.
# Reference: https://docs.omniverse.nvidia.com/isaacsim/latest/installation/install_container.html#container-deployment
# Note that this volume is shared among all workspaces.
- type: volume
source: isaac-sim-cache
target: /isaac-sim/kit/cache
volume:
subpath: cache/kit
- type: volume
source: isaac-sim-cache
target: /home/user/.cache/ov
volume:
subpath: cache/ov
- type: volume
source: isaac-sim-cache
target: /home/user/.local/lib/python3.10/site-packages/omni/cache # For Isaac Sim standalone
volume:
subpath: standalone/cache/ov
- type: volume
source: isaac-sim-cache
target: /home/user/.cache/pip
volume:
subpath: cache/pip
- type: volume
source: isaac-sim-cache
target: /home/user/.cache/nvidia/GLCache
volume:
subpath: cache/glcache
- type: volume
source: isaac-sim-cache
target: /home/user/.nv/ComputeCache
volume:
subpath: cache/computecache
- type: volume
source: isaac-sim-cache
target: /home/user/.nvidia-omniverse/logs
volume:
subpath: logs
- type: volume
source: isaac-sim-cache
target: /home/user/.local/lib/python3.10/site-packages/omni/logs # For Isaac Sim standalone
volume:
subpath: standalone/logs
- type: volume
source: isaac-sim-cache
target: /home/user/.local/share/ov/data
volume:
subpath: data
- type: volume
source: isaac-sim-cache
target: /home/user/.local/lib/python3.10/site-packages/omni/data # For Isaac Sim standalone
volume:
subpath: standalone/data
- type: volume
source: isaac-sim-cache
target: /home/user/Documents
volume:
subpath: documents
# TODO: Add more volume mounts here.
# Mount root workspace to allow easy access to all workspaces.
- ../..:/home/ros2-essentials
volumes:
gazebo-cache:
name: ros2-gazebo-cache
isaac-sim-cache:
name: ros2-isaac-sim-cache

0 comments on commit 9967043

Please sign in to comment.