Robot Operating System (ROS)
The Robot Operating System (ROS) is a flexible framework for writing robot software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms.
Note: "The robot operating system" is actually not an operating system the the traditional sense, but rather a middleware that runs on top of an the Ubuntu operating system. Each version of ROS depends on a specific version of Ubuntu. In this course, we will use the version of ROS2 named Humble Hawksbill (aka "Humble") which runs on Ubuntu 22.04.
Install ROS 2
The recommended way to install ROS2 is to use the roboracer_ws repository, which has tools for building and running a ROS2 workspace inside a Docker container.
Note: If you are using a Windows machine, first install Docker and WSL2. Then, run the following commands inside the WSL2 terminal:
# navigate to the home directory
cd ~
# clone the roboracer_ws repository
git clone https://github.com/ut_av/roboracer_ws.git
# navigate to the roboracer_ws directory
cd roboracer_ws
# checkout the workspace src code
./scripts/checkout.sh
# build the docker image
# NOTE! This will take a long time the first time you run it
# However, you only need to build the container once
./container build
# enter the container
./container shell
# build the ros 2 workspace
make
ROS2 Concepts
- Nodes: The basic building blocks of a ROS2 system. Each node is a separate process that performs a specific function. For example, a node might read data from a sensor, process that data, or control an actuator.
- Topics: A publish/subscribe messaging system that allows nodes to communicate with each other asynchronously. For example, a sensor node might publish data to a topic, and a processing node might subscribe to that topic to receive the data. Topics names are typically in the format of
/namespace/topic_name. - Messages: The data structures used for communication between nodes.
- Services: A request/reply messaging system that allows nodes to communicate synchronously.
- Packages: A collection of nodes, messages, services, and other resources that are organized together.
TF (Transform) Tree
The TF (Transform) library in ROS2 is used to keep track of multiple coordinate frames over time. It allows you to transform data between different coordinate frames, which is essential for tasks such as sensor fusion, localization, and navigation.
What is a coordinate frame?
A coordinate frame is a reference system that defines the position and orientation of objects in space. In robotics, we often have multiple coordinate frames, such as the robot's base frame, the camera frame, and the world frame.
Debugging and Viewing the TF Tree
To visualize the TF tree, you can use the view_frames tool from the tf2_tools package:
ros2 run tf2_tools view_frames
Working with ROS2
ROS projects are organized into packages. All packages for the project are placed in a workspace. This workspace is a folder in the home directory of the user. The workspace we'll use for the car is roboracer_ws. Within this workspace, there is a src directory where all the ROS2 packages are stored.
Each package contains nodes, message definitions, and other resources needed for a specific functionality.
ROS2 Tutorials
If you're not familiar with ROS2, it is highly recommended that you complete the following ROS2 tutorials. These tutorials should be completed on your computer, not on the car.
Alternative ROS 2 Installation Methods
There are many ways to install ROS2 on your computer. The recommended way is to use the roboracer_ws repository via Docker. Using a Docker container ensures that all of the necessary dependencies are installed and that the environment is consistent across different machines.
If you know what you're doing, here are some other options:
We are using the version of ROS 2 named Humble Hawksbill. This version of ROS2 only officially supports installation on Ubuntu 22.04 (Jammy Jellyfish). However, it is possible to install ROS2 on other operating systems (Windows and MacOS) using Docker containers, virtual machines, or the pixi package manager and the robostack project.
Install ROS 2 on Ubuntu 22.04
Follow the official ROS 2 Humble installation instructions for Ubuntu 22.04: Install ROS2 on Ubuntu 22.04. The steps are summarized below:
# setup locale
sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
# add the repository
sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update && sudo apt install curl -y
export ROS_APT_SOURCE_VERSION=$(curl -s https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | grep -F "tag_name" | awk -F\" '{print $4}')
curl -L -o /tmp/ros2-apt-source.deb "https://github.com/ros-infrastructure/ros-apt-source/releases/download/${ROS_APT_SOURCE_VERSION}/ros2-apt-source_${ROS_APT_SOURCE_VERSION}.$(. /etc/os-release && echo ${UBUNTU_CODENAME:-${VERSION_CODENAME}})_all.deb"
sudo dpkg -i /tmp/ros2-apt-source.deb
# install ROS 2 packages
sudo apt update
sudo apt upgrade
sudo apt install ros-humble-desktop ros-dev-tools
Using ROS2 on Ubuntu
To use ROS2, you need to source the ROS2 setup script in each terminal session. You can do this by running the following command:
source /opt/ros/humble/setup.bash
Install ROS 2 on MacOS
Using docker is the recommended way to install ROS2 on MacOS. However, you can also install ROS2 on MacOS using a virtual machine.
ROS2 on MacOS using a Virtual Machine
Install the free VMWare Fusion and create a new virtual machine using the Ubuntu 22.04 Desktop image. Follow the same installation instructions as for Ubuntu 22.04 above to install ROS2 Humble inside the virtual machine.
Install ROS 2 on Windows
Using docker is the recommended way to install ROS2 on Windows. However, you can also install ROS2 on Windows using WSL2 (Windows Subsystem for Linux). Follow the official ROS 2 Humble installation instructions for Windows using WSL2: Install ROS2 on Windows.
Be sure to use the Ubuntu 22.04 distribution for WSL2, as that is the only version that ROS2 Humble supports.