ROS 2 Learning Path  Β·  Illustrated Educational Book

Chapter 1: ROS 2 Architecture

The backbone of every robot β€” from Node to Launch File
Audience: beginner to robotics engineer
Prerequisite: no prior ROS experience needed
Ongoing project: the ARCHO robot
Study time: 90 to 120 minutes
What we'll cover in this chapter 1.1The Big Picture β€” Why Architecture Before Code? 1.2Node β€” The Living Unit of the System 1.3Topic and Message β€” A Continuous Stream of Data 1.4Service β€” Request and Response 1.5Action β€” Long-Running and Cancellable Operations 1.6Comparing the Three Communication Methods 1.7Parameter β€” Tuning Behavior Without Changing Code 1.8Launch File β€” Starting the Whole System 1.9The Complete Architecture Map 1.10Summary, Glossary, and Exercises

1.1The Big Picture: Why Architecture Before Code?

Imagine you're about to build a robot called ARCHO: a small robot that needs to move between the tall shelves of a warehouse, find its way using a laser sensor, and stop if a human steps in front of it. The first temptation is to open a code file and start writing: read from the camera, process it, send it to the motors. After a few hours you find everything stuck in a thousand-line file, unable to test any part on its own, and if one line of code breaks, the entire robot freezes. This is exactly the path most ROS 2 tutorials take: they jump straight to terminal commands β€” install this, run that β€” and you learn to type commands without knowing why.

This book, and this chapter in particular, takes a different path. Before we write even a single line of code for ARCHO, we sit down and sketch its map: what pieces we need, what each one does, and how they talk to each other. This is exactly what a real robotics engineer does before writing the first line of code. The good news is that the people who built ROS 2 solved this exact problem years ago, and almost the entire system β€” from a simple vacuum robot to an industrial robotic arm β€” is built on just a handful of concepts:

πŸ’‘ Simple Idea

If you learn the five concepts Node, Topic, Message, Service, and Action well, you've understood about 70% of ROS 2. The rest of the book's chapters are just details and tools built around this same core.

By the end of this chapter, you'll know these seven foundational concepts and be able to answer these four questions for any Node in any project:

The learning map for this chapter looks like this β€” each box builds on the one before it:

flowchart RL A["Node
Independent execution unit"] --> B["Topic + Message
Continuous data stream"] A --> C["Service
Request / Response"] A --> D["Action
Long-running operation"] A --> E["Parameter
Behavior configuration"] B --> F["Launch File
Starts the whole system"] C --> F D --> F E --> F F --> G["Chapter 2: Development Environment
Workspace and Package"] style A fill:#2f7de8,stroke:#ffffff,color:#0b1220,font-weight:bold style F fill:#d98c19,stroke:#ffffff,color:#0b1220,font-weight:bold style G fill:#0f9d78,stroke:#ffffff,color:#0b1220,font-weight:bold
🌍 Real-World Example: The Story of the ARCHO Robot

Throughout this book, we'll apply every concept to one consistent project: ARCHO, a simple mobile robot that will move around a large warehouse, sense its surroundings with LiDAR, and find its own path. Each chapter completes another piece of this robot. In this chapter, we'll only design ARCHO's communication skeleton; we won't write any code yet.

1.2Node β€” The Living Unit of the System

How was this problem solved before ROS?

Let's go back to ARCHO and that thousand-line file. Suppose you've been working on it for three weeks: reading the camera, processing images, computing the path, controlling the motors β€” all in one program, in one process. As long as the project is small, everything goes fine. But one morning, the image-processing part crashes and the entire robot freezes β€” even the motors stop responding, because everything is stuck in one program. Worse, when you just want to test the path-planning algorithm, you have to compile and run the entire giant program just to see whether one line of computation works correctly. This is the wall that almost everyone who starts without ROS eventually hits.

ROS's solution: split into independent units

ROS solves this problem with a concept called a Node. Each Node is a small, independent program with exactly one clear responsibility. One only reads from the camera, one only computes the path, one only sends commands to the motors.

πŸ“– Definition: Node

A Node is an independent process in ROS 2 that performs one specific task and communicates with other Nodes through Topics, Services, Actions, or Parameters in order to do so.

🧠 Simple Analogy

Picture a restaurant. The chef, the waiter, the cashier, and the dishwasher are each independent people; none of them does another's job, but they coordinate to keep the restaurant running. If the dishwasher doesn't show up today, the restaurant can still serve food β€” the dishes just pile up. In exactly the same way, if a robot's camera Node goes down, the other Nodes (say, the motor or the LiDAR) are still alive.

In a real mobile robot, dozens of Nodes are typically running simultaneously:

NodeResponsibility
camera_nodeReads images from the camera and publishes them
lidar_nodeReads laser range-finder data
slam_nodeBuilds a map of the environment from sensor data
navigation_nodeComputes the path to the target
motor_controller_nodeConverts velocity commands into motor signals
⚠️ Common Beginner Mistake

Many newcomers think they should write all of the robot's logic in one big Node to make it "simpler." The result is the opposite: debugging becomes hard, testing each part separately becomes impossible, and if one part crashes, the whole robot goes down. Golden rule: one Node, one responsibility.

πŸ”§ Engineering Perspective

From a software-architecture point of view, a Node in ROS 2 plays exactly the same role as a microservice in web-service architecture: a small, independent, replaceable unit with a clear communication contract with the rest of the system. This resemblance is no accident β€” both were designed to solve the same problem: reducing coupling between the parts of a large system.

Easy Exercise

If you wanted to design a simple vacuum-cleaning robot, what Nodes would you probably need? Name at least four and write each one's responsibility in a single sentence.

1.3Topic and Message β€” A Continuous Stream of Data

Problem: how should Nodes talk to each other?

Okay, now we've split ARCHO into several independent Nodes β€” one for the camera, one for image processing, one for the motors. But a new problem has appeared: these Nodes are isolated in their own worlds. The camera Node captures a fresh image every moment, but if there's no way to get it to the image-processing Node, that image just sits in the camera's memory and is useless. We need a way for these independent islands to talk to each other. The first and most common communication method in ROS 2 is the Topic.

πŸ“– Definition: Topic and Message

A Topic is a named channel for transmitting data. One Node can publish information on a Topic, and any other Node can subscribe to that same Topic and receive the information. Every packet of data sent on a Topic is called a Message.

🧠 Simple Analogy: the Kitchen Monitor

In a restaurant, the chef displays every dish that's ready on a monitor. The chef doesn't know who's watching β€” maybe the waiter, maybe the manager, maybe no one. They just keep publishing the status continuously. This is exactly how a Publisher behaves on a Topic.

Camera Node Publisher Topic: /image sensor_msgs/Image Vision Node Subscriber 30 times per second, non-stop, no prior request Each message on this channel is a Message of type sensor_msgs/Image
Figure 1.1 β€” A Publisher (camera) continuously publishes Messages, and one or more Subscribers (image processing) receive them.

A few important points about Topics to keep in mind from the start:

🌍 Real-World Example from ARCHO

In the ARCHO robot, the LiDAR Node publishes distance data on a Topic called /scan using the message type sensor_msgs/LaserScan. At the same time, both the mapping (SLAM) Node and the obstacle-detection Node subscribe to this same shared Topic β€” without the LiDAR ever knowing how many listeners there are.

⚠️ Common Mistake

Many newcomers think all communication between Nodes should go through Topics. A Topic is only suited to a continuous stream of data. If you want to ask a Node something and wait for a specific answer, a Topic is not the right tool β€” as we'll see in the next section.

Intermediate Exercise

Suppose you've mounted an IMU (an acceleration and orientation sensor) on the robot that produces new data every 100 milliseconds. Is this a good fit for a Topic or not? Write your reasoning in two lines.

1.4Service β€” Request and Response

Problem: sometimes we just want one specific answer

Now that ARCHO is broadcasting camera data over a Topic, something interesting happens: the development team, excited about this new tool, starts trying to solve everything with Topics β€” even saving the map, even reading the battery level. The result? Countless channels constantly sending useless messages. To understand why this is a mistake, let's step back into a restaurant. If you want to see the kitchen's status live, that's exactly like a Topic β€” information is continuously broadcast. But if you want to say "one pizza, please," something different happens: you send a specific request and wait for a specific answer. That's no longer a Topic; it's a Request/Response pattern. ROS built Service for exactly this purpose.

πŸ“– Definition: Service

A Service is a two-way communication in which one Node (the Client) sends a Request, and another Node (the Server) processes it and returns a specific Response.

Client Navigation Node Server Map Server Request: filename = warehouse_map Response: success = true The Client waits for the Response to arrive; then the exchange ends
Figure 1.2 β€” The Service pattern: one request, one response, done.

When to use a Topic, when to use a Service?

CriterionA Topic is a good fit if...A Service is a good fit if...
Data typeIt's constantly changing (camera, LiDAR, IMU)It's only read or executed when needed
Timing patternA continuous, repeating streamA one-time, request-driven event
ExampleInstantaneous speed, camera image, OdometrySaving a map, resetting an Encoder, reading battery percentage
Expecting a replyThe Publisher doesn't wait for a replyThe Client waits for a specific Response
🌍 Real-World Example: Robot Battery

Does the robot need to publish its battery percentage to everyone every second? No β€” that's wasteful and hogs network bandwidth. Instead, whenever needed (say, when a UI is opened), a Get Battery Status request is sent, and the Server returns a single response of 78%.

In the ARCHO project, examples of real Services would include:

Inspecting a Service from the command line

When we reach the hands-on chapters, these commands will be your everyday tools:

ros2 service list
ros2 service type /clear
ros2 interface show std_srvs/srv/Empty
ros2 service call /clear std_srvs/srv/Empty "{}"

The output of std_srvs/srv/Empty is just a line of ---, because this Service type carries no data in its Request or Response; calling it simply triggers an action, exactly like pressing a button. By contrast, example_interfaces/srv/AddTwoInts takes two integers (a and b) and returns their sum (sum).

Intermediate Exercise

Suppose you tell the robot "go to room number 5." Is this a Topic? Is it a Service? If the answer to both is no, think about why β€” this question leads us directly into the next section.

1.5Action β€” Long-Running and Cancellable Operations

One day, a member of the ARCHO team asks a simple question that leaves everyone quiet for a few minutes: "If we want to tell the robot to go to shelf number 5, which tool should we use?" Everyone thinks the answer is a Service β€” one request, one response. But looking more closely, they realize the command "go to shelf 5" is neither a Topic nor a Service. Why? Because this task might take several minutes: the movement has to start, progress has to be reported, an obstacle might turn up along the way, it might need to be cancelled, and at the end we need to know whether it succeeded or not. A Service only gives one short reply and doesn't wait around for a long task to finish. For this class of tasks, ROS 2 introduces a third concept called Action.

🧠 Simple Analogy: Ordering a Ride-Hailing Taxi

When you request a ride from a taxi app, you don't just get one reply. First they say a driver accepted, then they say the driver is 3 kilometers away, then they say the driver has arrived, then the trip begins, and finally the trip ends. This is exactly what Action provides in ROS 2: one goal, several progress updates, and one final result.

πŸ“– Definition: Action

An Action is a long-running operation whose progress can be observed while it runs, which can be cancelled if needed, and which returns a final result at the end. Every Action consists of three parts: a Goal, Feedback (progress reports), and a Result (final outcome).

sequenceDiagram participant C as Client (Navigation) participant S as Action Server (Motion Controller) C->>S: Goal: Move To Kitchen S-->>C: Feedback: 20% S-->>C: Feedback: 50% S-->>C: Feedback: 80% Note over C,S: At any point the Client can send Cancel Goal S-->>C: Result: Succeeded

Figure 1.3 β€” The full cycle of an Action: from Goal to Result, with a few Feedback updates in between.

Action PartRoleExample
GoalThe objective to be accomplishedtarget_x: 5.2, target_y: 8.1
FeedbackStatus report during executiondistance_remaining: 2.3
ResultFinal outcome once finishedsuccess: true
🌍 Real-World Example: a Robotic Arm

Suppose a robot arm has to tighten a screw; this could take 20 seconds. If we used a Service, we'd get only a request and a reply, with no visibility into what's happening in between. With Action, we track the steps live: Approaching β†’ Aligning β†’ Tightening β†’ Finished. If the object falls mid-way, the Result comes back as Failed β€” not an ambiguous silence.

One of the most well-known real-world Actions in ROS 2 is NavigateToPose in the Nav2 package. Almost every Nav2-based mobile robot uses this exact Action to go to a target point: the Client says "go here," and the Server reports the stages Planning… β†’ Moving… β†’ Avoiding Obstacle… β†’ Arrived.

⚠️ Common Mistake

An important capability that Action has and Topic and Service don't is the ability to Cancel. If the robot is moving and a human suddenly steps in front of it, a Cancel Goal can be sent at that instant and the robot stops. Many early designs forget this capability and later run into trouble when trying to add an "emergency stop button."

Harder Exercise

Picture a smart coffee maker. Explain what its behavior would look like if built with a Topic, what it would look like if built with a Service, and why Action is the best choice. Write at least one limitation of each approach.

1.6Comparing the Three Communication Methods

A mental image to keep with you forever: a Topic is like a radio, a Service is like a phone call with the bank, and an Action is like ordering a ride-hailing taxi.

Topic Like a radio πŸ“» Publish Publish Publish Publish... Continuous stream, no reply Service Like a call to the bank ☎️ Request β†’ ← Response One question, one answer, done Action Like ordering a taxi πŸš• Goal β†’ Feedback 20% Feedback 60% ← Result: Done Goal, progress, result, cancellable
Figure 1.4 β€” The three ROS 2 communication patterns side by side.
CriterionTopicServiceAction
PatternPublish / SubscribeRequest / ResponseGoal / Feedback / Result
DurationContinuousInstant and shortLong-running
Progress reportingNone (it's a stream itself)NoneYes
CancellableNoNoYes
ExampleCamera, LiDAR, IMUReset, Save, CalibrateNavigate, Pick Object
Best suited forSensors and data streamsInstant operations and settingsLong-running robotic tasks
πŸ”§ Engineering Perspective: a Design Decision

When designing a new Node's architecture, ask yourself: "Is this data constantly changing, or does it only happen based on a specific trigger?" If it's continuous β†’ Topic. If it's instant and short β†’ Service. If it's long-running and needs interim reporting β†’ Action. The wrong choice usually either floods the network with useless messages (Topic instead of Service) or leaves the UI "locked with no feedback" (Service instead of Action).

1.7Parameter β€” Tuning Behavior Without Changing Code

🧠 Simple Analogy: DSLR Camera Settings

On a professional camera, there are settings like ISO, shutter speed, and aperture. To change the ISO you don't need to reprogram the camera's firmware; you just change one setting. Parameter in ROS 2 plays exactly this role.

The problem without Parameter

The ARCHO team now knows when to use a Topic and when to use a Service and an Action. But a smaller, more annoying problem still remains. One engineer hardcoded the robot's default speed directly into the code: robot_speed = 0.5;. A month later, while testing the robot in a narrower corridor, they want to change this value to 0.7. Without a Parameter, you'd have to open the file, edit the code, rebuild, and rerun β€” for one small change, the entire development cycle repeats. With a Parameter, the code stays fixed and only the setting value changes.

πŸ“– Definition: Parameter

A Parameter is an adjustable value that controls a Node's behavior without changing the code. Parameters are typically kept in YAML files so a piece of software can be deployed across several different robots without rewriting code.

# camera_params.yaml
camera_node:
  ros__parameters:
    fps: 30
    width: 1280
    height: 720
🌍 Real-World Example: Three Sizes of the Same Robot

Suppose you install the same motion software on three robots: a small robot with max_speed = 0.4, a medium robot with max_speed = 0.8, and a large robot with max_speed = 1.5. The code is identical; only the Parameter differs. In the ARCHO project, the Node called motor_controller_node has parameters like wheel_radius, wheel_base, and max_velocity. If the wheel diameter changes, we only change the value of wheel_radius; the control algorithm stays untouched.

Parameter vs. Topic β€” the key difference

A simple analogy: a car's instantaneous speed (80 km/h) constantly changes β€” that's like a Topic. But setting Cruise Control to 100 km/h might stay fixed for hours β€” that's like a Parameter. A Topic carries live, flowing data; a Parameter holds relatively fixed settings.

ros2 param list
ros2 param get /camera_node fps
ros2 param set /camera_node fps 60
Easy Exercise

For the LiDAR Node on the ARCHO robot, propose three Parameters that would make sense (for example, detection range, scan rate). For each one, explain why this value should be a Parameter rather than a fixed part of the code.

1.8Launch File β€” Starting the Whole System

🧠 Simple Analogy: a Startup Script

Every morning when you start work, you open several programs: a browser, email, a messaging tool, a code editor. If you open them one by one every day, you'll be exhausted after a week. Instead, you build a script (start_work.sh) that launches them all together. A Launch File does exactly this for ROS 2.

The problem without Launch

By now ARCHO has seven or eight independent Nodes, each with its own Topics, Services, Actions, and Parameters. On test day, an engineer has to run each one manually in a separate terminal window: first the camera, then the LiDAR, then the IMU, then SLAM, then navigation, then the motor controller, then RViz. If the launch order is wrong or one is forgotten, the robot won't work correctly. Now imagine this number is a hundred and fifty Nodes instead of seven β€” this is exactly what happens on a real industrial robot. A real robot typically needs these Nodes running simultaneously: camera_node, lidar_node, imu_node, slam_node, navigation_node, motor_controller, and rviz. Manually running each one with ros2 run is practically impossible for an industrial robot with hundreds of Nodes.

πŸ“– Definition: Launch File

A Launch File is a Python file that specifies which Nodes run, with what Parameters, in what order, and under what conditions. Launch isn't just a sequential-execution script; it's an engine with conditional logic.

A Launch file can do the following:

🌍 Real-World Example: Simulation vs. the Real Robot

Suppose the project has both a Simulation mode and a real-robot execution mode. With one simple condition in the Launch File, if simulation = true, Gazebo, RViz, and a simulated controller run; if simulation = false, the real camera, real LiDAR, and real motor driver run instead β€” same project, no code changes.

# robot.launch.py (just for familiarity; full details in the hands-on chapters)
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(package="camera_driver", executable="camera_node"),
        Node(package="lidar_driver",  executable="lidar_node"),
        Node(package="rviz2",         executable="rviz2"),
    ])

And running all of this with a single command:

ros2 launch my_robot robot.launch.py

Folder structure of a real ROS 2 project

When you open almost any professional ROS 2 project, this same pattern repeats:

my_robot/
β”œβ”€β”€ launch/
β”‚   β”œβ”€β”€ robot.launch.py
β”‚   β”œβ”€β”€ simulation.launch.py
β”‚   └── navigation.launch.py
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ controller.yaml
β”‚   β”œβ”€β”€ nav2.yaml
β”‚   └── camera.yaml
β”œβ”€β”€ urdf/
β”œβ”€β”€ rviz/
β”œβ”€β”€ worlds/
β”œβ”€β”€ src/
└── package.xml
πŸ”§ Engineering Perspective

Take this with you from this chapter: ROS isn't just programming. ROS is a combination of software architecture (Node, Topic, Service, Action), communication (message passing between processes), deployment (Launch File), and configuration (Parameter and YAML). Someone who only writes code but doesn't know these four layers will never fully understand a real robotic system.

Harder Exercise

For the ARCHO robot, write a list of Nodes that should run together in a single Launch File (at least five Nodes), and specify which ones should run only in Simulation mode and which ones should run only on real hardware.

1.9The Complete Architecture Map

Now that we've seen each piece individually, let's put them all together. This is the diagram you should keep in mind for the rest of the book β€” the backbone of ROS 2:

flowchart TB N["Node"] N --> T["Topic
Streaming"] N --> S["Service
Request / Reply"] N --> A["Action
Long Tasks"] T --> M["Message"] S --> RQ["Request"] S --> RS["Response"] A --> G["Goal"] A --> F["Feedback"] A --> R["Result"] P["Parameter
Node behavior configuration"] -.-> N L["Launch File
Starts the whole system"] --> N L --> P style N fill:#2f7de8,stroke:#ffffff,color:#0b1220,font-weight:bold style P fill:#d98c19,stroke:#ffffff,color:#0b1220,font-weight:bold style L fill:#7c5cff,stroke:#ffffff,color:#0b1220,font-weight:bold

For every new Node you build in the ARCHO project or any other project, ask yourself these four questions; if you can answer them, you've truly understood that Node's architecture:

  1. What Topics does it publish?
  2. What Topics does it subscribe to?
  3. What Services or Actions does it provide or call?
  4. What Parameters control its behavior?

1.10Chapter 1 Summary

What we learned

Congratulations β€” you now know the seven main pillars of ROS 2 architecture: Node as the independent execution unit, Topic and Message for a continuous data stream, Service for instant request/response, Action for long-running, cancellable operations, Parameter for tuning behavior without changing code, and Launch File for starting the whole system with a single command. So far we've only learned the city map; we haven't entered the city yet.

βœ… Learning Checkpoint
  • I can say in one sentence what a Node is and why we split a system into several Nodes.
  • I can explain the difference between Topic and Service with a real example.
  • I know why Action is needed for long-running operations and why Service isn't enough.
  • I can explain how Parameter differs from Topic.
  • I know what a Launch File does and why it's more than just a simple script.
  • For a hypothetical Node, I can say what Topics, Services, Actions, and Parameters it might have.

Connection to the main project

ARCHO Project In this chapter, we only designed the robot's communication skeleton on paper: which Node talks to which Node via a Topic, which tasks should be Services, and which should be Actions. We haven't written any code yet, and no Node has run on a system.

What the next chapter adds

From Chapter 2 onward, we enter the hands-on world: building a Workspace from scratch, examining its structure, creating our first Package, writing our first real Node in Python, running it, and watching our first Publisher and Subscriber with our own eyes. From that point on, every concept you learn will immediately run on your own system β€” that's where ROS 2 turns from a set of concepts into a real tool for building robots.

Chapter 1 Glossary

Node
An independent process in ROS 2 with one clear responsibility.
Topic
A named channel for continuously publishing data between Nodes.
Message
The data format carried over a Topic.
Publisher
A Node that publishes data on a Topic.
Subscriber
A Node that listens to a Topic and receives data.
Service
A two-way request/response communication between a Client and a Server.
Action
A long-running operation with progress reports (Feedback) and the ability to cancel.
Parameter
An adjustable value that controls a Node's behavior without changing the code.
Launch File
A Python file that manages the simultaneous launch of several Nodes and the loading of settings.

Chapter 1 Common Mistakes β€” Summary