ROS services
When we need a request/response kind of communication in ROS, we have to use the ROS services. ROS topics can't implement natively such kind of communication because it is unidirectional. The ROS services are mainly used in a distributed system.
The ROS services are defined using a pair of messages. We have to define a request datatype and a response datatype in a srv file. The srv files are kept in a srv folder inside a package.
In ROS services, one node acts as a ROS server in which the service client can request the service from the server. If the server completes the service routine, it will send the results to the service client. For example, consider a node able to provide the sum of two numbers received in input, implementing this functionality through a ROS service. The other nodes of our system might request the sum of two numbers via this service. Differently, topics are used to stream continuous data flow.
The ROS service definition can be accessed by the following method; for example, if my_package/srv/Image.srv can be accessed by my_package/Image.
In ROS services also, there is an MD5 checksum that checks in the nodes. If the sum is equal, then only the server responds to the client.
There are two ROS tools to get information about the ROS service. The first tool is rossrv, which is similar to rosmsg, and is used to get information about service types. The next command is rosservice, which is used to list and query about the running ROS services.
The following explain how to use the rosservice tool to get information about the running services:
- $ rosservice call /service args: This tool will call the service using the given arguments
- $ rosservice find service_type: This command will find services in the given service type
- $ rosservice info /services: This will print information about the given service
- $ rosservice list: This command will list the active services running on the system
- $ rosservice type /service: This command will print the service type of a given service
- $ rosservice uri /service: This tool will print the service ROSRPC URI