ROS Service
Different from topic, service is bidirectional communication between a service server and a service client. The service can be described as the following sequential mechanism:
- A service client makes a request to a service server
- The service server sends a response to the service client
- The communication between the service client and the service server is terminated.
Because the communication between the service client and the service server only occurs during the request and response and afterwards the communication is terminated, service is appropriate to be used to perform a task which only occurs in a certain condition (not all the time). The use of service, instead of topic, in such a case can reduce the network load. Service is commonly used to query an information, to setup a configuration, or to perform a non-progressive task.
The jobs of service client and service server can be summarized as follow:
- Service client: 1) sending a request to service server, and 2) receiving a response from the service server.
- Service server: 1) receiving a request from service client, 2) performing the requested task, and 3) sending a response to the service client.
The configuration of a service is given by two parts: 1) request and 2) response. These two parts are defined in a file called .srv file. An .srv file looks like this:
1 2 3 4 5 |
data_type request_variable_1 data_type request_variable_2 --- data_type response_variable_1 data_type response_variable_2 |
A complete list of CLI commands regarding ROS service can be found here: http://wiki.ros.org/rosservice