Lesson 10 of 2250 minutes

Nodes, Messages, and Topics

Start with the lesson question, connect the representations, and test the model with evidence.

ros2nodesmessagestopicspublish subscribeintrospection

Learning objectives

  • Explain nodes, messages, topics, services, and actions.
  • Select the appropriate ROS 2 communication pattern for a task.
  • Inspect and diagnose a small robot computation graph.
Lesson flowHook, model, explanationShow guidance

Inspect the opening phenomenon

Predict what changes, then name the evidence.

Apply in the lab

Name the evidence before reading the answer.

Read only what helps

Then use the lab and recall check.

More when needed

Transcript and resources stay available below.

Course progress

AI & Robotics Foundations · Programming Robot Systems with ROS 2 Concepts · Lesson 10

Nodes, Messages, and Topics

In progress

Decision challenge

Observe the phenomenon. Then connect the representations.

Use the opening example to make a prediction, identify evidence, and explain which model supports it.

Why Is This ROS 2 Subscriber Receiving Nothing?

Predict whether the publisher is necessarily broken.

Before

Predict whether the publisher is necessarily broken.

During

Track node, topic name, message type, and direction.

After

Name three evidence checks for a silent subscriber.

Reference drawerTranscript, source notes, scripts, and package status stay tucked away until you need them.7 files

Lesson reading

live

50 min

Video script

draft

Transcript fallback

available

courses/ai-robotics/modules/04-programming-robot-systems-with-ros2/lessons/01-nodes-messages-and-topics/video-transcript.md

Inspect a ROS 2 Data Path

draft

30 min

Mastery check

live

6 questions / 10 min

Book section:courses/ai-robotics/modules/04-programming-robot-systems-with-ros2/lessons/01-nodes-messages-and-topics/book-section.md
Transcript for accessibility and fallback

# Transcript If a camera publishes obstacles but the safety monitor sees nothing, which part is broken? Start with the ROS 2 graph. A node has a focused responsibility. A message is one strongly typed data sample. A topic is the named asynchronous stream carrying those samples. The camera can publish `ObstacleArray` messages to `/camera/obstacles`, while safety and navigation subscribe independently. The camera does not need to know those subscribers. Communication requires the same topic name, a compatible message type, and compatible delivery settings. Diagnose in order: confirm the node exists, confirm the topic name, inspect the type, check publisher and subscriber counts, then inspect samples. A topic is a live named stream—not automatically a mailbox and not a node. What three checks would you make before blaming the camera? Inspect the complete graph in the EduQuest lab.

Reading lab

Core explanation

Connect the lesson's words, diagrams, graphs, evidence, and equations.

Opening challenge: A camera publishes obstacles, but the safety monitor receives nothing. Is the camera broken—or is the graph disconnected?

The mental model

A node is a running ROS 2 participant with a focused responsibility. A camera node might detect obstacles; a safety node might watch them; a navigation node might plan around them. Nodes are not required to know each other's implementation.

A message is a strongly typed data sample. Its fields and their meanings form a contract. A topic is a named asynchronous stream. Publishers write messages to the stream; any number of compatible subscribers may receive them.

ROS 2 nodes publish and subscribe to a named, strongly typed topic stream

Trace one evidence path

Assume /camera_node publishes ObstacleArray messages on /camera/obstacles. Both /safety_monitor and /navigation_node subscribe:

  1. The camera creates one ObstacleArray sample.
  2. It publishes the sample to /camera/obstacles.
  3. ROS 2 discovers compatible endpoints.
  4. Each compatible subscriber receives the stream independently.
  5. A recorder or debugger can join as another subscriber without changing the camera.

The endpoints need the same topic name and a compatible message type. Quality-of-service settings can also affect compatibility; this lesson keeps QoS at defaults and returns to delivery policy later.

Guided inspection

Use a ROS 2 environment with turtlesim, or study the sample output below:

ros2 node list
ros2 node info /turtlesim
ros2 topic list -t
ros2 topic info /turtle1/cmd_vel
ros2 interface show geometry_msgs/msg/Twist
ros2 topic echo /turtle1/pose

For each command, ask: Which node? Which topic name? Which message type? Which direction? ros2 topic echo behaves as an additional subscriber; it does not interrupt the existing flow.

Diagnose the silent subscriber

EvidenceLikely issueNext check
Topic absentpublisher not running or different nameros2 node list, ros2 topic list
Topic exists; type differscontract mismatchros2 topic list -t
Name and type matchdiscovery or QoS mismatchros2 topic info --verbose
Messages arrive but behavior is wrongmeaning, units, frame, or downstream logicinspect interface and sample values

Misconception checks

  • “A topic stores messages like a mailbox.” Not necessarily. Treat it as a live named stream; durability depends on QoS.
  • “One topic connects exactly two nodes.” A topic may have zero or more publishers and subscribers.
  • “A topic name alone defines the data.” The message type and semantics are part of the contract.
  • “ROS 2 is the robot's desktop operating system.” ROS 2 is middleware, libraries, tools, and conventions for robot software.

Retrieval pause

Without looking back, explain why a recorder can subscribe to a sensor topic without modifying the sensor node. Then name three checks for a subscriber that receives no data.

Summary

Nodes divide responsibilities. Messages define typed samples. Topics provide named asynchronous streams. Diagnose the graph from evidence—node, topic name, type, direction, and delivery compatibility—rather than guessing which program is broken.

Further learning

  • ROS 2 Topics, Open Robotics, retrieved 2026-08-19. Supports publish/subscribe, anonymous endpoints, strong typing, and recorder-as-subscriber claims; link-and-cite use.
  • ROS 2 Interfaces, Open Robotics, retrieved 2026-08-19. Supports topics as asynchronous continuous streams; link-and-cite use.
  • Understanding ROS 2 Nodes, Open Robotics, retrieved 2026-08-19. Supports focused node responsibility and graph inspection commands; link-and-cite use.
Practice labInspect a ROS 2 Data PathOpen this when you are ready to apply the model, collect evidence, and check your explanation.30 min

Lab: Inspect a ROS 2 Data Path

Objective

Build or analyze a publisher-subscriber graph and diagnose one deliberately broken connection.

Setup

Preferred: ROS 2 with turtlesim. Fallback: use the transcript and graph table in this lab without installing software.

Materials

  • Terminal with ROS 2 sourced, or paper/spreadsheet
  • Lesson visual
  • Evidence table

Steps

  1. Start turtlesim_node and turtle_teleop_key, or use the supplied sample graph.
  2. Run ros2 node list and record focused responsibilities.
  3. Run ros2 topic list -t; record topic names and message types.
  4. Inspect /turtle1/cmd_vel with ros2 topic info and geometry_msgs/msg/Twist with ros2 interface show.
  5. Echo /turtle1/pose and explain why the command acts as another subscriber.
  6. Create a failure on paper: rename one subscriber's expected topic to /turtle1/cmd_ve1, or assign the wrong type.
  7. Use only graph evidence to identify the mismatch and propose the smallest repair.

Expected Result

Your table identifies at least two nodes, two topic streams, each stream's type and direction, and a defensible diagnosis for the broken connection.

Troubleshooting

  • Empty node list: source the ROS 2 environment and confirm processes are running.
  • Topic exists but no samples: confirm a publisher is active and inspect publisher count.
  • Type command fails: copy the exact type from ros2 topic list -t.
  • Discovery delay: wait briefly and rerun; do not repeatedly restart everything without evidence.

Reflection Questions

  1. Why can one topic serve two subscribers?
  2. Why is a topic name insufficient as a complete contract?
  3. Which command best distinguishes “publisher missing” from “type mismatch”?

Extension Challenge

Add a hypothetical recorder node and explain what changes in publisher/subscriber counts.

Accessibility and Safety Fallback

The entire activity can be completed from the printed graph and sample outputs. No robot hardware or motor power is required. Use a screen reader-friendly table instead of the visual when needed.