WEBVTT

00:00.110 --> 00:02.300
What is a ros2 node?

00:02.330 --> 00:08.360
A node is a subpart of your application that you will code, for example, with Python or C plus plus.

00:08.390 --> 00:10.460
A node should have a single purpose.

00:10.460 --> 00:16.460
Your application will contain many nodes which will be put into packages, and nodes will then communicate

00:16.460 --> 00:17.210
with each other.

00:17.210 --> 00:22.670
But let's just see with a real life example, I will show you a simplified example so you can easily

00:22.670 --> 00:26.150
understand what a node is and why it is useful.

00:26.150 --> 00:30.410
So let's go back to the previous slide where I explained to you what packages were.

00:30.440 --> 00:34.370
A package is an independent unit inside your application.

00:34.370 --> 00:37.520
Now a package which is empty will not do anything.

00:37.520 --> 00:40.760
So we will create nodes inside the packages.

00:40.760 --> 00:43.160
Let's start with the camera package.

00:43.160 --> 00:46.700
This package will handle a camera as an independent unit.

00:46.700 --> 00:48.830
So what should we put inside?

00:48.830 --> 00:54.200
First we need a driver for the camera to be able to program it and get frames from it.

00:54.230 --> 00:59.510
We also need a program that will take those frames and do some image processing work.

00:59.510 --> 01:05.530
We could also add any other program related to the camera that we are using all those programs in blue

01:05.560 --> 01:06.850
are nodes.

01:06.880 --> 01:09.400
Each node can be launched separately.

01:09.400 --> 01:13.840
So first we will launch the driver and then the image processing node.

01:13.870 --> 01:19.900
Now the nodes will communicate between each other using Ros to communication functionalities which we

01:19.900 --> 01:21.460
will see later in this course.

01:21.490 --> 01:22.000
All right.

01:22.000 --> 01:26.080
We have our camera package filled with all the nodes that we need.

01:26.110 --> 01:31.420
Note that sometimes it can be quite hard to know if you should put two nodes in the same package.

01:31.420 --> 01:37.930
For example, the image processing node could be part of another package which only handles image processing

01:37.930 --> 01:39.700
for any camera.

01:39.730 --> 01:45.790
We could then add many other processing nodes, and this new package would communicate with any other

01:45.790 --> 01:48.760
camera package, which includes a driver.

01:48.760 --> 01:54.640
But for this example, let's just say that the image processing is specific to the camera we are talking

01:54.640 --> 02:00.100
about, and both driver and image processing are using some common dependencies.

02:00.100 --> 02:02.770
We have two other packages in our application.

02:02.770 --> 02:05.560
Let's check the motion planning package.

02:05.560 --> 02:11.400
So in this package you can expect to have a motion planning node, which will compute motion planning

02:11.400 --> 02:12.510
for a robot.

02:12.540 --> 02:19.950
We can also add a path correction node whose role is to modify the motion planning due to external factors.

02:19.950 --> 02:20.730
So great!

02:20.730 --> 02:23.370
We have two packages filled with nodes.

02:23.370 --> 02:29.340
What we can do now is to make two nodes inside different packages communicate together.

02:29.340 --> 02:33.480
We link the image processing node to the path correction node.

02:33.480 --> 02:39.690
The image processing node will analyze frames coming from the camera, and will send an analysis of

02:39.690 --> 02:42.690
the environment to the path correction node.

02:42.690 --> 02:46.380
This node will then be able to notify the motion planning node.

02:46.380 --> 02:50.730
And we finished with our third package which is the hardware control.

02:50.730 --> 02:57.630
This package has an independent unit will control the hardware of the robot that can be wheels, robotic

02:57.630 --> 02:59.910
arm joints, or anything else.

03:00.300 --> 03:05.010
In this package, we will find some drivers to control the motors with a control loop.

03:05.010 --> 03:10.260
And let's say that the position feedback, which is coming back from the motor encoders, is also sent

03:10.260 --> 03:15.300
back to the control loop for precise control and published by a state publisher node.

03:15.300 --> 03:21.810
So we have two nodes in this package, and now the motion planning node from the motion planning package

03:21.810 --> 03:29.670
will send computed trajectories to the driver inside the hardware control package to complete the architecture.

03:29.700 --> 03:35.160
Let's say that the hardware status of the robot is published, and both the motion planning and path

03:35.160 --> 03:37.920
correction nodes are getting those messages.

03:37.920 --> 03:43.110
Well, that's maybe quite complicated for you to get everything right now, but I think you have a better

03:43.110 --> 03:46.440
idea of what a node is and how they are used.

03:46.470 --> 03:50.280
Feel free to come back to this lesson after you make some progress in this course.

03:50.280 --> 03:52.020
You will understand more things.

03:52.050 --> 03:54.930
And so you've seen the big picture with a real life example.

03:54.930 --> 03:57.840
Now let's go back to the node definition.

03:57.870 --> 04:03.420
A node is a subprogram of your application which is responsible for one thing.

04:03.420 --> 04:09.030
Just as when you write a class with object oriented programming, you know that the class only serves

04:09.030 --> 04:10.410
a single purpose.

04:10.410 --> 04:15.320
Well, if you have two different functionalities to implement, you will have two different classes

04:15.320 --> 04:17.060
that's similar for nodes.

04:17.090 --> 04:23.930
Nodes are combined into a graph and communicate between each other using for example, topics, services,

04:23.930 --> 04:28.430
parameters, etc. we will cover the communication tools in the next sections.

04:28.460 --> 04:32.210
Now what are the characteristics and benefits of nodes?

04:32.240 --> 04:35.390
First, they help you reduce code complexity.

04:35.630 --> 04:40.850
If you correctly separate your application into packages and nodes, then it will be much easier for

04:40.850 --> 04:42.530
you to scale your application.

04:42.560 --> 04:43.640
Believe me on that.

04:43.640 --> 04:49.520
If you write everything into one big block of code, then after some time you will spend more time fixing

04:49.520 --> 04:52.670
your code than actually developing new functionalities.

04:52.700 --> 04:55.700
Nodes also provide great fault tolerance.

04:55.700 --> 05:01.250
If you run your nodes in different processes, then they are not directly linked and they can still

05:01.250 --> 05:04.520
continue to communicate thanks to Ross two communications.

05:04.520 --> 05:08.840
If one node crashes, it will not make the other nodes crash first.

05:08.870 --> 05:10.220
That's great for debugging.

05:10.220 --> 05:15.230
And second, that's great if you have, let's say, a critical node running your hardware that is well

05:15.260 --> 05:19.520
tested and you just add another node in your program that you want to test.

05:19.550 --> 05:24.770
Even if this later node can crash, it will not affect the critical hardware node.

05:24.770 --> 05:27.890
And then Ros2 is language agnostic.

05:27.890 --> 05:34.820
It means that you can write one node in Python, another node in Cplusplus, and both nodes can communicate

05:34.820 --> 05:36.710
without any problem.

05:36.740 --> 05:42.500
Python and Cplusplus are the two most common languages for Ros, and with some other libraries you can

05:42.500 --> 05:44.480
also use other languages.

05:44.480 --> 05:46.700
This characteristic is really great.

05:46.700 --> 05:52.070
For example, you can choose to develop most of your application in Python, while some nodes will be

05:52.070 --> 05:56.090
written in Cplusplus because they need fast execution speed.

05:56.090 --> 05:58.850
And just a quick note, and we're going to come back to this later.

05:58.880 --> 06:01.400
Two nodes cannot have the same name.

06:01.400 --> 06:06.770
If you want to run multiple instances of the same node, you will have to change their name or add them

06:06.770 --> 06:08.870
into a different namespace for example.

06:08.900 --> 06:09.410
All right.

06:09.410 --> 06:15.440
So in the next lessons we will see how to actually create nodes in both Python and C plus.

06:15.440 --> 06:21.440
Plus how to use them with command line tools and then how to make them communicate between each other.
