WEBVTT

00:00.080 --> 00:05.930
In this lesson we will review how to introspect your last two services with the Ros2 command line.

00:05.930 --> 00:12.290
In fact, you've already seen most of the comments with Ros2 service list and Ros to service call.

00:12.290 --> 00:16.250
So you can open a terminal and you can type Ros2.

00:16.280 --> 00:17.540
Then we have service.

00:17.540 --> 00:21.710
If you press on tab twice, you will also see all of the possible.

00:21.710 --> 00:25.760
You see all of the possible subcommands for the Ros2 service.

00:25.760 --> 00:31.730
And if you do dash h, you also have kind of a small documentation with more information.

00:31.730 --> 00:36.380
So let's clear that and let's start a service server okay.

00:36.410 --> 00:38.000
We're going to introspect services.

00:38.000 --> 00:39.560
So we need a service.

00:39.560 --> 00:40.730
How to start a service.

00:40.730 --> 00:43.520
Well we create it when we create a server.

00:43.520 --> 00:50.660
So let's run our service server in for example the C plus plus package or the Python one.

00:50.660 --> 00:56.780
It doesn't matter add to int server okay.

00:56.810 --> 00:58.550
So we have the server running here.

00:58.550 --> 01:00.290
And now I can do ros two.

01:00.320 --> 01:07.850
So first let's do a Ros two node list just to show you once again that you can find from the node information.

01:07.850 --> 01:09.500
You can find the services.

01:09.500 --> 01:14.480
We can do ros2 node info with the node name.

01:14.930 --> 01:20.150
And you see in the service servers here we have the add to hints.

01:20.150 --> 01:23.420
So we have the name and the interface.

01:23.420 --> 01:25.610
So we have all the information already here.

01:25.640 --> 01:30.980
But then you can also find this service with Ros2 service list.

01:32.060 --> 01:33.800
You see we have the service here.

01:33.800 --> 01:40.040
And you can see that we have 1234567 additional services here.

01:40.040 --> 01:41.450
What are those services.

01:41.450 --> 01:44.990
Well most of them you see contain the word parameters.

01:44.990 --> 01:48.080
So this is for the parameter functionality.

01:48.110 --> 01:51.950
So we're going to see parameters in a future section in this course.

01:51.950 --> 01:59.690
And basically for each node that you start you also have a bunch of services that allow you to for example

01:59.690 --> 02:06.530
get parameters, modify parameters and stuff like that so that you will have for every node you create,

02:06.530 --> 02:09.900
you see that's the name of the node and then parameter.

02:09.900 --> 02:13.020
You also have here get type description.

02:13.020 --> 02:15.840
So you may have additional stuff.

02:15.840 --> 02:21.330
But basically if you didn't create it in your code, you see that it's been automatically generated

02:21.330 --> 02:23.310
and you will have those seven.

02:23.340 --> 02:27.990
Or maybe if they do an update and they add one more or they remove, well, you're going to have about

02:27.990 --> 02:32.010
seven services here for each node that you start.

02:32.040 --> 02:32.550
All right.

02:32.550 --> 02:38.490
So if we filter those out we can just see that this is the one that we have created.

02:38.490 --> 02:43.590
And then there is another command you can do ros2 service type.

02:44.400 --> 02:45.960
So type.

02:46.380 --> 02:54.000
And note that for topics it was Ros2 topic info for service it's Ros2 service type okay.

02:54.000 --> 03:00.090
It's not the same world and you can put the here service name.

03:00.270 --> 03:02.460
And we also get the type.

03:02.490 --> 03:02.700
Okay.

03:02.730 --> 03:06.450
You see it's the same thing we got with the Ros2 node info.

03:06.720 --> 03:10.620
And then how to see what's inside this interface.

03:10.620 --> 03:19.140
Well we have the Ros2 interface show, and you just put the name of the interface, and that's going

03:19.170 --> 03:20.790
to show you what's inside.

03:20.820 --> 03:21.000
Okay.

03:21.030 --> 03:22.470
So this we've already done it.

03:22.470 --> 03:26.610
So here you have the request three dashes and the response.

03:26.640 --> 03:27.120
All right.

03:27.120 --> 03:34.230
So knowing how to use those commands is very useful because let's say you start a service server that

03:34.230 --> 03:37.050
you haven't written and you don't know what's in the code.

03:37.080 --> 03:39.390
Then you see that we just started here.

03:39.390 --> 03:45.090
And then with Ros2 command line tools, we can find all the information we need so that we can create

03:45.120 --> 03:50.940
a client, for example, and so that we can call the service and we can even call the service from the

03:50.940 --> 03:51.480
terminal.

03:51.480 --> 03:56.700
So if the request is quite small here, you see we just have two easy fields.

03:56.700 --> 03:58.770
So just primitive data types.

03:58.770 --> 04:02.820
If the request is quite small here you see we just have two integers.

04:02.820 --> 04:05.910
Then that's going to be easy to create a request from the terminal.

04:05.910 --> 04:09.780
So in this case you can do ros2 service call.

04:09.780 --> 04:12.810
And then you will need to provide a few things in that order.

04:12.810 --> 04:15.990
So the first thing is the service name.

04:15.990 --> 04:16.000
Servicename.

04:16.000 --> 04:20.620
So add to int and you should use Autocompletion here.

04:20.650 --> 04:25.870
Okay, just so you don't make any typo after the name of the service, you need to provide the interface.

04:25.870 --> 04:30.910
And here you can just type the first letter and press tab and it's going to find it.

04:30.940 --> 04:31.330
Okay.

04:31.360 --> 04:35.470
Because it knows that for this service it needs that interface.

04:35.470 --> 04:41.290
So if you put the first 1 or 2 letters and then the tab doesn't work, it's probably because you have

04:41.290 --> 04:43.420
written that service name wrong.

04:43.420 --> 04:45.190
Or maybe it's not up okay.

04:45.220 --> 04:46.900
But use the Autocompletion here.

04:46.900 --> 04:49.750
So Ros2 service call name interface.

04:49.750 --> 04:55.780
And then if I press tab twice you see that we have.

04:55.780 --> 04:58.510
So we need to provide A and B.

04:58.990 --> 05:05.980
You see we have this kind of syntax here that's not really readable and not easy to use.

05:05.980 --> 05:13.690
So instead we can just use double quotes and create the request with curly brackets okay.

05:13.720 --> 05:15.550
And then put each field.

05:15.550 --> 05:18.640
So for example a and then colon.

05:18.730 --> 05:20.530
And then that's important.

05:20.530 --> 05:24.250
You have to put a space, because if you don't put a space, you're going to get an error here.

05:24.250 --> 05:26.200
And let's put a value.

05:26.230 --> 05:33.670
Then if you want to provide several parameters, you put another comma and then space and then B space

05:33.670 --> 05:34.990
seven for example.

05:34.990 --> 05:37.150
And we can press enter.

05:37.930 --> 05:38.980
It's going to create.

05:38.980 --> 05:40.420
So it's going to send a request.

05:40.450 --> 05:41.920
You see we have the request here.

05:41.920 --> 05:44.050
And then it's going to get the response.

05:44.050 --> 05:47.920
And note that you don't need to provide all the parameters here.

05:47.950 --> 05:50.830
If I just put a let's see what's going to happen.

05:50.980 --> 05:52.900
You see it's still working.

05:52.900 --> 06:00.250
If you don't provide a parameter in the request, you see that it's automatically set to zero for a

06:00.250 --> 06:00.670
integer.

06:00.670 --> 06:02.530
And for string is going to be an empty string.

06:02.560 --> 06:02.860
All right.

06:02.890 --> 06:06.040
So that's how you can call a service from the terminal.

06:06.040 --> 06:08.770
And you can test simple service servers.

06:08.800 --> 06:13.420
Now there is another way to call the service I'm going to show you with Rkt.

06:13.600 --> 06:15.880
So if you start Rkt.

06:17.950 --> 06:19.840
Okay maybe you have this.

06:19.870 --> 06:21.220
That was activity graph.

06:21.220 --> 06:23.870
You can close it here Okay.

06:23.870 --> 06:26.780
And we are back to this acute window.

06:26.810 --> 06:31.700
You can go on plugins and services service color.

06:32.540 --> 06:37.370
So I click here and you see we have well you can choose the service here.

06:37.370 --> 06:39.320
We're going to choose add to insert.

06:39.320 --> 06:45.200
And we have the service name the type and the different fields of the requests.

06:45.230 --> 06:45.740
Okay.

06:45.770 --> 06:53.600
And you can just double click here and let's say for three let's put the window here and let's call

06:53.600 --> 06:54.410
the service.

06:54.440 --> 06:56.360
You see we have a log on the server side.

06:56.360 --> 06:57.770
And we have the response here.

06:57.770 --> 07:01.160
So RCT can also be quite nice to use.

07:01.160 --> 07:02.660
That's a graphical tool.

07:02.660 --> 07:05.540
And also you don't need to write so much stuff on the terminal.

07:05.540 --> 07:07.970
You just put the different fields here okay.

07:08.000 --> 07:11.480
That's also going to work well for simple requests.

07:11.480 --> 07:15.680
So you can see to test service server you have lots of different choices.

07:15.680 --> 07:18.080
You can use the Ros2 service call in the terminal.

07:18.080 --> 07:19.040
You can use RCT.

07:19.130 --> 07:25.580
You can also use the script we have created with either Python or C plus, plus and modify the script

07:25.610 --> 07:28.070
to send the appropriate request.
