Skip to content

ROS2 Installation

1.1. Introduction

ROS is an open-source meta-operating system for robots. It provides services expected of an operating system, such as hardware abstraction, low-level device control, implementation of common functions, inter-process message communication, and package management. In a sense, ROS is a kind of robot framework.

1.1. Introduction Figure 1

1.1. Introduction Figure 1

1.1.2 Differences Between ROS2 and ROS1

As the successor to ROS1, ROS2 retains the core functions of ROS while introducing many improvements and optimizations. Compared with ROS1, ROS2 removes the central “Master” node used in ROS1 and implements distributed node discovery, publish/subscribe (Pub/Sub), and request/response communication. While ROS1 used its own middleware (roscore), ROS2 uses DDS middleware. In addition, ROS1 used catkin as its build system, whereas ROS2 uses colcon.

1.1.2 Differences Between ROS2 and ROS1 Figure 2

1.1.2 Differences Between ROS2 and ROS1 Figure 2

1.2. ROS2 Installation

1.2.1 locale Configuration

Install locale

Terminal window
locale \# check for UTF-8

1.2.1 locale Configuration Figure 3

1.2.1 locale Configuration Figure 3

Terminal window
sudo apt update && sudo apt install locales

# Configure (generate) locale

Terminal window
sudo locale-gen en_US en_US.UTF-8

1.2.1 locale Configuration Figure 4

1.2.1 locale Configuration Figure 4

Terminal window
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

1.2.1 locale Configuration Figure 5

1.2.1 locale Configuration Figure 5

Terminal window
locale \# Check settings

1.2.1 locale Configuration Figure 6

1.2.1 locale Configuration Figure 6

1.2.2 APT Repository (Source) Configuration

Terminal window
sudo apt install software-properties-common

1.2.2 APT Repository (Source) Configuration Figure 7

1.2.2 APT Repository (Source) Configuration Figure 7

Terminal window
sudo add-apt-repository universe

1.2.2 APT Repository (Source) Configuration Figure 8

1.2.2 APT Repository (Source) Configuration Figure 8

# Install the curl library

Terminal window
sudo apt install curl -y

# Add environment variable

Terminal window
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}')

# Download the package

Terminal window
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"

1.2.2 APT Repository (Source) Configuration Figure 9

1.2.2 APT Repository (Source) Configuration Figure 9

# Install (unpack) the package

Terminal window
sudo dpkg -i /tmp/ros2-apt-source.deb

1.2.2 APT Repository (Source) Configuration Figure 10

1.2.2 APT Repository (Source) Configuration Figure 10

1.2.3 Installation

# Update and upgrade packages from the new repository

Terminal window
sudo apt update && sudo apt upgrade

There are two installation versions:

(1) Desktop version (recommended): Includes ROS, RViz, demos, and tutorials.

(2) Base version: Includes communication libraries, message packages, and command-line tools. GUI tools are not included.

# To install the Desktop version

Terminal window
sudo apt install ros-humble-desktop

# Install development tools (optional)

Terminal window
sudo apt install ros-dev-tools

# Set environment variables

Terminal window
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc

1.3 ROS2 Testing

1.3.1 Remote Control of the Desktop System

After installation is complete, run the xfce desktop environment in MobaXterm:

Terminal window
startxfce4

1.3.2 ROS2 Test

(1) Publish/Subscribe (Pub/Sub) test:**

Open a terminal and run the following:

Terminal window
ros2 run demo_nodes_cpp talker

Open another new terminal and run the following:

Terminal window
ros2 run demo_nodes_py listener

1.3.2 ROS2 Test Figure 11

1.3.2 ROS2 Test Figure 11

(2) Turtlesim test:**

Connect an 8-inch display, mouse, and keyboard, start a terminal, and run the following:

Terminal window
ros2 run turtlesim turtlesim_node

If you want to control the turtle using the keyboard, open a new terminal and run the following:

Terminal window
ros2 run turtlesim turtle_teleop_key

1.3.2 ROS2 Test Figure 12

1.3.2 ROS2 Test Figure 12