gwordal

Lesson 1 of 5 · 20 min

Why ROS 2 exists

ROS stands for Robot Operating System, but it is not an operating system. It does not schedule your CPU or manage your memory; Linux does that. ROS is a set of libraries, tools and conventions that let many small programs on one or several computers talk to each other in a structured way. Understanding that sentence is the key to the whole course.

What ROS is, and what it is not

A real robot is never one program. One piece reads a lidar, another estimates position, another plans a path, another turns velocity commands into motor signals. Written as one monolith, the code becomes impossible to test, reuse or debug. Written as separate programs, each piece needs a reliable way to exchange data. ROS provides that.

ROS isROS is not
A messaging layer plus toolsAn operating system
A collection of reusable packages (navigation, SLAM, drivers)A robot brain that works out of the box
Language neutral (Python, C++ and more)A real-time guarantee by itself
A shared vocabulary of message typesA replacement for good engineering

The last row of the left column matters most. A geometry_msgs/msg/Twist means "linear and angular velocity" in every package written by anyone, so a navigation stack from one team can drive a base built by another.

The graph

ROS programs are called nodes. Nodes connect into a graph: nodes are the vertices and the data flows between them are the edges. The simplest edge is publish and subscribe. A publisher sends messages to a named topic, and any number of subscribers receive them. Neither side knows the other exists.

camera_nodelidar_node/image_raw/scannav_node
A publisher never talks to a subscriber directly: both only know the topic name.

That decoupling is the point. You can replace a real camera node with a recorded bag file, add a logger that listens to the same topic, or restart a crashed planner, all without touching the other nodes. The topic name is the contract.

Middleware: DDS under the hood

ROS 1 used a central program, the master, that every node had to register with. If it died, the graph died with it. ROS 2 removed the master and built on DDS (Data Distribution Service), an industrial standard used in aircraft and medical systems. Nodes find each other by multicast discovery on the local network and then talk directly, peer to peer.

You rarely touch DDS directly. ROS 2 hides vendors behind an abstraction called RMW (ROS middleware interface). On Jazzy the default is Fast DDS (rmw_fastrtps_cpp), and Cyclone DDS is a common alternative. What you do control are two practical settings:

  • ROS_DOMAIN_ID (0 to 101): nodes only see each other when the ID matches. On a shared classroom network, give each student a different number or your robots will receive each other's commands.
  • ROS_LOCALHOST_ONLY=1: keeps all traffic on the loopback interface.

Why it exists

Robotics labs used to rewrite the same drivers, mapping code and message formats for every project. ROS began at Willow Garage around 2007 as a way to share work. ROS 2 was a redesign for things ROS 1 handled badly: multiple robots, unreliable wireless links, real-time control, and commercial products. Jazzy Jalisco (May 2024) is a long-term-support release maintained until May 2029, which makes it a safe base for learning.

Install ROS 2 Jazzy

Jazzy targets Ubuntu 24.04. These are the official apt steps; run them in a terminal.

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 $VERSION_CODENAME)_all.deb"
sudo dpkg -i /tmp/ros2-apt-source.deb

sudo apt update && sudo apt upgrade -y
sudo apt install ros-jazzy-desktop ros-dev-tools -y

ros-jazzy-desktop includes the core libraries, RViz and demo nodes. ros-dev-tools brings colcon and other build tools you need in the next lesson. Installed software sits in /opt/ros/jazzy, but your shell does not know that until you source the setup script:

source /opt/ros/jazzy/setup.bash
echo "source /opt/ros/jazzy/setup.bash" >> ~/.bashrc

Sourcing sets environment variables (PATH, PYTHONPATH, AMENT_PREFIX_PATH) so that ros2 and import rclpy work. Forgetting this step is the most common beginner error: if you see ros2: command not found, you did not source.

First run: talker and listener

Open two terminals, source in each, and run:

# terminal 1
ros2 run demo_nodes_cpp talker

# terminal 2
ros2 run demo_nodes_py listener

A C++ publisher is feeding a Python subscriber over DDS, with no code from you. Language neutrality, shown in one line.

A tour of the ros2 CLI

The ros2 command is your microscope on the graph. Keep a third terminal open while the demo runs:

ros2 node list              # who is running
ros2 topic list -t          # topics with their message types
ros2 topic echo /chatter    # print messages as they arrive
ros2 node info /talker      # what this node publishes and subscribes to
ros2 interface show std_msgs/msg/String   # the message definition

The pattern is always ros2 <noun> <verb>. Nouns you will meet: node, topic, service, action, param, bag, pkg, interface. When something misbehaves, the first debugging move is to ask the graph what it actually looks like, not what you think you wrote.

Check yourself

What problem did removing the master in ROS 2 solve?

Check yourself

You get ros2: command not found right after a successful apt install. What is the most likely cause?