ROS 2 for beginners

How ROS 2 works, by playing with it

ROS 2 is software that helps the parts of a robot work together. This page explains seven ideas, and each one has something to try: swap a camera, follow a message on its journey, drive a robot through a translator, send messages three different ways, change a codebase, and set up a workspace. Everything here is a simulation, so no robot and no ROS 2 installation are needed.

Words used on this page (open this if a word is new)
nodeA small program that does one job, such as reading a camera or following a person.
messageOne piece of data that a node sends, such as a picture or a number.
topicA named channel for messages, like a mailbox with a name on it. Nodes drop messages in, or take messages out.
publisher, subscriberA publisher sends messages to a topic. A subscriber listens to a topic.
driverA small program that talks to one device, such as a camera or a motor board, and translates for it.
packageA folder of programs and files that belong together. Robot software is split into many packages.
workspaceThe folder on the computer where a developer keeps their own packages.
terminalThe text window where commands are typed.
simulationA pretend version that behaves like the real thing, so it can be tried without a robot.
01

Why ROS 2 exists

A robot program that talks straight to a camera is tied to that camera. ROS 2 puts a standard message in between, so the camera can be replaced without touching the program that uses the pictures. In plain words: a topic is a named mailbox. The camera driver puts pictures into the mailbox called /camera/image, and the program takes them out. Neither side needs to know what the other one is.

Key idea. ROS 2 separates robot intelligence from robot hardware, so hardware can change without breaking the algorithms.
02

Inside ROS 2: the six layers

When one program sends a message to another, the message passes through six layers, like a parcel passing through stations. Each layer has one small job. First walk a single message through, step by step. Then send many messages over a network that loses some of them.

Key idea. Most developers only work in the top layer, the robot program. Everything below it, the language helper, the delivery service brand and the computer system, can change while the robot program stays the same.
03

Why ROS is called an operating system

The operating system of a computer (Windows or Linux, for example) hides the computer’s parts from programs, and uses drivers to talk to each device. ROS 2 does the same job for a robot. First match the parts of the two worlds, then drive a robot through a driver.

ROS 2 drivers: translating for the hardware

Every printer has its own private language, so a printer driver translates for it. Motors, sensors and cameras are the same. A driver translates, so robot programs never have to learn the private language of each device.

Key idea. ROS 2 manages robot hardware through drivers the same way a PC operating system manages printers, keyboards and other devices. Hardware can change while the ROS code stays the same.
04

How nodes talk: topics, services and actions

The programs on a robot (the nodes) need ways to talk to each other. There are three. A topic is a stream of messages. A service is a question with one answer. An action is a long job that reports progress and can be cancelled. Each tab is a small simulator.

Key idea. Topics stream data, services answer questions, and actions execute long tasks. Together they let ROS 2 manage communication the way an operating system does.
05

Packages: why many small ones

A computer does not keep every program in one giant file, and neither should a robot. ROS 2 splits robot software into packages that each do one job. First see what happens when something has to change. Then decide what a drone can reuse.

Reuse across robots

Key idea. ROS 2 splits robot software into small packages. That makes the software easy to change, easy to reuse on other robots, and easy to look after, just like the programs on a computer.
06

Workspaces: where the code lives

Robot software lives in two places. ROS 2 itself, as installed on the computer, is the ground floor (the underlay). The folder where a developer writes new code is the floor above it (the overlay). If both floors have a package with the same name, the upper floor wins. Try the steps in different combinations. Then look inside a package and start its nodes.

Inside a package, and the launch file

Key idea. The workspace sits on top of ROS 2 as installed. It can add new packages or replace installed ones, without ever touching ROS 2 itself. That keeps the work tidy and reusable.
07

Quiz