#ROS2

ROS 2 Tips & Tricks

Small configurations for your ROS 2 workflow

· · 2min · Damien LaRocque
cover

Here are a few tips and tricks and configurations to add to your system while working with ROS 2.

Timeline

Here is a timeline for recent previous distributions of ROS. When searching for a ROS packages on GitHub, the names of the distributions is often used as a repo branch. For example, at the time of writing this article, the turtlebot4_robot package had jazzy as its main branch. If you're working with a ROS 2 distribution that is not supported yet, prioritize using repositories with ROS 2 compatibility, as it is easier to migrate code between ROS 2 distributions (foxy ➡️ jazzy, for example) than to migrate from ROS (1) to ROS 2 (noetic -> humble, for example).

<figcaption class="mb-4">
    Ubuntu, ROS and ROS 2 timeline
</figcaption>

Terminal settings

Add the following lines to your terminal rc file (e.g.: ~/.bashrc):

# Console output colorizing
export RCUTILS_COLORIZED_OUTPUT=1
# Console output formatting
export RCUTILS_CONSOLE_OUTPUT_FORMAT="[{severity} {time}] [{name}]: {message} ({function_name}() at {file_name}:{line_number})"

Colcon

You can easily cd to the source of a specific ROS 2 package with colcon_cd. To enable it, add the following line to your terminal configuration file:

source /usr/share/colcon_cd/function/colcon_cd.sh
export _colcon_cd_root=/opt/ros/${ROS_DISTRO}/

You can also enable argcomplete for colcon. This speeds up calling colcon commands by enabling tab completion with colcon.

source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash

colcon mixins are also useful to build with specific C++ build types without having to remember tedious and long commands. In your ~/colcon_ws, run these commands:

colcon mixin add default https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml
colcon mixin update default

rosdep

rosdep is the dependency resolver to install dependencies for the ROS 2 packages in a colcon workspace. To initialize rosdep on your system, use these commanda

# Initialize and update rosdep
sudo rosdep init
rosdep update

And then, in the root directory of your colcon_ws, use this command to install the dependencies of the packages available in the workspace:

rosdep install --from-paths src -y --ignore-src

⚠️ and for ROS 1 ⚠️

rosdep install --from-paths src --ignore-src -r -y

ROS 2 package creation

You can create a ROS 2 colcon package in the src/ directory of your colcon workspace with this command:

ros2 pkg create --build-type ament_cmake --license <license> <package_name>

Here are the licenses options that are supported by ROS 2, when creating a package:

$ ros2 pkg create --license ? package
Supported licenses:
Apache-2.0
BSL-1.0
BSD-2.0
BSD-2-Clause
BSD-3-Clause
GPL-3.0-only
LGPL-3.0-only
MIT
MIT-0
ROS 2 Tips & Tricks