Skip to content

MrDuartePT/ros2-rob-trsa-template

Repository files navigation

Docker image (amd64) Docker image (arm64) Docker Image Size Docker Pulls

ros2-rob-trsa-template

Template for ROS2 workspace using VS Code Dev Containers & Docker Compose.

Table of Contents

Mount Point ./rob_ws, ./trsa_ws and ./drone_ws

Mount points are used to mount a folder from the host into the container. The ./rob_ws, ./trsa_ws and ./drone_ws are three seperates workspace, one for Robotics, other for Telerobotics and other for PX4-Autopilot.

./rob_ws, ./trsa_ws and ./drone_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:

The PX4-Autopilot is included in the toolchain folder of the repo as submodule and it pull when the Dev Container is started

Other Features

requirements.txt Escape Hatch

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.

Alias

There are two alias that can be used to create ros packages:

  • ros2_cmake_pkg: Create a Ros2 C/C++ package in the current directory
  • ros2_python_pkg: Create a Ros2 Python package in the current directory

VS Code Tasks

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.

VS Code Extension Suggestions

Both devcontainer.json and extensions.json are configured such that VS Code will automatically install some extensions. These are highly recommended for developer experience.

Code Formatting

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.

Dev Container using Docker Compose

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.

Tips

Update Package Indexes

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 update

Change ROS Distro

To change ROS Distro, do a global search for the current distro (humble) and replace as necessary with the new distro. Afterwards, rebuild the Dev Container.

Docker Image Distribution

See https://docs.docker.com/engine/reference/commandline/docker/ for more info.

Building

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-humble-rob-trsa:vx.x.x -t ros-humble-rob-trsa:latest

Images can have multiple names tagged to them. Tagging images with the version number and as latest helps when distributing images.

Exporting

Note: Run this command on the host computer rather than in the Dev Container.

docker save ros-humble-rob-trsa:vx.x.x ros-humble-rob-trsa:latest -o ros-humble-rob-trsa-vx.x.x.tar

Compressing the image afterwards using xzip is recommended to save space. Docker is able to load compressed images (i.e., ros-humble-rob-trsa-vx.x.x.tar.xz) without decompressing manually.

Importing

docker load -i ros-humble-rob-trsa-vx.x.x.tar.xz

Imports the image and its names. It will still be tagged as ros-humble-rob-trsa:vx.x.x and ros-humble-rob-trsa:latest, conveniently replacing the previous latest.

Troubleshooting

Setup Issues

Build Issues

  • Try deleting the build and install folders before rebuilding all packages.

Runtime Issues

  • rosdep has no version lock, which means there is no protection against breaking changes when packages update.
  • ROS launch files aren't symlinked unlike Python code.
    • Rebuild the package when launch files are modified.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages