WEBVTT

00:00.050 --> 00:04.100
To create a raster node, you first need a package.

00:04.130 --> 00:08.360
Packages will allow you to separate your code into reusable blocks.

00:08.390 --> 00:11.060
Each package is an independent unit.

00:11.060 --> 00:16.850
For example, in one application you could have one package that will handle a camera, another package

00:16.850 --> 00:21.980
that will run the wheels of your robot, and yet another one that will handle motion planning for the

00:21.980 --> 00:23.750
robot in the environment.

00:23.750 --> 00:29.120
So we will first create a simple Python package here, and you will learn more about packages and best

00:29.120 --> 00:31.220
practices all along this course.

00:31.250 --> 00:37.220
Note that in Ros2, Python packages and Cplusplus packages have a complete different architecture.

00:38.330 --> 00:41.660
So where will we create our Python package?

00:41.660 --> 00:45.110
Well, that's going to be inside our Ros2 workspace.

00:45.110 --> 00:50.240
So you go inside the Ros2 workspace and you go also in the source folder okay.

00:50.270 --> 00:54.620
Make sure that you create all the files inside this src folder.

00:54.650 --> 00:55.550
It's very important.

00:55.550 --> 00:57.410
So now this is empty of course.

00:57.440 --> 01:01.500
And to create a package we are going to use the Ros two command line.

01:01.740 --> 01:01.890
Okay.

01:01.920 --> 01:03.750
I'm going to come back to this a lot.

01:03.780 --> 01:07.890
During this course we're going to explore a lot of different commands you can use with Ros two.

01:07.920 --> 01:10.440
So Ros two and then space.

01:10.440 --> 01:16.290
And we can use the PKG command to create a package with the create keyword.

01:16.290 --> 01:18.210
So Ros two pkg create.

01:18.210 --> 01:20.670
Then we need to give a name for the package.

01:20.670 --> 01:26.640
So for example if your package would be monitoring a temperature sensor it could be a temperature sensor

01:26.640 --> 01:27.330
package.

01:27.330 --> 01:32.100
Here I'm just going to name it my pi pkg.

01:32.100 --> 01:33.690
So my Python package okay.

01:33.720 --> 01:39.690
As a first example for this course, make sure that you use underscores to separate words.

01:39.690 --> 01:44.610
If you want inside the name of the package after the name, you will need to precise.

01:44.610 --> 01:48.540
If the package is a Python package or a C plus plus package for example.

01:48.540 --> 01:52.800
So you can do this with build type okay.

01:52.830 --> 01:53.250
Like this.

01:53.250 --> 01:55.770
So dash dash build dash type.

01:55.770 --> 01:57.180
And you can use Autocompletion.

01:57.180 --> 01:58.380
As you can see it should work.

01:58.410 --> 02:00.300
And then you provide the build type.

02:00.300 --> 02:04.260
And we're going to write element underscore Python.

02:05.040 --> 02:06.420
So what is element.

02:06.450 --> 02:08.700
Element is the build system.

02:08.880 --> 02:10.920
So we have call con that is the build tool.

02:10.920 --> 02:12.600
And element is the build system.

02:12.600 --> 02:15.960
You're going to see quite a few times in different files.

02:15.960 --> 02:21.240
And to say that the package is a Python package you need to write element underscore Python.

02:21.240 --> 02:24.030
And that's pretty much it for the package.

02:24.030 --> 02:26.940
Now what you can do is you can also add dependencies.

02:26.940 --> 02:34.110
So dependencies like this which are basically other packages that this package will depend on.

02:34.110 --> 02:38.640
So of course we will be able to add all the dependencies later directly inside the package, but you

02:38.640 --> 02:42.390
can also provide them already from the start.

02:42.390 --> 02:47.040
So here I'm going to add one rcl py and rcl.

02:47.040 --> 02:49.800
Py is the Python library.

02:49.800 --> 02:53.700
So you can write Python code to use the ros2 features.

02:53.700 --> 03:00.340
So of course if we're going to write Python nodes We want to use the Python ros2 library.

03:00.340 --> 03:03.340
So now that we have all that let's press enter.

03:03.370 --> 03:05.470
That's going to create a package.

03:05.470 --> 03:12.970
You can see we have lots of logs with creating folders, creating files etc. and we also have.

03:12.970 --> 03:14.770
So you might have this warning.

03:14.770 --> 03:17.440
If you have this warning it's really not important.

03:17.440 --> 03:20.620
It's just to say that you don't have a license file.

03:20.620 --> 03:22.930
So having a license file is going to be important.

03:22.930 --> 03:27.880
If you want to publish your code with an open source license somewhere on GitHub, for example, if

03:27.880 --> 03:29.830
you want other people to use, etc..

03:29.830 --> 03:34.570
But for now, for learning and for most projects you will do, you don't really need to publish your

03:34.570 --> 03:37.210
code online, so we don't really need a license.

03:37.210 --> 03:40.300
So you can just ignore completely this warning.

03:40.300 --> 03:42.010
So let's do a clear.

03:42.130 --> 03:47.980
And now if I do ls you see I have my pi pkg.

03:47.980 --> 03:50.050
So that's my new package.

03:50.050 --> 03:51.910
And let's see what we have inside.

03:51.940 --> 03:57.860
To do this I'm going to open Visual Studio Code and to open Visual Studio Code, I recommend that you

03:57.860 --> 03:59.600
always do the following.

03:59.600 --> 04:07.160
So first you navigate inside your source folder here of the roster workspace, not anywhere else.

04:07.160 --> 04:08.480
And then you do code.

04:08.480 --> 04:16.700
That's the command to launch VSCode and then dot to say you want to open VSCode from the source folder.

04:16.700 --> 04:22.310
I recommend you do that because if you open VSCode from different parts every time, that might be a

04:22.310 --> 04:24.830
problem, especially for Autocompletion.

04:24.860 --> 04:31.880
Okay, because VSCode might not find the includes and the imports, etc. so better to open it from the

04:31.880 --> 04:32.810
source folder.

04:32.810 --> 04:33.770
That's what I'm doing here.

04:33.800 --> 04:36.020
Code space dot.

04:40.850 --> 04:41.390
Okay.

04:41.390 --> 04:44.750
And you can see that I have my source folder.

04:44.750 --> 04:47.660
So we have a new VSCode folder.

04:47.660 --> 04:49.160
We're going to come back to this later.

04:49.160 --> 04:51.620
That's just stuff for VSCode.

04:51.620 --> 04:56.250
And then we have well this package that we have created my Python package.

04:56.250 --> 04:57.570
And what do we have inside?

04:57.570 --> 04:59.190
You see, we have quite a lot of stuff.

04:59.190 --> 05:05.010
First of all, you will find another folder that has exactly the same name as the package.

05:05.010 --> 05:09.630
So if your package was named ABC, that folder would be named ABC.

05:09.720 --> 05:13.110
And inside you have an empty init.py.

05:13.140 --> 05:18.240
Okay, so this folder here is where you will write your Python code.

05:18.240 --> 05:19.950
Then we have a resource folder.

05:19.980 --> 05:22.140
Don't really need to worry about that.

05:22.440 --> 05:25.110
A test folder with test stuff.

05:25.110 --> 05:27.720
But also we don't need to worry about that right now.

05:27.720 --> 05:29.490
And then we have three more files.

05:29.490 --> 05:31.560
So we have a package dot XML.

05:31.560 --> 05:36.540
This file is quite important and it's mandatory for any ros2 package okay.

05:36.540 --> 05:37.890
And what do you have inside.

05:37.920 --> 05:43.440
Well as you can see we have stuff like name version description.

05:43.440 --> 05:45.510
You can put a maintenance email or license.

05:45.510 --> 05:50.940
So if you're going to publish your code somewhere on GitHub for example, you will need to fill this

05:50.940 --> 05:52.680
with accurate information.

05:52.700 --> 05:55.580
Then you see we have a depend tag with RCL.

05:55.610 --> 06:03.110
Py so that's because we have provided the CLP dependency in the command line when we created the package.

06:03.110 --> 06:05.240
Now if you want to add more dependencies.

06:05.240 --> 06:11.690
So if this package here that you've created depends on more other packages, you will need to add other

06:11.690 --> 06:12.620
dependency tag.

06:12.620 --> 06:15.500
So one tag per line we have more stuff here.

06:15.500 --> 06:19.760
And in the end you also see the build type here amount Python.

06:19.790 --> 06:20.060
All right.

06:20.090 --> 06:22.790
So that's about it for the package dot XML for now.

06:23.060 --> 06:29.690
And then you have a setup.cfg and setup.py that's going to be used when we want to install the nodes.

06:29.690 --> 06:32.960
We're going to come back to that when we create a node okay.

06:32.990 --> 06:37.190
So that's what you can find in a Python package.

06:37.190 --> 06:38.930
Now let's go back to the terminal.

06:38.930 --> 06:41.510
And we can build this Python package.

06:41.540 --> 06:44.090
Even if it has no node we can build it.

06:44.090 --> 06:48.050
So let's go back to Ros2 workspace okay.

06:48.080 --> 06:51.050
You always go back to this Ros2 workspace.

06:51.050 --> 06:55.750
You don't build inside the source folder you build inside the Ros2 workspace.

06:55.750 --> 07:04.780
Once we are here, we can do a call on build and you can see we have starting my Python package and

07:04.780 --> 07:06.790
then finished my Python package.

07:06.790 --> 07:08.770
So that package has been built.

07:08.770 --> 07:11.080
And I'm just going to show you one option here.

07:11.080 --> 07:16.660
So you can use call build with packages select and you can press tab.

07:16.660 --> 07:23.110
Here you should have the Autocompletion and then my Python package with Autocompletion okay.

07:23.140 --> 07:28.420
So if I do this well you will see the result is going to be the same because we only have one package.

07:28.420 --> 07:31.480
But that option is quite convenient to use.

07:31.480 --> 07:35.410
It's only going to build the packages that you actually select.

07:35.410 --> 07:38.710
So the packages that you write after this option.

07:38.740 --> 07:39.010
All right.

07:39.040 --> 07:43.720
So if you just want to build that package, if you have let's say 12 packages and you just want to build

07:43.720 --> 07:46.660
that one, you can use this option as well.

07:46.690 --> 07:47.080
All right.

07:47.080 --> 07:51.130
And now your Python package is ready to host a Python node.
