Skip to content

2.1 Topic Communication

Topic communication is the most frequently used communication pattern in ROS. It is based on the publish-subscribe model, meaning: one node publishes messages, and another node subscribes to those messages. The application scenarios for topic communication are extremely widespread, such as the following common scenario:

A robot is performing navigation tasks using a LiDAR sensor. The robot collects information perceived by the LiDAR, performs calculations, and then generates motion control information to drive the robot's chassis movement.

In the scenario described above, topic communication is used multiple times.

  • Taking the collection and processing of LiDAR information as an example, in ROS, one node needs to continuously publish the data currently acquired by the LiDAR, while a node within the navigation module subscribes to and parses this LiDAR data.
  • Similarly, for the publication of motion messages, the navigation module calculates motion control information in real-time based on the sensor data and publishes it to the chassis. The chassis can have a node that subscribes to this motion information and ultimately converts it into pulse signals to control the motors.

By extension, the data acquisition from sensors like LiDAR, cameras, GPS, etc., also typically uses topic communication. In other words, topic communication is suitable for application scenarios involving continuously updated data transmission.


Concept

A communication pattern that enables data interaction between different nodes through a publish-subscribe approach.

Purpose

Used for data transmission scenarios involving continuously updated information with minimal logical processing.

Examples

  1. Implement the most basic publish-subscribe model: The publisher sends a text message at a fixed frequency, and the subscriber receives the text and prints it. (Sections 2.1.2 -- 2.1.3)

gif

  1. Implement publishing and subscribing using custom message types. (Sections 2.1.4 -- 2.1.6)

gif


See also: