3.3. Services#
In the section covering nodes, topics, and messages, we looked at the publisher-subscriber model of communication between nodes. nodes can receive a constant stream of data and updates. Services offer a different method of communication through a call-response mode. Instead of getting constant data, services only provide data when it is called by a client.
Nodes can contain service clients and servers. The client provides a call through a service, and the server then sends out a response. For each individual service, there can be multiple clients and only one server.
ROS2 Service Example (Courtesy of ROS2 Documentation)
3.3.1. An Example of a Service#
Further on in this tutorial, you will be learning about turtlesim, a program that uses ROS2 to simulate turtles. There are many services in this program, but very simple one is /spawn.
Simply put, you select this service from a list and fill in settings for where you would like to put your turtle. Once you’re done filling out the settings, there is a button that says call. This call button initiates the same “call” that was mentioned in this introduction to this Services chapter above. Once you press this button, a call for a service will be initiated and a message will be sent to the service server. Finally, the server will send out a response in the form of actually making your turtle appear!
Once again, more details will be given about these services when you start learning about turtlesim later on in this tutorial. However, for now, this is a good example of a service and how the call/response function works.