In the previous section on tools and with nodes and Ros to run, you have seen that you can rename a
node at runtime.
Well, it's also possible to rename a topic and it's pretty simple.
Let's see how to do that.
So first we are going to use the Ros to run with the package name for example my pi pkg.
And let's start the robot new station.
What you have seen so far I'm going to put that a bit bigger.
What you have seen so far.
How to rename a node for example Ros.
You put Ros args and then dash r and then underscore underscore node and let's name it my station okay.
So you run that you see now the node is my station.
So I can do Ros two node list.
It's called my station.
And if I do Ros two topic list.
So the topic is still robot news okay.
We haven't modified the topic.
Now I'm going to stop and I'm going to run the command again.
But this time I'm also going to rename the topic.
So how to do that?
Well, as I told you, you need to put Ros ARGs, but you only need to put that once.
Okay.
So it's already here.
Then we have one remapping for the node with this underscore underscore node.
To add another remapping you just add another dash R.
And then here well we need to provide the name of the topic.
So what is the name of the topic robot news.
We don't need to provide the slash okay.
It's robot news in the code here.
It's.
So if I go to the Python one you see we have created the robot news topic.
So I put this one here and I put colon equal and I put the new name.
So let's say a b c.
If I press enter now I have renamed the node and also the topic.
So if I do Ros two topic lists you see now we have the ABC topic Okay if I do ros2 topic equal a b c.
You see, that's where we receive the data now.
Okay.
So when you do a remapping of the topic you can see that.
So this string here when you do create publisher it's actually not fixed okay.
It can be changed at runtime.
So this name can be overridden at runtime with that dash R and then the name.
So the previous name and the new name.
So now let's for example let's run here Ros to run my.
So you could run the Python one or the C plus plus one.
It doesn't matter.
Let's run the smartphone node which is subscribing to the robot news station.
So to the robot news topic.
And you see we receive nothing.
Why is that.
Because Ros two topic list.
You see that we have the topic ABC here and we have the topic Robot news.
So if we want to be able to receive the information.
We are also going to do a remapping of the topic.
So we do Dash, Dash, Ross, AGS.
And then here I'm not going to rename the node, I'm just going to rename the topic.
So Dash R robot News colon equal ABC.
I press enter and you can see now we receive the data.
Why.
Because this is a subscriber to ABC and this is a publisher to ABC okay.
So this can be very very useful because if you need to match different nodes written by different persons,
or maybe you can't access the code and you can't modify the topic name in the code.
Well, you just remap the topic name at runtime.
And very important.
Again, you only write the Ros args once.
As you can see here we do two remappings, but we only write ros args once and then dash r and the remapping.