Summary
In this chapter, you worked on ROS 2 services, which is another ROS 2 communication you can use alongside topics.
With services, nodes can talk to each other using a client/server type of communication. Only one server can exist for a service, but you can send multiple requests from several clients.
You can implement service servers and clients directly in your nodes using rclpy
for Python and rclcpp
for C++.
To write a service server, you must do the following:
- As the name and interface are defined by the server, you have to choose them here. As a best practice, use a verb as the first word in the name.
- Import the interface in your code and create the service server in the constructor.
- Add a callback method to process any received request.
When choosing a service interface, if you can’t find an existing one that perfectly matches what you need, then you have to create and build your own. To do that, you must do the following:
-
...