Services
Topics are very useful to send a stream of data/commands from one node to another node. However, this is not the only way to communicate. You can also find client/server communications in ROS 2. In this case, services will be used.
As we did for topics, we will run two nodes communicating with each other, this time with services, and we will try to analyze, using the ROS 2 tools, what’s happening and how the communication is working.
In Chapter 6, you will get a much more detailed explanation about services, when to use them versus topics, and how to include them in your code. For now, let’s just continue with our discovery phase.
Running a service server and client
Stop all running nodes. This time, we will start another node from demo_nodes_cpp
, which contains a simple service server to add two integer numbers. We will also start a client node, which will send a request to the server node.
In Terminal 1, input the following:
$ ros2 run demo_nodes_cpp...