WEBVTT

00:00.050 --> 00:02.900
Let's continue with our launch file and improve it.

00:02.900 --> 00:08.840
I will be using XML for the example, but still I will show you just in case, the Python syntax at

00:08.840 --> 00:09.980
the end of the video.

00:09.980 --> 00:15.380
So in the previous sections in this course you have seen that you can rename a node and you can remap

00:15.410 --> 00:17.660
topics and services at runtime.

00:17.660 --> 00:26.360
So for that you use the uh if you remember dash dash args and then dash R to rename, for example,

00:26.360 --> 00:34.490
a node like that, and then a topic to a new topic and the same thing for services.

00:34.490 --> 00:37.820
Well, this is something you can also do in a launch file.

00:37.820 --> 00:39.470
Let's see how you can do that.

00:39.470 --> 00:44.030
So first let's try to rename the node we want to rename.

00:44.030 --> 00:45.710
Well we can rename both nodes.

00:45.710 --> 00:47.300
In this case it's very easy.

00:47.300 --> 00:51.440
You have in this node tag you have pkg exec.

00:51.440 --> 00:59.690
And then you add another argument name and let's say my number publisher.

00:59.690 --> 01:00.560
And that's it.

01:00.560 --> 01:03.500
That's how you rename a node at runtime.

01:03.500 --> 01:06.590
When you start it with a launch file we can do the same here.

01:06.610 --> 01:09.760
name, which is going to be, uh.

01:09.760 --> 01:15.700
Well, let's just also use my number counter.

01:16.540 --> 01:16.900
Okay?

01:16.930 --> 01:31.030
Once I have done this, I will I will go back to my workspace and click on Build packages, select with

01:31.240 --> 01:33.550
my robot bring up.

01:34.480 --> 01:34.870
Great.

01:34.870 --> 01:35.950
And now I will.

01:35.980 --> 01:37.690
So I still have stuff here.

01:38.950 --> 01:42.730
I will source my environment.

01:43.000 --> 01:47.920
And I can do Ros to run my robot.

01:47.950 --> 01:50.980
Bring up with the number app.

01:51.040 --> 01:56.170
So number actually it's not rush to run you see it's Ros to launch.

01:56.170 --> 01:59.320
And I could see it because the auto completion didn't work.

01:59.350 --> 02:04.420
So Ros to launch my robot bring up.

02:04.420 --> 02:11.050
And that's going to be number app dot launch dot x m L.

02:13.260 --> 02:16.170
It is working and you can see already in the logs.

02:16.200 --> 02:18.120
So that's the executable name.

02:18.150 --> 02:18.360
Okay.

02:18.390 --> 02:21.690
Not to be confused with the node name.

02:21.690 --> 02:26.070
The node name is my number counter and my number publisher.

02:26.070 --> 02:35.610
We can see this with Ros2 node list and also with Actigraph you can see my number publisher my number

02:35.610 --> 02:36.120
counter.

02:36.120 --> 02:39.180
So we have correctly renamed the node.

02:39.210 --> 02:43.260
Now what if you want to remap a topic or a service that's going to be the same.

02:43.260 --> 02:46.080
What if I want to remap the number topic here?

02:47.070 --> 02:54.240
Well let's go back and to remap we will need to actually add another tag inside the node tag.

02:54.240 --> 02:59.370
So for now I have just closed the node tag like this so that it's just in one line.

02:59.400 --> 03:07.380
Now I'm going to remove this forward slash to open the node tag, and I'm going to close it like that.

03:09.000 --> 03:12.360
And now I can add more tags inside the node tag.

03:13.200 --> 03:15.630
So make sure you have just one angle bracket here.

03:15.660 --> 03:18.360
And here you have a forward slash.

03:19.360 --> 03:23.770
and I can use the remap tag and it's going to be very easy.

03:23.800 --> 03:30.700
You have a from argument and then a two argument and I'm going to close it like this.

03:31.600 --> 03:34.540
From is the previous name two is the new name.

03:34.540 --> 03:44.620
So the previous name we have for example number topic we want to rename to my number.

03:44.770 --> 03:49.510
And this way when we start the node is going to change the topic name.

03:49.510 --> 03:51.280
Or it's also working for services.

03:51.280 --> 03:54.910
It's the same from number to my number.

03:54.970 --> 03:59.500
Now if I do this of course it's not going to work for the number counter because the number counter

03:59.500 --> 04:02.350
is still subscribing to number.

04:02.350 --> 04:04.300
So I will do the same thing.

04:04.330 --> 04:12.790
I will open and close the node tag, and then I will add a remapping which is basically the same.

04:12.790 --> 04:17.110
So let's just take that one here and we also rename.

04:17.110 --> 04:20.260
So we remap the topic name in both nodes.

04:20.290 --> 04:23.230
All right let's save and let's build.

04:23.230 --> 04:24.840
Well actually I don't even need that one.

04:24.840 --> 04:27.360
I could I could directly build here.

04:27.390 --> 04:43.200
If I do ctrl c here, let's go to the workspace, click on build packages, select my robot bring up

04:44.880 --> 04:57.750
and then source install, setup bash and then Rose to launch my robot bring up still with the number

04:57.780 --> 05:01.740
app launch XML.

05:03.090 --> 05:05.580
So it is starting.

05:05.580 --> 05:09.390
We don't have any log for the topics, so what we can do?

05:09.420 --> 05:13.650
Well you could do a actually rose to topic list.

05:14.520 --> 05:16.500
You see now we have my number topic.

05:16.500 --> 05:19.920
And you can also verify that easily with arc graph.

05:20.640 --> 05:22.830
And you see now the topic is my number.

05:22.830 --> 05:26.850
So it has been remapped on that side and on that side.

05:26.850 --> 05:31.550
So the publisher and the subscriber are now using a different name for the topic.

05:31.550 --> 05:33.470
So you see, it's very powerful.

05:33.560 --> 05:34.070
Okay.

05:34.100 --> 05:40.370
From that launch file you can just change the name of the nodes, change the topic name, the service

05:40.370 --> 05:40.880
name.

05:40.910 --> 05:41.240
Okay.

05:41.270 --> 05:43.700
All that from one file.

05:43.700 --> 05:47.030
And you see we only have eight lines of code here.

05:47.030 --> 05:51.590
To start, two nodes with a different name and a different topic name.

05:51.590 --> 05:55.850
And let's have a quick look at the Python launch file for the same thing.

05:55.850 --> 06:00.020
So this is the previous one and I have had it in my nodes you see.

06:00.050 --> 06:02.870
So this config is still not that complicated.

06:03.140 --> 06:05.450
Uh you have a name argument.

06:06.020 --> 06:07.640
You can change the name of the node.

06:07.640 --> 06:08.840
So we change it here.

06:08.840 --> 06:10.370
We change it there as well.

06:10.370 --> 06:16.970
And then for Remappings you have a remappings argument which is actually a list of tuples.

06:16.970 --> 06:22.220
So you need to provide one tuple for each remapping that you want.

06:22.250 --> 06:25.430
And you see with the previous name and the current name.

06:25.520 --> 06:26.000
All right.

06:26.000 --> 06:32.540
And even if I could save on spaces, you see now we have 24 lines and eight lines here.

06:32.540 --> 06:32.990
But what.

06:33.020 --> 06:37.310
So here's the Python way to do renamings and remappings.
