WEBVTT

00:00.080 --> 00:06.650
In this lesson, you will see how to create your first custom Ros2 interface and we will create a message

00:06.650 --> 00:07.010
here.

00:07.010 --> 00:10.340
But first of all, where will you write your interfaces?

00:10.340 --> 00:12.590
Where will you write the message definition?

00:12.590 --> 00:18.680
If we go to our rust workspace in the source folder, we already have two packages.

00:18.680 --> 00:19.970
So in which package?

00:19.970 --> 00:26.210
Well, basically you could technically add message definitions in any package you want.

00:26.240 --> 00:31.910
However, it will be much easier for you to create all the custom interfaces that you have in a single

00:31.910 --> 00:39.200
package dedicated only to custom interfaces that will prevent you from having a dependency mess in the

00:39.200 --> 00:44.060
future, and when you need to import a custom interface in another package, for example, from the

00:44.060 --> 00:48.890
Python package here, you just need to add a dependency to that new interface package.

00:48.890 --> 00:49.700
And that's it.

00:49.700 --> 00:51.740
So let's create a package.

00:51.740 --> 00:54.380
And that's something we will need to do only once okay.

00:54.380 --> 00:59.540
Because once we have this package, any new interface we add is going to be in that same package.

00:59.540 --> 01:02.530
So we go to our source folder okay.

01:02.560 --> 01:04.360
Where we have already our two.

01:04.390 --> 01:05.860
Existing packages.

01:05.860 --> 01:11.110
And we are going to do Ros2 pkg create and I'm going to name it.

01:11.140 --> 01:14.650
My robot interfaces.

01:14.650 --> 01:19.090
So for the name I recommend that you start with the name of your application.

01:19.090 --> 01:21.910
So if your robot here I'm just using my robot.

01:21.940 --> 01:25.630
If your robot is named ABC, you're going to put ABC.

01:25.720 --> 01:30.940
Or if you have an application name, you just put the application name and then underscore interfaces

01:30.970 --> 01:31.150
okay.

01:31.180 --> 01:36.580
We're going to use interfaces as a suffix here to make it clear that this is an interface package.

01:36.580 --> 01:38.770
And then well then that's it.

01:38.770 --> 01:44.650
You could actually put a build type with amount CMake.

01:44.650 --> 01:49.390
But actually if you don't provide it, it's just going to be a CMake by default.

01:49.390 --> 01:51.040
And we don't really need it anyway.

01:51.040 --> 01:53.020
And we're not going to provide any dependencies.

01:53.020 --> 01:59.950
So what I do to create an interface package, I just do Ros to create and the name of the package.

02:00.040 --> 02:01.480
Let's press enter.

02:01.480 --> 02:06.580
And you see we have some logs for the files that were created.

02:06.610 --> 02:09.250
A warning for the license that we can just ignore.

02:09.250 --> 02:12.610
And now we have our new package here.

02:12.610 --> 02:19.510
And if I go inside my robot interfaces, you see this is a C plus plus package.

02:19.510 --> 02:22.360
So we will need the package dot XML file.

02:22.360 --> 02:27.400
As for any package in Ros2, we will also need Cmakelists.txt.

02:27.430 --> 02:30.850
That's where we're going to provide rules to build our interfaces.

02:30.850 --> 02:34.030
But then we don't need src and we don't need include.

02:34.030 --> 02:36.040
So what I'm going to do is just I'm going to clean that.

02:36.040 --> 02:40.090
I'm going to remove the include and I'm going to remove the SRC.

02:40.480 --> 02:40.720
Okay.

02:40.750 --> 02:46.360
So now we just have those two files and we will need to add a few lines inside those files here so we

02:46.360 --> 02:48.400
can build our interfaces.

02:48.400 --> 02:50.440
So let's open.

02:50.620 --> 02:56.350
I'm going to open here this workspace with Visual Studio Code.

02:57.810 --> 03:02.100
and let's go to my robot interfaces.

03:02.280 --> 03:04.410
For example in package dot XML.

03:04.410 --> 03:07.830
So you see here build tool depend its element CMake.

03:07.860 --> 03:08.760
That's what we want.

03:08.790 --> 03:10.680
And we have the build type here as well.

03:10.710 --> 03:12.510
Now what do we add here.

03:12.540 --> 03:15.930
Well there are three lines you need to add in package dot XML.

03:15.930 --> 03:21.600
And in order not to make mistakes, it's actually better to just copy and paste them from an existing

03:21.690 --> 03:22.710
configuration.

03:22.710 --> 03:24.660
So we can go on.

03:24.750 --> 03:29.700
Let's go on the internet and you can just type custom Ros2 interfaces.

03:29.700 --> 03:34.770
We're going to find something and let's go for example to that website.

03:34.770 --> 03:37.650
I might link it to this lesson.

03:38.250 --> 03:41.550
And this website is actually pretty nice for Ros2 tutorials.

03:41.550 --> 03:42.480
Robotics back end.

03:42.480 --> 03:45.780
And I'm absolutely not saying that just because it's my own website.

03:45.810 --> 03:50.910
Okay, so in this tutorial, well, we don't really want to read the tutorial.

03:50.910 --> 03:53.010
We just want to go down here.

03:53.010 --> 03:57.920
You can find the same information under Also ros2 official documentation.

03:57.920 --> 03:59.720
You will find those same lines here.

03:59.720 --> 04:06.080
But you see, when we set up a package for Ros2 custom interfaces, we have three lines we need to add.

04:06.110 --> 04:06.470
Okay.

04:06.500 --> 04:07.790
Build tool depend.

04:07.820 --> 04:09.080
I'm going to zoom in a bit.

04:09.110 --> 04:14.870
Build tool depend with Ros ideal default generators and then execute depend with Ros.

04:14.900 --> 04:18.770
Ideal default runtime and member of group Ros.

04:18.800 --> 04:20.450
Ideal interface packages.

04:20.450 --> 04:25.700
So that's why I'm not just going to write them in order not to make mistakes, I'm just going to copy

04:25.700 --> 04:27.470
and paste them.

04:27.530 --> 04:28.280
Okay.

04:28.310 --> 04:34.340
After the build tool here after build tool depend I just add those three lines.

04:34.370 --> 04:34.520
Okay.

04:34.550 --> 04:40.820
There is nothing really to understand Ros ideal is basically the functionality that's going to create

04:40.820 --> 04:42.260
and manage interfaces.

04:42.260 --> 04:44.300
So you just need to add those lines.

04:44.300 --> 04:49.670
The good thing is after you do this once that's basically it for your whole application.

04:49.700 --> 04:50.120
All right.

04:50.120 --> 04:51.770
So that's it for package dot XML.

04:51.770 --> 04:59.050
We can close it and then we can open Cmakelists.txt and we will first clean a bit.

04:59.050 --> 05:05.260
I don't need this build testing stuff and just remove those comments here.

05:05.290 --> 05:12.220
Okay, so we have the minimum thing for the list.txt and I'm going to go back to that web page.

05:12.520 --> 05:14.350
You need to add this.

05:14.380 --> 05:19.240
Okay Findpackage with Ross ideal default generators.

05:19.240 --> 05:23.080
Then we are going to add Ross ideal generate interfaces.

05:23.080 --> 05:28.060
That's the command to generate interfaces where we're going to put the path to all of the interfaces

05:28.060 --> 05:28.690
we create.

05:28.690 --> 05:34.360
And then you have amend export dependencies with Ross ideal default runtime.

05:34.360 --> 05:37.570
So again it's not really important to understand anything here.

05:37.600 --> 05:40.150
Just have to add this to your configuration.

05:40.150 --> 05:45.550
So let's go here after Findpackage here and before element package.

05:45.850 --> 05:47.200
Let's add a line.

05:47.350 --> 05:49.570
Let's add a space here.

05:51.580 --> 05:52.150
Okay.

05:52.180 --> 05:54.670
And you see your custom interfaces will be here.

05:54.700 --> 05:59.890
One per line and no comma for separating lines, as you can see.

05:59.920 --> 06:04.990
So I'm just going to remove everything now and let's save that.

06:04.990 --> 06:07.180
And now the package is configured.

06:07.210 --> 06:07.570
Okay.

06:07.600 --> 06:10.330
So we have three lines in the package dot XML.

06:10.330 --> 06:16.930
And then we have this fine package this function here and this element export dependencies here for

06:16.930 --> 06:18.400
the Cmakelists.txt.

06:18.430 --> 06:23.470
Now that we have set up the package we can create our first interface.

06:23.470 --> 06:24.910
So how to do that.

06:24.940 --> 06:31.750
Well I'm going to go back here in my robot interfaces package.

06:31.750 --> 06:37.750
And to create a message we are going to create first an MSG folder.

06:38.200 --> 06:38.590
Okay.

06:38.620 --> 06:41.770
And that's where we are going to put all our messages.

06:41.800 --> 06:46.030
I go inside the MSG and let's create a new interface.

06:46.030 --> 06:49.720
Let's say we want to publish the hardware status of our robot.

06:49.720 --> 06:53.010
So that's going to contain a few information about the robot.

06:53.040 --> 06:56.340
For example, I don't know the name, the version number, the temperature.

06:56.520 --> 06:57.810
All kinds of stuff.

06:57.810 --> 06:59.490
So let's create an interface.

06:59.490 --> 07:04.980
Touch hardware status dot msg.

07:05.040 --> 07:09.750
So what are the rules to create names for interfaces?

07:09.750 --> 07:14.760
Well you are going to start with an uppercase and you're going to use upper camel case okay.

07:14.790 --> 07:18.300
So no dashes no underscore is very important.

07:18.300 --> 07:22.650
And you're going to separate each word by an uppercase.

07:22.650 --> 07:27.870
That is going to have an importance for example for the C plus plus header files as we will see later.

07:27.870 --> 07:29.190
So you start with an uppercase.

07:29.190 --> 07:31.110
Each new word has an uppercase.

07:31.140 --> 07:33.840
Also don't write message okay.

07:33.840 --> 07:36.840
We could say hardware status message or something.

07:36.840 --> 07:37.500
Don't write this.

07:37.530 --> 07:38.850
It's going to be redundant.

07:38.850 --> 07:41.070
So just the name of the interface.

07:41.070 --> 07:45.630
And then dot msg for a message definition.

07:45.630 --> 07:52.340
Now I'm going to go back here and let's edit that file so we can use primitive data types.

07:52.340 --> 07:57.680
We can also use existing messages from that package or from other packages.

07:57.680 --> 07:59.240
Let's keep things simple here.

07:59.240 --> 08:01.370
And let's just use primitive types.

08:01.370 --> 08:06.560
Let's say we have a float 64.

08:06.590 --> 08:09.980
That's going to be the temperature okay.

08:09.980 --> 08:12.740
I'm just going to use a few examples with some types.

08:12.740 --> 08:18.590
And then let's say bool are mortals ready.

08:18.740 --> 08:19.400
Okay.

08:19.460 --> 08:24.980
And let's add a string debug message okay.

08:25.010 --> 08:30.590
So you can see I write one field on each line okay.

08:30.620 --> 08:34.070
There is no other separation, no comma, no punctuation.

08:34.100 --> 08:36.710
The first thing I do is I put the type.

08:36.710 --> 08:38.930
So here those are primitive types.

08:38.930 --> 08:40.100
And then the name.

08:40.100 --> 08:43.340
And to separate words I use underscore okay.

08:43.370 --> 08:47.120
It's very important here to use underscores and nothing else.

08:47.120 --> 08:47.930
And that's it.

08:47.930 --> 08:49.420
So it's not really complicated.

08:49.450 --> 08:51.280
Now I'm going to save.

08:51.310 --> 08:56.260
Just make sure that you use exactly the the syntax or the good syntax for primitive types.

08:56.260 --> 08:57.430
I'm going to save this file.

08:57.430 --> 08:58.720
Make sure you save everything.

08:58.720 --> 09:06.190
And then well once I have created a new interface, all I need to do is to go back to my cmakelists.txt.

09:06.400 --> 09:10.270
And inside this rose ideal generate interfaces.

09:10.270 --> 09:16.750
I'm going to add a new line with double quotes, and I'm going to put the path to the interface.

09:16.750 --> 09:26.290
So from here we need to go to the msg folder slash hardware status dot m s g.

09:26.470 --> 09:27.880
And that's it okay.

09:27.910 --> 09:35.500
So you see after you've set up the package, adding a new interface is just about creating a file in

09:35.500 --> 09:40.990
this folder and then adding the path to the file here in that function.

09:40.990 --> 09:44.740
Then you save and then let's go back to the terminal.

09:44.740 --> 09:53.410
Let's stay in that one and let's go back to our Ros2 workspace folder here, and let's do a call on

09:53.410 --> 09:54.040
build.

09:55.060 --> 10:00.250
I'm going to also use packages select to only build this interface.

10:00.250 --> 10:07.450
So my robot interfaces let's build it might take a bit of time the first time that you build some interfaces.

10:10.150 --> 10:11.740
Okay so it took 11 seconds.

10:11.740 --> 10:12.700
It's not that bad.

10:12.700 --> 10:16.210
And now the interface has been built okay.

10:16.240 --> 10:23.410
If you go to the install folder inside the My Robot interfaces, you could find and check the C plus

10:23.410 --> 10:24.910
plus and the Python files.

10:24.940 --> 10:25.120
Okay.

10:25.150 --> 10:27.250
You can try to do that on your own if you want.

10:27.280 --> 10:31.480
But once again it's not really that important because they exist and we don't need to check them.

10:31.480 --> 10:32.890
We can just use them.

10:32.890 --> 10:38.050
And let's see in this terminal the interface we have just created.

10:38.050 --> 10:44.350
So because we have just built here in that terminal, if we're using another one that we haven't sourced

10:44.380 --> 10:46.560
after that we need to source it now.

10:46.560 --> 10:51.090
So let's source the bash RC so we can source our workspace.

10:51.120 --> 10:55.230
And then I can do Ros2 interface show.

10:55.230 --> 10:59.490
And let's start with the package name my robot and let's press tab.

10:59.490 --> 11:01.200
You see I have only one.

11:01.200 --> 11:08.880
So my robot interfaces slash msg slash hardware status I press enter.

11:08.880 --> 11:12.990
And this is the message definition that I have okay.

11:13.020 --> 11:14.790
So now you understand this.

11:14.790 --> 11:17.070
We have done several times Ros2 interface show.

11:17.070 --> 11:23.610
But now you see the whole process to create an interface to build it and then to see it on the terminal.

11:23.640 --> 11:24.120
Great.

11:24.120 --> 11:27.900
And make sure that you can see the interface with this command.

11:27.930 --> 11:28.080
Okay.

11:28.110 --> 11:33.120
If you cannot see the interface, then you will not be able to use the message in your code in the next

11:33.120 --> 11:33.690
lesson.

11:33.690 --> 11:35.880
So make sure that you can do that if needed.

11:35.880 --> 11:41.370
You remove the package, you clean everything up and you start everything again from scratch because

11:41.370 --> 11:42.540
there are quite a few steps here.

11:42.540 --> 11:45.540
So make sure that this is working before you go to the following.
