In this lesson you will see how to introspect your topics with the command line tools.
We will look at the Ros2 topic command line.
In fact, you've already seen two functionalities of that one Ros2 topic list and Ros two topic eco.
So we are going to review them and discover a few new ones.
First of all, what if I do Ros two topic list.
That's going to list all the topics.
So I have well I have parameter events and arose out.
This is because I have run some nodes before.
So if you run that for the first time you will not see this.
But I have run some nodes recently and there is some stuff happening in the background.
So anyway, you will see that every time you start a node, you will also see that you have two topics,
one for parameter events.
So that's for parameter stuffs.
And we're going to see parameter later in this course.
And one is Ros out.
So basically actually when you do a log in a node, anytime you do a log it's also going to be published
to the Ros out topic.
Okay.
You don't see that, but it's actually done in the background.
So now let's do Ros two run.
Let's start a node that has a publisher.
So my Pi PG for example with Robot News Station okay.
It has been started.
Now if I do Ros two topic list, you see we have the robot news and you see if I stop the node and if
I do Ros two topic list.
Again the robot news is gone.
All right.
So you will only see the topic in the list if you have at least one publisher or at least one subscriber
to the topic.
So we can do Ros two topic info with the topic name.
So you find it with the list and then you do info.
The info is going to give us the type.
So we see that this topic.
To publish or subscribe to this topic you need to use this interface.
So example interfaces msg string.
And you see that's exactly what we provided in the code, and we can see we have how many publishers
we have one and we have zero subscriber.
Okay, so Rostopic list and Ross two topic info.
Now you can subscribe directly to a publisher or actually not to a publisher, but to a topic with Ross
two topic equal.
That's quite powerful.
And you're going to provide the name of the topic.
So robot news and in this case you see that I'm going to receive the messages from that publisher here.
If I do a Ross two topic info here, you see we have one publisher, but now we have one subscriber
because that's Ross two topic equal counts as a subscriber.
Okay, if I stop that you see we lose the subscriber okay, so Ross two topic equal is probably one
of the comments that I use the most.
This is very, very useful because when you have a topic, well you find the name etc. but then if you
just want to know quickly what's being published, what's going on in the topic.
You just do a rostopic echo and you have all the data on the terminal.
Then let's continue with the introspection here of the topics.
So you have the list.
You can find the info and then you see in the info you can find the interface.
Now to see what's in the interface.
What's the detail of that.
You will use actually a different command line which is Ros2 interface.
And you have the show keyword here and you need to provide.
So you just take that name here and it's going to show you the detail.
So the implementation of that interface.
So here you can see once again we have some comments.
And we just have one field which is a string data type with a data name okay.
So from the Ros2 topic command line you can find the name of the topic, the type of the topic and what's
exactly inside this type.
Then there are two more commands I want to show you.
So let's clear that.
Let's clear that.
So we still have one publisher running.
Okay.
Now, if you want to know what is the frequency at which messages are published on the topic, you can
use Ross to topic h z for Hertz.
Okay.
And then the name of the topic.
So Robot News that's going to listen to the topic.
So you need to wait a few seconds and it's going to tell you the average rate.
Okay.
So let's control C here.
And you see the average rate is two.
That's two hertz.
Two hertz means 0.5 seconds.
Okay.
And that's exactly what's happening here.
So if you have one topic like this and we know we publish at 0.5 seconds, that's easy to verify.
But then let's say you have several publishers with many different messages.
Then you can have a good idea of how many messages are actually being published every second.
Okay, with this Hz command.
And now if you want to see not the frequency, but if you want to see the bandwidth.
So how much data is actually sent?
You can use Ros2 topic BW for bandwidth and same you provide the topic name.
And so here let's wait a bit is gonna do the same thing.
It's gonna create a subscriber and then print some data.
And you can see.
So that's the average.
You see 100 and something 118 bytes per second.
So that's really not that much here.
We just send some text okay.
But you can see with this how much data is actually sent through the topic.
All right.
So with H, Z and BW you can get more info about how many messages and how big they are.
Great.
And now we have seen how to introspect a topic when you already have some publishers that are running.
But there is also a command you can use.
Let's clear that this is a command you can use to publish on a topic.
You can use rose to topic and then pub.
Okay that's going to publish.
Then you need to provide dash R.
That's going to be the rate.
Let's say I want to publish five times per second.
So I'm going to put dash R five.
After this I need to provide a name.
So I'm going to use slash here.
Robot news okay.
The topic names.
As you can see in the graph they start with a slash.
So in the code you don't need to provide the slash.
It's going to be added automatically for you.
Okay.
So we have dash R and then five and then space.
And then the name of the topic and then space.
And then we have the type.
Okay.
So we have the name and the type for the type we're going to use example interfaces.
And here you can use the auto completion.
It's going to make it much easier.
You can see I just press tab and I have the whole thing for example interfaces msg string.
That's recognized because this topic is using that data type.
And then I need to put double quotes.
And here the syntax is this one.
So curly brackets we have a data field.
And inside we're going to write.
So I'm going to use just single quotes here because we already have double quotes.
Let's say hello from the terminal okay.
So the syntax is a bit more heavy with this comment.
And that's only going to work when you have simple data types like for example this example interface
string.
Because if you have big data types with arrays and classes and subtypes and well, that's not going
to be possible to publish from the terminal okay.
So it only works with very small data types.
So let's press enter.
And you see it's publishing.
So it's publishing on the topic.
Now if I do rose to topic equal with robot news, you see that we're going to receive hello from the
terminal.
And also hi this is the robot from the news station, so we are actually receiving both messages from
both publishers.
Okay, it makes sense.
All the publishers are publishing to a topic, and then from any subscriber we receive all the messages.
So I'm going to stop that and stop that.
Finally one last thing.
So I'm going to clear and clear.
We still have this publisher running.
You can also find informations from the Ros2 node command line okay here we've only used the ros2 topic.
But if you do ros2 node well if you do ros2 node list you will find that node.
Then you do ros2 node info with the node.
And you can see that in the publishers we have robot news topic and the interface name.
Okay.
So you can see you can also find the information using Ros2 node.
So there are many ways you can find the same information from the terminal using the different command
line tools.