2.1.1 Topic Communication Theoretical Model
The implementation model of topic communication is relatively complex. The model is illustrated in the diagram below and involves three roles:
- ROS Master (Manager)
- Talker (Publisher)
- Listener (Subscriber)
The ROS Master is responsible for storing the registration information of Talkers and Listeners. It matches Talkers and Listeners that share the same topic name and helps them establish a connection. Once the connection is established, the Talker can publish messages, which are then subscribed to by the Listener.
The entire process is implemented through the following steps:
0. Talker Registration
After startup, the Talker registers its own information with the ROS Master via RPC, including the topic name of the messages it publishes. The ROS Master adds the node's registration information to its registry.
1. Listener Registration
After startup, the Listener also registers its own information with the ROS Master via RPC, including the topic name of the messages it wishes to subscribe to. The ROS Master adds the node's registration information to its registry.
2. ROS Master Performs Information Matching
The ROS Master matches Talkers and Listeners based on the information in its registry and sends the Talker's RPC address information to the Listener via RPC.
3. Listener Sends Request to Talker
Based on the received RPC address, the Listener sends a connection request to the Talker via RPC, transmitting the subscribed topic name, message type, and communication protocol (TCP/UDP).
4. Talker Confirms the Request
Upon receiving the Listener's request, the Talker confirms the connection information with the Listener via RPC and sends its own TCP address information.
5. Listener Establishes Connection with Talker
The Listener uses the information returned in step 4 to establish a network connection with the Talker using TCP.
6. Talker Sends Messages to Listener
Once the connection is established, the Talker starts publishing messages to the Listener.
Note 1: In the above process, steps 0-4 use the RPC protocol, while the final two steps (5-6) use the TCP protocol.
Note 2: There is no strict requirement for the startup order of Talkers and Listeners.
Note 3: There can be multiple Talkers and multiple Listeners.
Note 4: After the connection between a Talker and a Listener is established, the ROS Master is no longer needed. This means that even if the ROS Master is shut down, the Talker and Listener will continue to communicate normally.