Skip to content

Lab 3.1. ROS 2 Topics

Objectives

At the end of this self-learning lab, you should be able to:

  • Write a publisher and subscriber node in C++
  • Understand how nodes communicate via topics

Communication between nodes via ROS Topics: Basic concepts

Recommended reading: ROS 2 Tutorial: Understanding Nodes

Recommended reading: ROS 2 Tutorial: Understanding Topics

  • To say that two programs (i.e. nodes) are communicating with each other, it means that the output of one program is the input of another.
  • In ROS, one of the ways for nodes to communicate with each other is via a topic.
  • A topic is a named data bus that contains data. A node can write data onto this topic, and another node can read data from such topic. The data transfer is facilitated via the topic.
  • Each data packet on the bus is called a message. Nodes can only read/write to a topic one message at a time.
  • Each message has its own format and structure (this will become apparent with an example later). This structure is called a msg. We will use "message type" and "msg" interchangeably.
  • To say that a node is to write (output) to a topic, with ROS terminology is to publish.
  • To say that a node is to read (input) from a topic, with ROS terminology is to subscribe.
  • Multiple nodes can write (publish) to the same topic, and multiple nodes can also read (subscribe) from the same topic.
  • The same node can publish to topics and subscribe to multiple topics simultaneously.

ROS 2 Official tutorials about topics (Required reading)

You can now follow and self-learn the ROS 2 official tutorials on topics, publisher and subscribers here.