Template for ROS2 workspace using VS Code Dev Containers & Docker Compose.
- Use
Dev Containers: Clone Repository in Container Volume...in VS Code's Command Palette to auto-magically setup everything!- To re-open repository, either use
File > Open Recentor repeat the above with the exact SAME url.
- To re-open repository, either use
- For customization, do a global find & replace for
(OPTION).- Remember to
Dev Containers: Rebuild Containerafterwards!
- Remember to
- GUI apps are viewable via noVNC (VNC client web app) hosted on http://localhost:6080/.
- By default the docker-compose.yaml will use images publish to Github/Docker Hub (same version of master)
This image was confirmed working by a user.
If you prefer to use it that way, just run the commands below.
Note: --root is added to the command, but depending on your usage, it might not be needed.
For NVIDIA Users:
# Change the second --volume for your ros distro folders
distrobox create --root -i mrduartept/ros2-rob-trsa-template:humble --yes --nvidia --volume /usr/share/vulkan/icd.d:/usr/share/vulkan/icd.d:r --volume $HOME/Documents/ros-workspaces:$HOME/Documents/ros-workspaces:rwFor Intel/AMD Users
# Change the second --volume for your ros distro folders
distrobox create --root -i mrduartept/ros2-rob-trsa-template:humble --yes --volume /usr/share/vulkan/icd.d:/usr/share/vulkan/icd.d:r --volume $HOME/Documents/ros-workspaces:$HOME/Documents/ros-workspaces:rwMount points are used to mount a folder from the host into the container.
The ./rob_ws and ./trsa_ws are two seperates workspace, one for Robotics and other for Telerobotics
./rob_ws and ./trsa_ws can be used to share anything from the host with the container, is also the place on were you create your ros packages
Also remember to:
- Add mount points to
.gitignoreand.dockerignore.
Some dependencies may be unavailable from the rosdep package manager (check ROS Index). For Python dependencies, they should be added to a requirements.txt created within the ROS package. The ROS package's requirements.txt should then be composed into the workspace's requirements.txt (example in requirements.txt). For other dependencies, they should be added to both Dockerfiles. See https://github.com/ros/rosdistro/blob/master/CONTRIBUTING.md#rosdep-rules-contributions with regards to adding new packages to rosdep.
There are two alias that can be used to create ros packages:
ros2_cmake_pkg: Create a Ros2 C/C++ package in the current directoryros2_python_pkg: Create a Ros2 Python package in the current directory
There also alias to auto-load the Isaac Sim and Issac Lab python envrioment, called isaacload
This enviroment is only created isaac_ros-dev folder is mounted in the container, look at postCreate.sh and issaclab-pyenv.sh
For developer convenience, some common tasks are present in tasks.json. Use them by opening the Command Palette and typing task. The following tasks are available:
rosdep install dependencies: Install all dependencies of the current workspace.colcon build all: Build all (detected) ROS packages.colcon build specific: Build a specific ROS package.update package index: Update Ubuntu and ROS package indexes.
Both devcontainer.json and extensions.json are configured such that VS Code will automatically install some extensions. These are highly recommended for developer experience.
black is used to format Python code due to its uncompromising design. Imports are also automatically sorted using compatible rules. See settings.json for the configuration.
Instead of using Dev Container with a Dockerfile, this template uses it with Docker Compose instead. This is done for a few reasons:
- Include example of how to configure Docker for ROS to communicate across containers.
- Docker Compose is closer to real world deployment scenarios.
- It is also more flexible and easier to configure than
devcontainer.json.
- It is also more flexible and easier to configure than
The rosdep and Ubuntu package managers rely on a local cache of their package index. If the package index is outdated, it may not contain any active package distribution server, leading to package downloads failing. Hence, it is recommended to periodically re-download the package index:
apt-get update
rosdep updateTo change ROS Distro, do a global search for the current distro (jazzy) and replace as necessary with the new distro. Afterwards, rebuild the Dev Container.
See https://docs.docker.com/engine/reference/commandline/docker/ for more info.
Note: If using
Dev Containers: Clone Repository in Container Volume...on Windows, follow https://code.visualstudio.com/docs/containers/choosing-dev-environment#_windows-subsystem-for-linux to ensure built images are stored on the host computer's image repository.
docker build . -t ros-jazzy-rob-trsa:vx.x.x -t ros-jazzy-rob-trsa:latestImages can have multiple names tagged to them. Tagging images with the version number and as latest helps when distributing images.
Note: Run this command on the host computer rather than in the Dev Container.
docker save ros-jazzy-rob-trsa:vx.x.x ros-jazzy-rob-trsa:latest -o ros-jazzy-rob-trsa-vx.x.x.tarCompressing the image afterwards using xzip is recommended to save space. Docker is able to load compressed images (i.e., ros-jazzy-rob-trsa-vx.x.x.tar.xz) without decompressing manually.
docker load -i ros-jazzy-rob-trsa-vx.x.x.tar.xzImports the image and its names. It will still be tagged as ros-jazzy-rob-trsa:vx.x.x and ros-jazzy-rob-trsa:latest, conveniently replacing the previous latest.
- On first setup, the Dev Container fails to build and complains about
/r.- The Dev Container lifecycle hooks were checked out with CRLF instead of LF line endings.
- Do
git config --global core.autocrlf inputand re-clone the repository. - See https://code.visualstudio.com/docs/remote/troubleshooting#_resolving-git-line-ending-issues-in-wsl-resulting-in-many-modified-files for more info.
- When modifying the Dockerfile, earlier cached steps might be stale, causing later steps to fail.
- Rebuild the Dev Container without cache.
- Try deleting the
buildandinstallfolders before rebuilding all packages.
rosdephas no version lock, which means there is no protection against breaking changes when packages update.- See: ros-infrastructure/rosdep#325
- One solution would be to use your own install script instead of
rosdep.
- ROS
launchfiles aren't symlinked unlike Python code.- Rebuild the package when
launchfiles are modified.
- Rebuild the package when