WEBVTT

00:00.050 --> 00:02.510
This is an extra lesson that I wanted to add.

00:02.510 --> 00:08.690
And here I'm going to talk about Ross two bags, which can be very useful when working with topics.

00:08.690 --> 00:14.000
So this is more of a parenthesis in this course, and it's the only time I will talk about bags so you

00:14.000 --> 00:16.220
can see it as a bonus.

00:16.220 --> 00:21.260
And to understand what bags are and why we need them, let's start with the problem.

00:21.260 --> 00:22.640
Let's use an example.

00:22.640 --> 00:28.040
Let's say you need to test a robot outside so you have a mobile robot or whatever robot.

00:28.070 --> 00:31.640
You need to test your robot outside when it's raining.

00:31.640 --> 00:37.670
And let's say you are working in a university or in a workplace, but then let's say, well, you don't

00:37.670 --> 00:39.350
have access to the robot all the time.

00:39.350 --> 00:45.260
Maybe you cannot take it outside all the time, and maybe when you take it outside, it's not necessarily

00:45.260 --> 00:46.850
raining all the time.

00:46.850 --> 00:52.520
So that's going to be a problem, especially if you need to develop a feature to improve the robot behavior

00:52.520 --> 00:54.470
when it's raining outside.

00:54.470 --> 00:59.210
And so instead of waiting every time that you have access to the robot, that you can take it outside

00:59.210 --> 01:04.510
and that it's raining, what you could do is to run the experiment once.

01:04.510 --> 01:10.480
So let's say you take it one hour outside when it's raining, you run the experiment once and you save

01:10.480 --> 01:12.130
all the data from the topics.

01:12.130 --> 01:16.960
So for example, if you have a camera topic, if you have will topics, while all the topics that you

01:16.960 --> 01:21.310
have in your applications, you could save the ones that you want inside the data set.

01:21.310 --> 01:27.520
And then you could replay this data set later on, and then you could develop the feature of your application

01:27.520 --> 01:29.050
for this data set.

01:29.080 --> 01:29.200
Okay.

01:29.200 --> 01:30.880
That's going to be much more convenient.

01:30.880 --> 01:33.640
And that's exactly what bags allow you to do.

01:33.640 --> 01:40.750
So with a Ros2 bag, you can save the data from a topic for any amount of time you want, and then you

01:40.750 --> 01:44.710
can replay this data as many times as you want.

01:44.710 --> 01:46.570
And let's see how to do that.

01:46.570 --> 01:50.830
So first of all we will need a publisher okay.

01:50.860 --> 01:55.780
So I'm going to start the publisher we just had from the previous activity.

01:55.810 --> 01:59.620
I'm going to start here Ros to run my pip pig.

01:59.920 --> 02:02.550
And let's start the number.

02:02.850 --> 02:03.930
Publisher.

02:05.490 --> 02:07.680
So that's going to publish on a number topic.

02:07.680 --> 02:16.830
And I'm also going to start here to run my Pi PG number counter.

02:16.830 --> 02:18.090
So here we have a subscriber.

02:18.090 --> 02:20.340
And we also have another publisher.

02:20.340 --> 02:27.180
If I do roster topic list you can see that we have a number topic and a number count topic okay.

02:27.210 --> 02:31.830
So let's say we want to save one of those topics or the two of them.

02:31.830 --> 02:35.220
So I am now in my home directory.

02:35.220 --> 02:42.630
Let's create well let's keep things organized I'm going to create a folder named bags okay.

02:42.660 --> 02:47.010
And we're going to save the bags in that folder just so they are not everywhere.

02:47.010 --> 02:49.920
And then we have the Ros2 command line tool if you remember.

02:49.920 --> 02:52.710
And in this command line we also have Ros2 bag.

02:52.710 --> 02:55.320
And with Ros2 bag you can do dash h.

02:55.320 --> 02:59.040
And of course you have all of the possible commands.

02:59.070 --> 02:59.700
Okay.

03:00.240 --> 03:04.450
So here I'm going to do Ros2 bag and how to record a topic.

03:04.450 --> 03:08.920
I'm going to do record, and then I need to provide the name of a topic.

03:08.920 --> 03:11.980
So let's do a Ross two topic list again here.

03:12.700 --> 03:16.120
Let's say I want to save the number count topic.

03:16.120 --> 03:21.370
So I'm going to do record and then slash number count.

03:21.400 --> 03:22.930
Let's press enter.

03:23.290 --> 03:26.410
And you see we have a lot of stuff here.

03:26.410 --> 03:29.110
So it's listening for topics.

03:29.110 --> 03:32.950
You see we have subscribed to the topic number count okay.

03:32.980 --> 03:34.420
It's recording.

03:34.420 --> 03:36.880
And well you see it's hanging in there.

03:36.880 --> 03:38.620
So it's going to record.

03:38.680 --> 03:43.540
As long as this is running then you can press Ctrl C.

03:43.540 --> 03:48.160
And when you press Ctrl C you see that the recording has stopped.

03:48.160 --> 03:53.680
And here from the logs it seems you see I had 64 and 84.

03:53.680 --> 04:00.880
So I have recorded for about 20s, which means that all the data that was published on that number count

04:00.910 --> 04:05.520
topic for those 20s are now recorded inside a bag.

04:05.520 --> 04:06.540
And if I do lose?

04:06.540 --> 04:09.660
You see, I have a Ross bag here with a time stamp.

04:09.660 --> 04:12.330
So if I go inside, what do we have?

04:12.660 --> 04:18.870
Well, you see, we have some information and the data itself with a map file.

04:18.870 --> 04:22.290
So that's going to contain all of the topics you have saved.

04:22.890 --> 04:26.880
And if I show what's in this metadata.yaml.

04:27.900 --> 04:35.460
Well you can find for example, well the duration in nanoseconds, the starting time and then the different

04:35.490 --> 04:36.780
topics that we have saved.

04:36.780 --> 04:43.260
So you see here we have saved the number count topic with the type and then how many messages we have

04:43.260 --> 04:43.740
saved.

04:43.740 --> 04:48.480
You see we have saved 20 messages and a bit more stuff.

04:48.720 --> 04:50.310
Let's clear that.

04:51.360 --> 04:53.100
Let's go back to our bikes folder.

04:53.100 --> 04:56.220
So we don't really need to go inside the bike itself.

04:56.220 --> 04:57.240
But now you know that.

04:57.270 --> 05:02.400
Well, in this bag we have a YAML file with some information and then the messages.

05:02.760 --> 05:06.440
Now let's start this command again.

05:07.190 --> 05:08.900
So Rose two bike record.

05:08.900 --> 05:14.180
And let's add here a dash o option with test.

05:14.180 --> 05:19.070
Because here by default is going to do rosbag two and then a timestamp.

05:19.070 --> 05:24.470
But you can do a dash o to provide the output name okay.

05:24.500 --> 05:29.660
So for example here I'm going to record for a few seconds and then press control C.

05:29.660 --> 05:33.110
And you see I have the test folder okay.

05:33.110 --> 05:36.500
So you can rename the bag with dash o.

05:36.500 --> 05:38.330
And then you should only have.

05:38.330 --> 05:42.950
Well if you're going to record again you see the folder already exists.

05:42.950 --> 05:44.570
So you need to give a new name.

05:44.600 --> 05:44.960
All right.

05:44.990 --> 05:47.570
So test one for example.

05:47.870 --> 05:49.550
And then control C.

05:49.550 --> 05:52.850
And you see we have our test and test one folder.

05:52.850 --> 05:58.730
You can do rose two bag info as well with for example test.

05:58.730 --> 06:01.040
So you just provide the folder name.

06:01.400 --> 06:04.750
And you can see here actually well we have the back side.

06:04.750 --> 06:10.330
We have the duration, the start, the end, the number of messages, the topics we have saved with

06:10.330 --> 06:11.710
the data type, etc..

06:11.710 --> 06:17.740
So you see what we saw before in this YAML file that's saved inside the folder.

06:17.740 --> 06:22.120
What we find basically the same information here, but more readable.

06:22.120 --> 06:23.920
So you don't even need to go inside.

06:23.920 --> 06:27.040
You just do Ross Toolbag info and you get the same information.

06:27.040 --> 06:30.310
And then now you know how to record topics inside the bag.

06:30.310 --> 06:38.290
How to play a bag again, you can do Ross to bag and then play and then just the name.

06:38.290 --> 06:41.950
So for example test is going to replay.

06:42.370 --> 06:47.530
So you see here it's starting playback and it's ending with just a few seconds okay.

06:47.560 --> 06:53.050
So it's going to replay and publish again all the data that was received on that topic.

06:53.050 --> 06:54.130
Let's do a.

06:54.160 --> 07:01.150
So let's do a Ross two topic equal number count okay.

07:01.180 --> 07:05.200
So here we have what we have this node here I'm going to stop all the nodes.

07:05.230 --> 07:12.460
Okay, so now we don't have anything publishing on that number count.

07:12.490 --> 07:13.270
As you can see.

07:13.270 --> 07:17.590
And I'm going to do Ros2 bag play.

07:17.590 --> 07:21.910
And I'm going to play the first one that I have recorded, this one.

07:21.910 --> 07:25.090
So Rosbag two with a timestamp.

07:25.090 --> 07:27.250
And let's press enter.

07:27.580 --> 07:31.990
And you see now we receive the data here on the number count topic.

07:31.990 --> 07:36.670
And you see at this time the counter was at 180.

07:36.700 --> 07:44.050
And then it's continuing to be published for that one was for 20s.

07:44.710 --> 07:46.330
So let's wait a bit more.

07:46.570 --> 07:50.710
And you see, after 20s the bag stops.

07:50.710 --> 07:57.100
So the ros2 bag play command stops and we have received 20 messages.

07:57.130 --> 07:57.490
All right.

07:57.520 --> 08:03.370
So everything you have recorded at that time is going to be published exactly as it was, because you

08:03.370 --> 08:10.960
can see we were reaching 750 for the number count with the number counter node, but when we recode

08:10.960 --> 08:12.730
it, it was 180.

08:12.730 --> 08:16.330
So we are playing back the data that was at that time.

08:16.630 --> 08:18.250
And so you can see that's very useful.

08:18.250 --> 08:23.260
You can just play the data exactly as it was when you tested your robot.

08:23.260 --> 08:34.300
And finally, let's so let's, uh, run the publisher and the counter again and let's do a Ros two bag

08:35.380 --> 08:37.030
and recode again.

08:38.380 --> 08:43.780
So recode and then oh, let's name it test two.

08:44.140 --> 08:52.300
And then, well, you have seen that you can use a topic name, but you can also provide several topic

08:52.300 --> 08:53.020
names okay.

08:53.050 --> 08:54.880
So number count and number.

08:54.910 --> 09:01.480
In this case I'm going to record you see subscribe to topic number count and subscribe to topic number.

09:01.480 --> 09:03.970
So you can record several topics.

09:04.000 --> 09:07.290
I'm going to press Ctrl I'll see if I do.

09:07.380 --> 09:10.290
Let's put that a bit bigger if I do.

09:10.320 --> 09:14.550
Ross to bag info test two.

09:14.910 --> 09:19.650
You see, we have two topics with nine messages for each.

09:19.650 --> 09:25.320
So if you're going to replay, that bag is going to replay all of the topics that you saved.

09:25.320 --> 09:32.460
And finally you can also just do dash A if you want to record all of the topic.

09:33.450 --> 09:34.860
So in this case what.

09:34.890 --> 09:36.660
Test two is already existing.

09:36.660 --> 09:38.400
I'm going to put test three.

09:39.000 --> 09:43.980
And you see now it's subscribing to all of the existing topics.

09:44.160 --> 09:46.140
Okay I'm going to press Ctrl C.

09:46.140 --> 09:50.970
And then if I do Ross two back info test three.

09:51.270 --> 09:52.920
You see we have the number topic.

09:52.920 --> 09:56.640
We even have extra topics that we didn't even see before.

09:57.030 --> 09:57.390
Okay.

09:57.420 --> 09:58.050
Number count.

09:58.080 --> 10:01.110
We have the parameter events and the rows out.

10:01.140 --> 10:02.520
All right so that's it for Ross.

10:02.520 --> 10:02.910
Two bags.

10:02.910 --> 10:06.630
And as you can see that can be a very useful functionality.
