Skip to content

2.2 Service Communication

Service communication is another extremely common communication pattern in ROS. Service communication is based on the request-response model, which is a reply mechanism. That is: Node A sends a request to Node B, Node B receives and processes the request, then generates a response result and returns it to Node A. For example, consider the following scenario:

During a robot's patrol, the control system analyzes sensor data and detects a suspicious object or person... At this point, it needs to take a photo and save it.

In the scenario described above, service communication is used.

  • One node needs to send a photo capture request to the camera node. The camera node processes the request and returns the processing result.

Similar to the application above, service communication is more suitable for application scenarios that require timeliness and involve certain logical processing.


Concept

A communication pattern that enables data interaction between different nodes through a request-response approach.

Purpose

Used for occasional, time-sensitive data transmission scenarios that require some logical processing.

Example

Implement the summation of two numbers. A client node runs and sends two numbers to the server. The server node receives the two numbers, calculates their sum, and sends the result back to the client as a response.

img


See also: