6  Topic

Important

You are reading the work-in-progress edition of ROS 2 : Mea Via et Mea Disciplina. This chapter is currently a dumping ground for ideas, and we don’t recommend reading it. The complete version will be available here soon. Stay tuned!

In ROS2, a topic is a named bus over which nodes can send and receive messages. Topics are used for asynchronous communication between nodes, allowing them to exchange data without needing to know anything about each other’s internal workings.

Each topic has a unique name, which is used by nodes to identify the topic they want to communicate on. Nodes can publish messages to a topic or subscribe to a topic to receive messages. When a node publishes a message to a topic, all other nodes that are subscribed to that topic will receive the message. Source ros.org1 Messages sent over a topic can be of any type, as long as they are defined in the same message package and have the same message name. For example, a sensor node might publish messages containing sensor readings, while a control node might subscribe to those messages and use the data to control a robot’s movements.

ROS2 uses a publisher-subscriber model for topic communication. Publishers are nodes that send messages to a topic, while subscribers are nodes that receive messages from a topic. Nodes can publish and subscribe to multiple topics at the same time, allowing for complex communication patterns between nodes.

ROS2 topics are an important part of building a distributed robotic system, as they allow nodes to communicate in a decoupled manner. By using topics, nodes can exchange data without needing to know anything about each other’s internal workings, making it easier to build complex robotic systems out of smaller, specialized components.