WEBVTT

00:00.080 --> 00:04.100
In this lesson you will see how to create a Ros2 Cplusplus package.

00:04.100 --> 00:09.860
Please make sure that you watch the previous video on how to create a Python package so you can better

00:09.860 --> 00:10.550
understand.

00:10.550 --> 00:14.480
And the first thing is to navigate inside your Ros2 workspace.

00:14.480 --> 00:17.960
So for example, from anywhere you just go back to your home directory.

00:17.960 --> 00:22.700
You go to the roster workspace and inside the source folder okay.

00:22.880 --> 00:24.950
Here we already have one package.

00:24.950 --> 00:26.870
So my Python package.

00:26.870 --> 00:32.540
And that's where we will put all the packages for our application for our workspace.

00:32.540 --> 00:40.580
So now that you are in this source folder you can do Ros2 and then pkg create okay.

00:40.610 --> 00:41.990
So that's the same command.

00:42.020 --> 00:43.730
Then we're going to give a name.

00:43.730 --> 00:47.330
So let's do my CP pkg.

00:47.360 --> 00:52.850
So once again you can name it as you want as long as it makes sense here for this example.

00:52.850 --> 00:57.170
And for this first package of this course I just name it my C plus plus package.

00:57.170 --> 01:01.000
We need to provide a build type.

01:01.090 --> 01:06.820
And this time the build type is going to be element underscore CMake.

01:06.850 --> 01:10.090
That's going to create a C plus plus package.

01:10.120 --> 01:10.330
Okay.

01:10.360 --> 01:13.750
So we had element Python for Python packages.

01:13.750 --> 01:17.320
And we have element cmake for C plus plus packages.

01:17.320 --> 01:21.760
And as you will see the architecture of the package is going to be completely different.

01:21.760 --> 01:23.920
So with that command that's going to be enough.

01:23.920 --> 01:25.570
You can already launch it.

01:25.570 --> 01:29.260
But if we want we can also add dependencies okay.

01:29.260 --> 01:32.800
And I'm going to add a dependency this time to our CL cpp.

01:32.980 --> 01:38.020
So we have our clcp which is the C plus plus library for ros2.

01:38.050 --> 01:42.820
And that's going to allow you to write C plus plus code to interact directly with the functionalities

01:42.820 --> 01:43.810
of Ros2.

01:43.840 --> 01:48.430
And you can add as many dependencies you want after this option here.

01:48.430 --> 01:49.870
For now we just add one.

01:49.900 --> 01:52.270
We're going to add more later in this course.

01:52.270 --> 01:58.330
So now that I have this command inside the source folder I can press enter.

01:58.330 --> 02:00.580
And that's going to create another package.

02:00.580 --> 02:04.840
So you can see we also have some logs creating folders and files.

02:04.840 --> 02:09.460
We also have a warning for the license okay but no need to worry about that.

02:09.460 --> 02:11.110
We don't need a license for now.

02:11.110 --> 02:15.010
And so let's do a clear here LZ.

02:15.010 --> 02:18.880
And you can see we have a my C plus plus package.

02:18.880 --> 02:25.150
So let's open VSCode and well if you have closed VSCode make sure you go back again.

02:25.180 --> 02:30.610
You go back to your source folder and then you do code dot always like that.

02:30.610 --> 02:33.370
That's what I always do and I never have any problem.

02:33.370 --> 02:40.750
So you press enter here and you can see we have still our Python package.

02:40.780 --> 02:43.210
Our C plus plus package now is right here.

02:43.210 --> 02:45.790
And the architecture is quite different.

02:45.790 --> 02:51.250
As you can see here for a C plus plus package we have an include folder with the name.

02:51.340 --> 02:54.010
So another folder with the name of the package.

02:54.010 --> 02:56.860
And then we have a source folder after that.

02:56.860 --> 02:59.580
We also have a CMake list dot txt.

02:59.940 --> 03:05.370
So I'm just going to ignore all of the pop ups here because we already have the correct extensions in

03:05.370 --> 03:06.000
VSCode.

03:06.000 --> 03:13.890
And as you can see, well, if you already know a bit of C plus plus that's typically a well a C plus

03:13.890 --> 03:14.610
plus project.

03:14.610 --> 03:17.940
You have a source and include folder and then a cmakelists.txt.

03:18.000 --> 03:23.940
So this is really basically a standard C plus plus architecture inside the Ros2 package.

03:23.970 --> 03:24.270
All right.

03:24.300 --> 03:26.610
So that's going to be the implementation files.

03:26.640 --> 03:30.330
The CPP files in the include you have the header files.

03:30.360 --> 03:33.150
There's going to be the HPP files or the H files.

03:33.150 --> 03:38.550
And then in Cmakelists.txt you're going to write the rules to build your code.

03:38.580 --> 03:42.030
Okay I'm going to come back to the Cmakelists.txt when we write the first note.

03:42.030 --> 03:43.860
For now let's just close that.

03:43.860 --> 03:46.350
And you see we also have a package dot XML.

03:46.350 --> 03:49.830
And this one is very similar to the one we had for Python.

03:49.860 --> 03:50.040
Okay.

03:50.070 --> 03:51.330
So package dot XML.

03:51.360 --> 03:57.800
Basically this is the only file that you need to have in every Ros2 to package.

03:57.830 --> 03:58.070
Okay.

03:58.100 --> 04:00.110
So that's the minimum thing you need to have.

04:00.110 --> 04:05.660
And as you can see we also have name version description emails license.

04:05.660 --> 04:07.940
So we have all those things.

04:08.000 --> 04:10.760
If you want to publish the package you will need to fill those.

04:10.760 --> 04:13.580
Then you see we have the Aim and CMake here.

04:13.610 --> 04:14.540
That's the build type.

04:14.540 --> 04:18.860
And we also have the dependency with the depend tag with rcl, cpp.

04:19.040 --> 04:24.710
And so if you want to add more dependencies you will need to add more depend tag just after that one.

04:24.740 --> 04:25.250
Great.

04:25.250 --> 04:28.550
So now let's go back to the terminal and let's build this package.

04:28.550 --> 04:36.080
So once again don't run call build here just in case I'm going to run call on build okay in my source

04:36.080 --> 04:36.770
folder.

04:36.980 --> 04:39.800
So I make the mistake of running call on build here.

04:39.800 --> 04:40.970
What's going to happen.

04:40.970 --> 04:43.100
Well you see it's still building stuff.

04:43.100 --> 04:49.460
And now I have to install a build and a log folder inside my source repository.

04:49.460 --> 04:53.240
But I also have the same thing in my ros2 workspace.

04:53.240 --> 04:59.630
So if you have that well things can be confusing and you might have a lot of errors in the future.

04:59.630 --> 05:03.680
So if you have made a mistake, it's not a problem you just remove.

05:03.680 --> 05:08.420
So let's do a remove with recursive of the build, install and log.

05:08.450 --> 05:14.150
Okay, so that's just to show you that if you build in the wrong place, make sure you remove all those

05:14.150 --> 05:15.020
folders.

05:15.020 --> 05:20.450
And then make sure you build exactly in this Ros2 workspace.

05:20.840 --> 05:23.780
So now I can do call on build.

05:25.820 --> 05:30.770
And you can see we are building the C plus plus package and the Python package.

05:30.770 --> 05:39.020
And if I only want it to build the C plus plus package I can do call build with packages select and

05:39.020 --> 05:42.020
then my C plus plus package.

05:42.050 --> 05:46.760
I press enter and you can see that we only build that package okay.

05:46.790 --> 05:48.530
So this option is very useful.

05:48.560 --> 05:49.100
Great.

05:49.130 --> 05:50.720
Now you have a C plus plus package.

05:50.720 --> 05:52.310
You also have a Python package.

05:52.310 --> 05:55.880
So let's see what a node is and then let's create one.
