WEBVTT

00:00.050 --> 00:05.060
In this lesson you will see how to introspect your topics with the command line tools.

00:05.060 --> 00:07.520
We will look at the Ros2 topic command line.

00:07.520 --> 00:14.150
In fact, you've already seen two functionalities of that one Ros2 topic list and Ros two topic eco.

00:14.150 --> 00:17.630
So we are going to review them and discover a few new ones.

00:17.630 --> 00:21.530
First of all, what if I do Ros two topic list.

00:21.560 --> 00:23.390
That's going to list all the topics.

00:23.390 --> 00:27.770
So I have well I have parameter events and arose out.

00:27.770 --> 00:31.100
This is because I have run some nodes before.

00:31.100 --> 00:33.620
So if you run that for the first time you will not see this.

00:33.620 --> 00:37.760
But I have run some nodes recently and there is some stuff happening in the background.

00:37.760 --> 00:44.390
So anyway, you will see that every time you start a node, you will also see that you have two topics,

00:44.390 --> 00:46.040
one for parameter events.

00:46.040 --> 00:47.450
So that's for parameter stuffs.

00:47.450 --> 00:50.360
And we're going to see parameter later in this course.

00:50.360 --> 00:52.280
And one is Ros out.

00:52.280 --> 00:59.540
So basically actually when you do a log in a node, anytime you do a log it's also going to be published

00:59.570 --> 01:01.280
to the Ros out topic.

01:01.310 --> 01:01.580
Okay.

01:01.610 --> 01:05.260
You don't see that, but it's actually done in the background.

01:05.260 --> 01:07.840
So now let's do Ros two run.

01:07.840 --> 01:10.630
Let's start a node that has a publisher.

01:10.750 --> 01:17.050
So my Pi PG for example with Robot News Station okay.

01:17.080 --> 01:18.490
It has been started.

01:18.520 --> 01:25.810
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

01:25.810 --> 01:27.040
I do Ros two topic list.

01:27.040 --> 01:30.310
Again the robot news is gone.

01:30.340 --> 01:30.700
All right.

01:30.730 --> 01:39.250
So you will only see the topic in the list if you have at least one publisher or at least one subscriber

01:39.250 --> 01:40.480
to the topic.

01:40.480 --> 01:45.520
So we can do Ros two topic info with the topic name.

01:45.580 --> 01:48.640
So you find it with the list and then you do info.

01:48.670 --> 01:51.610
The info is going to give us the type.

01:51.610 --> 01:53.920
So we see that this topic.

01:53.950 --> 01:58.030
To publish or subscribe to this topic you need to use this interface.

01:58.030 --> 02:01.450
So example interfaces msg string.

02:01.450 --> 02:07.110
And you see that's exactly what we provided in the code, and we can see we have how many publishers

02:07.110 --> 02:09.990
we have one and we have zero subscriber.

02:10.020 --> 02:14.100
Okay, so Rostopic list and Ross two topic info.

02:14.130 --> 02:20.790
Now you can subscribe directly to a publisher or actually not to a publisher, but to a topic with Ross

02:20.820 --> 02:22.740
two topic equal.

02:22.770 --> 02:23.880
That's quite powerful.

02:23.880 --> 02:27.390
And you're going to provide the name of the topic.

02:27.390 --> 02:35.310
So robot news and in this case you see that I'm going to receive the messages from that publisher here.

02:35.310 --> 02:42.240
If I do a Ross two topic info here, you see we have one publisher, but now we have one subscriber

02:42.240 --> 02:46.980
because that's Ross two topic equal counts as a subscriber.

02:47.010 --> 02:53.640
Okay, if I stop that you see we lose the subscriber okay, so Ross two topic equal is probably one

02:53.640 --> 02:55.620
of the comments that I use the most.

02:55.650 --> 03:00.990
This is very, very useful because when you have a topic, well you find the name etc. but then if you

03:00.990 --> 03:04.700
just want to know quickly what's being published, what's going on in the topic.

03:04.700 --> 03:09.140
You just do a rostopic echo and you have all the data on the terminal.

03:09.140 --> 03:13.010
Then let's continue with the introspection here of the topics.

03:13.010 --> 03:13.790
So you have the list.

03:13.820 --> 03:19.220
You can find the info and then you see in the info you can find the interface.

03:19.250 --> 03:21.980
Now to see what's in the interface.

03:21.980 --> 03:24.140
What's the detail of that.

03:24.140 --> 03:30.170
You will use actually a different command line which is Ros2 interface.

03:30.170 --> 03:34.640
And you have the show keyword here and you need to provide.

03:34.640 --> 03:39.890
So you just take that name here and it's going to show you the detail.

03:39.920 --> 03:43.040
So the implementation of that interface.

03:43.040 --> 03:45.710
So here you can see once again we have some comments.

03:45.740 --> 03:52.010
And we just have one field which is a string data type with a data name okay.

03:52.040 --> 04:00.020
So from the Ros2 topic command line you can find the name of the topic, the type of the topic and what's

04:00.020 --> 04:02.480
exactly inside this type.

04:02.480 --> 04:06.100
Then there are two more commands I want to show you.

04:06.640 --> 04:09.040
So let's clear that.

04:09.160 --> 04:10.660
Let's clear that.

04:11.110 --> 04:13.630
So we still have one publisher running.

04:13.660 --> 04:14.320
Okay.

04:14.350 --> 04:21.760
Now, if you want to know what is the frequency at which messages are published on the topic, you can

04:21.760 --> 04:26.590
use Ross to topic h z for Hertz.

04:26.620 --> 04:27.160
Okay.

04:27.160 --> 04:28.990
And then the name of the topic.

04:29.080 --> 04:33.460
So Robot News that's going to listen to the topic.

04:33.940 --> 04:37.840
So you need to wait a few seconds and it's going to tell you the average rate.

04:37.870 --> 04:38.530
Okay.

04:38.530 --> 04:40.240
So let's control C here.

04:40.240 --> 04:42.640
And you see the average rate is two.

04:42.670 --> 04:43.960
That's two hertz.

04:43.990 --> 04:46.480
Two hertz means 0.5 seconds.

04:46.510 --> 04:46.990
Okay.

04:47.020 --> 04:48.970
And that's exactly what's happening here.

04:49.000 --> 04:54.850
So if you have one topic like this and we know we publish at 0.5 seconds, that's easy to verify.

04:54.850 --> 04:57.850
But then let's say you have several publishers with many different messages.

04:57.850 --> 05:02.950
Then you can have a good idea of how many messages are actually being published every second.

05:02.980 --> 05:05.380
Okay, with this Hz command.

05:05.380 --> 05:10.010
And now if you want to see not the frequency, but if you want to see the bandwidth.

05:10.010 --> 05:12.800
So how much data is actually sent?

05:12.830 --> 05:21.200
You can use Ros2 topic BW for bandwidth and same you provide the topic name.

05:23.000 --> 05:26.690
And so here let's wait a bit is gonna do the same thing.

05:26.690 --> 05:30.650
It's gonna create a subscriber and then print some data.

05:30.650 --> 05:31.610
And you can see.

05:31.610 --> 05:33.140
So that's the average.

05:33.140 --> 05:39.110
You see 100 and something 118 bytes per second.

05:39.110 --> 05:40.700
So that's really not that much here.

05:40.700 --> 05:42.530
We just send some text okay.

05:42.560 --> 05:47.960
But you can see with this how much data is actually sent through the topic.

05:47.990 --> 05:48.500
All right.

05:48.500 --> 05:55.580
So with H, Z and BW you can get more info about how many messages and how big they are.

05:55.610 --> 05:56.180
Great.

05:56.180 --> 06:02.150
And now we have seen how to introspect a topic when you already have some publishers that are running.

06:02.150 --> 06:04.640
But there is also a command you can use.

06:04.670 --> 06:09.340
Let's clear that this is a command you can use to publish on a topic.

06:09.370 --> 06:13.360
You can use rose to topic and then pub.

06:13.930 --> 06:15.220
Okay that's going to publish.

06:15.220 --> 06:17.590
Then you need to provide dash R.

06:17.620 --> 06:18.730
That's going to be the rate.

06:18.760 --> 06:22.000
Let's say I want to publish five times per second.

06:22.000 --> 06:24.430
So I'm going to put dash R five.

06:24.460 --> 06:26.680
After this I need to provide a name.

06:26.680 --> 06:28.960
So I'm going to use slash here.

06:28.990 --> 06:32.230
Robot news okay.

06:32.260 --> 06:33.460
The topic names.

06:33.460 --> 06:35.980
As you can see in the graph they start with a slash.

06:35.980 --> 06:38.260
So in the code you don't need to provide the slash.

06:38.260 --> 06:40.630
It's going to be added automatically for you.

06:40.660 --> 06:40.930
Okay.

06:40.960 --> 06:44.680
So we have dash R and then five and then space.

06:44.680 --> 06:47.140
And then the name of the topic and then space.

06:47.140 --> 06:49.870
And then we have the type.

06:49.900 --> 06:50.110
Okay.

06:50.140 --> 06:55.120
So we have the name and the type for the type we're going to use example interfaces.

06:55.120 --> 06:57.400
And here you can use the auto completion.

06:57.400 --> 06:59.470
It's going to make it much easier.

06:59.470 --> 07:04.750
You can see I just press tab and I have the whole thing for example interfaces msg string.

07:04.750 --> 07:08.790
That's recognized because this topic is using that data type.

07:08.790 --> 07:11.700
And then I need to put double quotes.

07:11.700 --> 07:13.740
And here the syntax is this one.

07:13.740 --> 07:16.170
So curly brackets we have a data field.

07:16.170 --> 07:18.000
And inside we're going to write.

07:18.000 --> 07:21.750
So I'm going to use just single quotes here because we already have double quotes.

07:21.780 --> 07:26.490
Let's say hello from the terminal okay.

07:26.520 --> 07:29.820
So the syntax is a bit more heavy with this comment.

07:29.820 --> 07:36.000
And that's only going to work when you have simple data types like for example this example interface

07:36.000 --> 07:36.690
string.

07:36.720 --> 07:42.960
Because if you have big data types with arrays and classes and subtypes and well, that's not going

07:42.990 --> 07:45.330
to be possible to publish from the terminal okay.

07:45.360 --> 07:47.670
So it only works with very small data types.

07:47.670 --> 07:49.110
So let's press enter.

07:49.830 --> 07:52.320
And you see it's publishing.

07:52.320 --> 07:54.150
So it's publishing on the topic.

07:54.150 --> 08:06.540
Now if I do rose to topic equal with robot news, you see that we're going to receive hello from the

08:06.540 --> 08:07.020
terminal.

08:07.020 --> 08:15.050
And also hi this is the robot from the news station, so we are actually receiving both messages from

08:15.050 --> 08:15.890
both publishers.

08:15.920 --> 08:16.880
Okay, it makes sense.

08:16.880 --> 08:23.240
All the publishers are publishing to a topic, and then from any subscriber we receive all the messages.

08:24.710 --> 08:26.510
So I'm going to stop that and stop that.

08:26.510 --> 08:28.790
Finally one last thing.

08:28.790 --> 08:31.880
So I'm going to clear and clear.

08:31.880 --> 08:34.340
We still have this publisher running.

08:34.340 --> 08:41.240
You can also find informations from the Ros2 node command line okay here we've only used the ros2 topic.

08:41.240 --> 08:46.400
But if you do ros2 node well if you do ros2 node list you will find that node.

08:46.400 --> 08:51.410
Then you do ros2 node info with the node.

08:52.040 --> 09:00.950
And you can see that in the publishers we have robot news topic and the interface name.

09:00.950 --> 09:01.370
Okay.

09:01.400 --> 09:05.480
So you can see you can also find the information using Ros2 node.

09:05.480 --> 09:09.860
So there are many ways you can find the same information from the terminal using the different command

09:09.860 --> 09:10.610
line tools.
