In this lesson we will review how to introspect your last two services with the Ros2 command line.
In fact, you've already seen most of the comments with Ros2 service list and Ros to service call.
So you can open a terminal and you can type Ros2.
Then we have service.
If you press on tab twice, you will also see all of the possible.
You see all of the possible subcommands for the Ros2 service.
And if you do dash h, you also have kind of a small documentation with more information.
So let's clear that and let's start a service server okay.
We're going to introspect services.
So we need a service.
How to start a service.
Well we create it when we create a server.
So let's run our service server in for example the C plus plus package or the Python one.
It doesn't matter add to int server okay.
So we have the server running here.
And now I can do ros two.
So first let's do a Ros two node list just to show you once again that you can find from the node information.
You can find the services.
We can do ros2 node info with the node name.
And you see in the service servers here we have the add to hints.
So we have the name and the interface.
So we have all the information already here.
But then you can also find this service with Ros2 service list.
You see we have the service here.
And you can see that we have 1234567 additional services here.
What are those services.
Well most of them you see contain the word parameters.
So this is for the parameter functionality.
So we're going to see parameters in a future section in this course.
And basically for each node that you start you also have a bunch of services that allow you to for example
get parameters, modify parameters and stuff like that so that you will have for every node you create,
you see that's the name of the node and then parameter.
You also have here get type description.
So you may have additional stuff.
But basically if you didn't create it in your code, you see that it's been automatically generated
and you will have those seven.
Or maybe if they do an update and they add one more or they remove, well, you're going to have about
seven services here for each node that you start.
All right.
So if we filter those out we can just see that this is the one that we have created.
And then there is another command you can do ros2 service type.
So type.
And note that for topics it was Ros2 topic info for service it's Ros2 service type okay.
It's not the same world and you can put the here service name.
And we also get the type.
Okay.
You see it's the same thing we got with the Ros2 node info.
And then how to see what's inside this interface.
Well we have the Ros2 interface show, and you just put the name of the interface, and that's going
to show you what's inside.
Okay.
So this we've already done it.
So here you have the request three dashes and the response.
All right.
So knowing how to use those commands is very useful because let's say you start a service server that
you haven't written and you don't know what's in the code.
Then you see that we just started here.
And then with Ros2 command line tools, we can find all the information we need so that we can create
a client, for example, and so that we can call the service and we can even call the service from the
terminal.
So if the request is quite small here, you see we just have two easy fields.
So just primitive data types.
If the request is quite small here you see we just have two integers.
Then that's going to be easy to create a request from the terminal.
So in this case you can do ros2 service call.
And then you will need to provide a few things in that order.
So the first thing is the service name.
Servicename.
So add to int and you should use Autocompletion here.
Okay, just so you don't make any typo after the name of the service, you need to provide the interface.
And here you can just type the first letter and press tab and it's going to find it.
Okay.
Because it knows that for this service it needs that interface.
So if you put the first 1 or 2 letters and then the tab doesn't work, it's probably because you have
written that service name wrong.
Or maybe it's not up okay.
But use the Autocompletion here.
So Ros2 service call name interface.
And then if I press tab twice you see that we have.
So we need to provide A and B.
You see we have this kind of syntax here that's not really readable and not easy to use.
So instead we can just use double quotes and create the request with curly brackets okay.
And then put each field.
So for example a and then colon.
And then that's important.
You have to put a space, because if you don't put a space, you're going to get an error here.
And let's put a value.
Then if you want to provide several parameters, you put another comma and then space and then B space
seven for example.
And we can press enter.
It's going to create.
So it's going to send a request.
You see we have the request here.
And then it's going to get the response.
And note that you don't need to provide all the parameters here.
If I just put a let's see what's going to happen.
You see it's still working.
If you don't provide a parameter in the request, you see that it's automatically set to zero for a
integer.
And for string is going to be an empty string.
All right.
So that's how you can call a service from the terminal.
And you can test simple service servers.
Now there is another way to call the service I'm going to show you with Rkt.
So if you start Rkt.
Okay maybe you have this.
That was activity graph.
You can close it here Okay.
And we are back to this acute window.
You can go on plugins and services service color.
So I click here and you see we have well you can choose the service here.
We're going to choose add to insert.
And we have the service name the type and the different fields of the requests.
Okay.
And you can just double click here and let's say for three let's put the window here and let's call
the service.
You see we have a log on the server side.
And we have the response here.
So RCT can also be quite nice to use.
That's a graphical tool.
And also you don't need to write so much stuff on the terminal.
You just put the different fields here okay.
That's also going to work well for simple requests.
So you can see to test service server you have lots of different choices.
You can use the Ros2 service call in the terminal.
You can use RCT.
You can also use the script we have created with either Python or C plus, plus and modify the script
to send the appropriate request.