ROS Learning and Practice Chapter 2 ROS Communication Mechanism - Topic Communication (1)

ROS learning and practice

ROS communication mechanism - topic communication (1)

foreword

Topic communication is the most used communication method in ROS, and topic communication is based on the publish and subscribe model.

1. What is Topic Communication?

Topic communication: Topic communication is based on the publish and subscribe model, that is, one of the parties subscribes to the message, and the other party publishes the message. In ROS, the two establish a connection through a common topic to achieve communication

2. Application Scenarios of Topic Communication

In the study of ROS, topic communication is widely used, such as lidar navigation as an example, and the information collected by lidar must be transmitted to the computer for processing, and the processed information must be transmitted to the chassis of the robot to control the movement of the robot. In this process, two topic communications are applied. First, the lidar is used as the publisher, and the computer is used as the subscriber. In the second communication, the computer acts as the publisher, and the chassis of the second car acts as the subscriber. In addition to using topic communication in lidar navigation, topic communication is also used in the use of other sensors. Topic communication is suitable for constantly updated information transmission scenarios.

3. The core elements of topic communication

Publisher
Subscriber
Topic

4. Theoretical model of topic communicationinsert image description here

The role of topic communication:

Publisher talker
subscriber listener
manager master

The process of topic communication:

According to the figure above:
Step 0: The publisher (talker) will register its topic and the remote call address (RPC) in the master; Step 1: The
subscriber (listener) will register its topic in the master Register in the master;
Step 2: The master will compare the topics of the subscriber and the publisher, and if there is a match between the two, it will send the publisher's RPC address to the subscriber; Step 3: The subscriber will send the RPC address to the subscriber according to the
RPC The address remotely accesses the publisher to obtain the publisher's TCP address;
Step 4: The publisher will send its own TCP address to the subscriber after receiving the request;
Step 5: The subscriber accesses the publisher according to the TCP address;
Step 6: The publisher sends its own information to the subscribers to realize the information exchange between the two.

Precautions

The protocol used for topic communication: RPC, TCP
Talker and listener can have multiple
masters. After the talker and listener establish a connection, they will be closed.
The above implementation process has been packaged, and the user only needs to call it. You only need to implement the publisher and subscriber, and don't care about the specific protocol.

Guess you like

Origin blog.csdn.net/qq_52111026/article/details/121708801