Software installation with ROS2

In this tutorial, we will learn how to install ROS2 Iron Irwini on Ubuntu 22.04 and build our software stack.

0. Use Ubuntu 22.04

As ROS works best on Ubuntu, we are using this distribution. Currently, ROS2 Iron runs on Ubuntu 22.04. If you are not already using Ubuntu 22.04, consider installing it on your system (perhaps as a dual boot), alternately you can run it in a virtual machine (not recommended, as recently we had some issues with it; https://www.virtualbox.org/) or use the ROS2 docker (https://github.com/timonegk/rosdocked)

1. Setup and Install ROS 2

sudo apt install \
clang-format \
cppcheck \
python3-colcon-clean \
python3-colcon-common-extensions \
python3-pip \
python3-rosdep \
python3-vcstool \
ros-iron-plotjuggler-ros \
ros-iron-rmw-cyclonedds-cpp \
ros-iron-rqt-robot-monitor \
ros-iron-rqt-runtime-monitor
  • Run sudo rosdep init to initialize rosdep, a tool that helps you install system dependencies for ROS packages.

2. Install Webots

3. Download our software

  • Create a GitHub account, if not already done (see here for further information on this: http://doku.bit-bots.de/private/manual/dienste_accounts.html) Those services host our Git software repositories.

  • Add your SSH key to GitHub to access and sync our repositories
  • Now, you can clone (download) our main code repository (repo) called bitbots_main:
    • Open a terminal and go to the directory where you want to download our code (typically ~/git/bitbots/)
      • Create the directory with: mkdir -p ~/git/bitbots This is were your source code will live and grow.

      • Move to this directory with: cd ~/git/bitbots

    • Clone the code repository with: git clone git@github.com:bit-bots/bitbots_main.git Confirm the host key by typing yes, if asked.

    • Move into the newly created directory with: cd bitbots_main

    • Clone all code and other files by running: make install This will take a while, as it downloads all the code and other files from our repositories and additionally installs all missing dependencies (using rosdep and pip). Finally, it will register pre-commit hooks (automatic code-formatting and warnings), which will be run every time you commit code to our repositories.

4. Setup colcon workspace

Colcon is the tool provided by ROS 2 to build and install our ROS packages, so that they can be launched later. The colcon workspace is where your source code gets build and where we use colcon.

  • Create colcon workspace directory (typically ~/colcon_ws/)
    • Create directory with: mkdir -p ~/colcon_ws/src

    • Link our software contained in the bitbots_main repo to the newly created src directory with: ln -s ~/git/bitbots/bitbots_main/ ~/colcon_ws/src/bitbots_main

5. Final touches

To let your system know where it should find all the ROS 2 dependencies and packages and to add colored output etc., we add a little bit of config to your ~/.bashrc file, which will be run every time you open a new terminal. In case you are not using the bash shell, replace ~/.bashrc and bash with your shell’s configuration file.

  • Run the following command:

cat >> ~/.bashrc << EOF
export PATH=\$PATH:\$HOME/.local/bin
export COLCON_WS="\$HOME/colcon_ws"
export COLCON_LOG_LEVEL=30
export RCUTILS_COLORIZED_OUTPUT=1
export RCUTILS_CONSOLE_OUTPUT_FORMAT="[{severity}] [{name}]: {message} ({function_name}() at {file_name}:{line_number})"
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
source /opt/ros/iron/setup.bash
eval "\$(register-python-argcomplete3 ros2)"
eval "\$(register-python-argcomplete3 colcon)"
EOF
  • Optionally, run the following command to set some useful shortcuts for various ROS2 commands:

cat >> ~/.bashrc << EOF
alias rr='ros2 run'
alias rl='ros2 launch'

alias rte='ros2 topic echo'
alias rtl='ros2 topic list'
alias rth='ros2 topic hz'
alias rtp='ros2 topic pub'

alias rpl='ros2 param list'
alias rpg='ros2 param get'

alias cdc='cd \$COLCON_WS'

alias cba='cdc && colcon build --symlink-install --continue-on-error'
alias cb='cdc && colcon build --symlink-install --continue-on-error --packages-up-to'
alias cbs='cdc && colcon build --symlink-install --packages-select'
alias cc='cdc && colcon clean packages --packages-select'
alias cca='cdc && colcon clean packages'

alias sr='source /opt/ros/iron/setup.bash'
alias sc='source \$COLCON_WS/install/setup.bash'
alias sa='sr && sc'
EOF

6. Troubleshooting

If you have some problems with your installation, like not finding any nodes or topics, referr here for some troubleshooting steps: https://docs.ros.org/en/rolling/How-To-Guides/Installation-Troubleshooting.html