Let's continue with our launch file and improve it.
I will be using XML for the example, but still I will show you just in case, the Python syntax at
the end of the video.
So in the previous sections in this course you have seen that you can rename a node and you can remap
topics and services at runtime.
So for that you use the uh if you remember dash dash args and then dash R to rename, for example,
a node like that, and then a topic to a new topic and the same thing for services.
Well, this is something you can also do in a launch file.
Let's see how you can do that.
So first let's try to rename the node we want to rename.
Well we can rename both nodes.
In this case it's very easy.
You have in this node tag you have pkg exec.
And then you add another argument name and let's say my number publisher.
And that's it.
That's how you rename a node at runtime.
When you start it with a launch file we can do the same here.
name, which is going to be, uh.
Well, let's just also use my number counter.
Okay?
Once I have done this, I will I will go back to my workspace and click on Build packages, select with
my robot bring up.
Great.
And now I will.
So I still have stuff here.
I will source my environment.
And I can do Ros to run my robot.
Bring up with the number app.
So number actually it's not rush to run you see it's Ros to launch.
And I could see it because the auto completion didn't work.
So Ros to launch my robot bring up.
And that's going to be number app dot launch dot x m L.
It is working and you can see already in the logs.
So that's the executable name.
Okay.
Not to be confused with the node name.
The node name is my number counter and my number publisher.
We can see this with Ros2 node list and also with Actigraph you can see my number publisher my number
counter.
So we have correctly renamed the node.
Now what if you want to remap a topic or a service that's going to be the same.
What if I want to remap the number topic here?
Well let's go back and to remap we will need to actually add another tag inside the node tag.
So for now I have just closed the node tag like this so that it's just in one line.
Now I'm going to remove this forward slash to open the node tag, and I'm going to close it like that.
And now I can add more tags inside the node tag.
So make sure you have just one angle bracket here.
And here you have a forward slash.
and I can use the remap tag and it's going to be very easy.
You have a from argument and then a two argument and I'm going to close it like this.
From is the previous name two is the new name.
So the previous name we have for example number topic we want to rename to my number.
And this way when we start the node is going to change the topic name.
Or it's also working for services.
It's the same from number to my number.
Now if I do this of course it's not going to work for the number counter because the number counter
is still subscribing to number.
So I will do the same thing.
I will open and close the node tag, and then I will add a remapping which is basically the same.
So let's just take that one here and we also rename.
So we remap the topic name in both nodes.
All right let's save and let's build.
Well actually I don't even need that one.
I could I could directly build here.
If I do ctrl c here, let's go to the workspace, click on build packages, select my robot bring up
and then source install, setup bash and then Rose to launch my robot bring up still with the number
app launch XML.
So it is starting.
We don't have any log for the topics, so what we can do?
Well you could do a actually rose to topic list.
You see now we have my number topic.
And you can also verify that easily with arc graph.
And you see now the topic is my number.
So it has been remapped on that side and on that side.
So the publisher and the subscriber are now using a different name for the topic.
So you see, it's very powerful.
Okay.
From that launch file you can just change the name of the nodes, change the topic name, the service
name.
Okay.
All that from one file.
And you see we only have eight lines of code here.
To start, two nodes with a different name and a different topic name.
And let's have a quick look at the Python launch file for the same thing.
So this is the previous one and I have had it in my nodes you see.
So this config is still not that complicated.
Uh you have a name argument.
You can change the name of the node.
So we change it here.
We change it there as well.
And then for Remappings you have a remappings argument which is actually a list of tuples.
So you need to provide one tuple for each remapping that you want.
And you see with the previous name and the current name.
All right.
And even if I could save on spaces, you see now we have 24 lines and eight lines here.
But what.
So here's the Python way to do renamings and remappings.