Message Communication Methods
In this article we will give an idea of how ROS nodes communicate with each other. Basically nodes exchange data with other nodes through messages subsequently forming a large program. There are three different methods for message communication among nodes. These are
Most of the message communication is done using topics. It is a one way communication. The publisher node is registered with master on a certain topic and then publish the data on that topic. While, the subscriber node registers with master to subscribe the topic. The subscriber node then connects to the publisher node and receives the data on that topic in the form of messages. There can be multiple publisher and subscriber nodes for the same topic.
The method of “publish” and “subscribe” of a topic is not only unidirectional but it is also asynchronous. It is useful for periodical data transmission. On the other hand, there is a synchronized message communication method which is called “service”. This is a one-time message communication. In this case a service client sends a request to a service server, which responds to the request. After the work is done, the connection between two nodes will be disconnected. Since service does not maintain the connection, therefore it is useful to reduce the load of the network in comparison to a topic.
Another bidirectional communication method is “Action”. Similar to service, it involves action client and action server nodes, and works on the mechanism of request and response. However the terms used in this method are “goal” and “result” instead of “request” and “response”. There are also intermediate actions (Cancel, Feedback, and Status) as shown in the figure. The action is used when goal needs a longer time to be completed, hence progress feedback is also required. However, this communication is also asynchronous like topic. It means that the program can perform other operations while action tasks are in progress.
Parameters are not strictly considered the method of message communication however these are the part of this process. Parameters are global variables used by the nodes. In parameter file, the configurations are set with default values that can be read and write externally, when required. The parameters can also be modified in real time from outside the node using the write function.
Message communication between nodes are comprehensively illustrated in the Figure 1
Figure 1: Message communication between ROS nodes
Here we can briefly compare the three message communication methods in a table.
|Topic||Asynchronous||Unidirectional||It is used when data is exchanged continuously/periodically.|
|Service||Synchronous||Bi-directional||It is used when a task needs to be done one-time and meanwhile the other tasks cannot be performed until current requested task is completed. It is based on “request” and “response” mechanism|
|Action||Asynchronous||Bi-directional||Action is used when it takes longer time as compare to processing a service request. Hence intermediate responses (feedback, status) are also required. Action can be perform while other tasks are also in progress.|
Table 1: Comparison of message communication methods.