WEBVTT

00:00.050 --> 00:01.280
What are Ros2?

00:01.310 --> 00:02.510
Interfaces.

00:02.540 --> 00:08.900
In the previous sections on topics and services, you have used some common interfaces to communicate

00:08.900 --> 00:11.240
between nodes with topics.

00:11.240 --> 00:17.540
You have seen that all nodes publishing are subscribing to a topic must use the same data type with

00:17.570 --> 00:18.140
services.

00:18.140 --> 00:24.200
You have seen that the client must send a message respecting a certain data type, and the server must

00:24.200 --> 00:29.120
respond with another message, also respecting another data type.

00:29.120 --> 00:37.220
So a topic is defined by two things a name so you can recognize it, and an interface based on a message

00:37.220 --> 00:41.930
definition which is the data structure of the information that you send.

00:42.020 --> 00:49.190
A service is also defined by two things a name so you can recognize it, and an interface or service

00:49.190 --> 00:50.000
definition.

00:50.030 --> 00:56.240
The service definition contains one message definition for the request and one message definition for

00:56.240 --> 00:56.900
the response.

00:56.900 --> 00:58.700
So it's a pair of messages.

00:58.700 --> 01:05.950
And well you can see topics and services as the communication layer tool, and the interfaces or the

01:05.950 --> 01:09.550
messages are the actual content that you send.

01:09.550 --> 01:13.000
Let's just make another very simple real life analogy.

01:13.030 --> 01:17.380
When you send a letter, the transport company will carry your letter.

01:17.410 --> 01:24.640
The content of this letter is the analogy of a raster interface here using a message definition.

01:24.820 --> 01:30.580
When you send a letter and you wait for a response, then the first letter contains a request message,

01:30.580 --> 01:34.990
and the letter that you receive back contains a response message.

01:34.990 --> 01:40.210
And the combination of the two message definitions is the service definition.

01:40.210 --> 01:40.660
All right?

01:40.660 --> 01:45.070
As you can see, message and service definitions are quite useful.

01:45.070 --> 01:50.140
Without them, you would have nothing to send over a topic or a service.

01:50.140 --> 01:56.980
So now, technically speaking, how is it possible that you can use those interfaces directly in your

01:56.980 --> 01:57.520
code?

01:57.520 --> 02:01.300
Because for now it just looks like a bunch of simple text.

02:01.300 --> 02:04.870
Well, let's say that you create a message definition.

02:04.870 --> 02:12.370
When you use the build command line, the message will be passed by the build system, and then a source

02:12.370 --> 02:18.640
code will be generated for this message in any Ros2 supported language C plus plus Python.

02:18.640 --> 02:20.980
But it could also be another language.

02:21.010 --> 02:25.960
Your interface is now ready and that's why you can, for example, include the message header in your

02:25.990 --> 02:33.910
C plus plus code or import the library in Python because the build system generated that file.

02:33.940 --> 02:36.190
Now how to write an interface.

02:36.190 --> 02:42.550
Well, you will be able to use primitive types that we will see in a minute and also include other message

02:42.550 --> 02:43.420
definitions.

02:43.420 --> 02:49.090
And they are already a lot of existing interfaces in for example, those package that we are going to

02:49.120 --> 02:50.470
browse right now.

02:50.770 --> 02:56.620
So what kind of data types can you use to create a message or a service definition?

02:56.620 --> 03:00.280
If you go on the Ros2 interfaces page on the Ros documentation.

03:00.280 --> 03:06.480
So you can just basically type Ros to interfaces, you will get a page like that, and you can see all

03:06.480 --> 03:08.910
the primitive data types that you can use.

03:08.940 --> 03:10.350
It's not really complicated.

03:10.380 --> 03:12.630
Among them you can see for example we have boolean.

03:12.630 --> 03:14.460
So you will need to write bool.

03:14.460 --> 03:16.050
You have integer numbers.

03:16.080 --> 03:22.110
For example with int 64 float numbers it's the same float 64 for example.

03:22.140 --> 03:28.650
Then you can use string etc. and you can also create arrays of those types.

03:28.680 --> 03:30.630
So can you have an example here.

03:31.230 --> 03:34.410
So that's what you're going to write in the message definition.

03:34.410 --> 03:36.450
We're going to create one in the next lesson.

03:36.450 --> 03:39.030
And then how to interact with this in the code.

03:39.030 --> 03:42.540
Well you see you have the simple plus and the Python equivalent.

03:42.540 --> 03:47.760
So if you're going to use for example a string then in Python it's just going to be a normal string.

03:47.760 --> 03:51.120
And in Cplusplus it's going to be an STD string.

03:51.150 --> 03:51.690
Okay.

03:51.690 --> 03:54.120
For most of it is really, really simple.

03:54.120 --> 03:58.050
So those are all the primitive types that you can use.

03:58.050 --> 04:03.120
Now where to find the existing packages, for example the ones that we have used already.

04:03.150 --> 04:05.690
Well you can find most of them on GitHub.

04:05.690 --> 04:09.770
For example, here I am on GitHub with the example interfaces.

04:09.770 --> 04:11.300
So you have the URL here.

04:11.300 --> 04:15.710
But you could also just type ros2 and then example interfaces GitHub.

04:15.710 --> 04:17.510
You will easily find this page.

04:17.840 --> 04:21.560
Same thing I don't necessarily give you URLs because they might change stuff.

04:21.560 --> 04:22.910
They might move stuff around.

04:22.910 --> 04:24.950
So a very simple Google search will do.

04:24.980 --> 04:27.800
Now I am in this example interfaces package.

04:27.800 --> 04:29.750
So that's the code inside the package.

04:29.750 --> 04:31.460
You see we have a cmakelists.txt.

04:31.490 --> 04:33.140
We have a package dot XML.

04:33.140 --> 04:35.510
And then we have for example in MSG.

04:35.510 --> 04:43.160
So in message we have here if I go down we have int 64 dot msg.

04:43.190 --> 04:44.600
That's the one we have used already.

04:44.600 --> 04:48.590
You see that the definition we have seen which contains an int 64.

04:48.590 --> 04:52.100
So that's an integer number with the field data okay.

04:52.130 --> 04:53.990
So that's something we've already seen.

04:54.740 --> 04:56.060
So you can browse around.

04:56.060 --> 04:58.910
You can find different messages and services here.

04:58.910 --> 05:04.370
And let's go to the Common Interfaces repository on GitHub okay.

05:04.400 --> 05:09.620
This one contains actually it's not just one package, it's a collection of packages.

05:09.650 --> 05:11.690
Okay, so each folder is a different package.

05:11.690 --> 05:15.050
Some of them are already installed when you install Ros2.

05:15.080 --> 05:19.220
For example, the geometry messages were already installed for us.

05:19.250 --> 05:24.440
And if you want to install one that's not installed yet, it's very easy.

05:24.470 --> 05:27.740
For example, let's say you want these shape messages.

05:27.740 --> 05:32.720
I don't know if it's installed, but if it's not you're going to do a sudo apt install and then ros

05:32.720 --> 05:38.150
dash the distribution dash and then shape dash msgs okay.

05:38.180 --> 05:42.290
If you have an underscore for the package name, you're going to replace it with a dash.

05:42.290 --> 05:43.910
So it's very easy to install.

05:43.910 --> 05:45.500
Now let's check some of them.

05:45.500 --> 05:47.810
So let's go to sensor messages.

05:47.810 --> 05:50.900
This one is quite useful okay.

05:50.930 --> 05:53.300
And this one for example we go to message.

05:54.110 --> 05:57.350
And there are a lot of stuff okay.

05:57.380 --> 06:00.500
And let's go for example to joint state.

06:02.390 --> 06:04.640
So you see lots of comments.

06:04.640 --> 06:08.230
And you see also that it's a bit bigger.

06:08.230 --> 06:10.240
So what do we have in this message?

06:10.240 --> 06:12.910
You see we have an STD message header.

06:12.910 --> 06:16.030
So that's a message from another package okay.

06:16.060 --> 06:20.350
You can include a message inside a message that's completely possible.

06:20.500 --> 06:26.050
So this one if you go to check that definition of that message inside this package is going to contain

06:26.050 --> 06:27.970
a timestamp and some other stuff.

06:27.970 --> 06:32.740
And then in this one you can see for example we have an array of strings for name.

06:32.740 --> 06:40.210
So basically for each joint of a robot and then three arrays with float numbers for the position, velocity

06:40.210 --> 06:40.870
and effort.

06:40.870 --> 06:45.790
So as an example, let's say you have a robotic arm with 5 or 6 joints.

06:45.790 --> 06:48.520
And you want to publish the state for the joints.

06:48.520 --> 06:54.250
So you read data from the encoders, and then you want to create a message to publish the state with

06:54.250 --> 06:56.770
the position, maybe velocity, maybe effort.

06:56.800 --> 06:59.830
Well, the stuff you compute for all of the joints of your robot.

06:59.830 --> 07:01.570
Then do you need to create a new message?

07:01.570 --> 07:03.430
No, you can just use that one.

07:03.460 --> 07:03.640
Okay.

07:03.670 --> 07:04.750
You just use that one.

07:04.750 --> 07:09.210
And then you fill the different fields here and you just publish with this message.

07:09.240 --> 07:09.540
Okay.

07:09.570 --> 07:13.380
So you can check this sensor message package.

07:13.410 --> 07:15.720
It's quite useful whenever you have a sensor.

07:15.750 --> 07:18.510
You see here we can use Joy for joystick.

07:18.540 --> 07:20.100
You have an IMU.

07:20.130 --> 07:21.510
You have image okay.

07:21.540 --> 07:23.310
Laser scan point cloud.

07:23.310 --> 07:27.150
So it contains a lot of useful things for common sensors.

07:27.150 --> 07:31.890
And of course, well after you've installed this package, the messages are going to be built.

07:31.890 --> 07:34.290
And you can just use them in Python or C plus plus.

07:34.290 --> 07:42.120
Now let's go back to the root of this repository and let's go to geometry Messages.

07:43.260 --> 07:46.770
And in geometry messages we also have an MSG folder.

07:47.220 --> 07:50.010
And you see so we have a lot of stuff.

07:50.010 --> 07:52.830
And one that we've used here is twist.

07:53.610 --> 07:55.110
And you can see the twist.

07:55.110 --> 07:56.760
So we have a comment.

07:56.760 --> 08:00.540
And then we have vector three linear and vector three angular.

08:00.540 --> 08:01.860
And what is vector three.

08:01.860 --> 08:07.920
So here we don't see a package name in front because we are using a message from that same package.

08:08.040 --> 08:12.950
So if we go back to the message here and we find vector three.

08:12.980 --> 08:14.000
It's here.

08:14.780 --> 08:21.440
You see that vector three contains three primitive data types, which are each a float number with x,

08:21.440 --> 08:22.250
y, and z.

08:22.280 --> 08:22.580
Okay.

08:22.610 --> 08:25.970
So if we come back to the twist.

08:27.800 --> 08:33.260
So you see we have linear x, y and z and angular x, y and z.

08:33.260 --> 08:37.130
And usually this one as you can see it's used for velocity.

08:37.130 --> 08:42.050
And so the twist message is used with the turtle sim simulation that we've used.

08:42.050 --> 08:47.750
But also if you're going to use for example, robots like Turtlebot or basically any mobile robot,

08:47.780 --> 08:50.390
you will use this twist message.

08:50.570 --> 08:51.530
It's very useful.

08:51.560 --> 08:51.890
Okay.

08:51.920 --> 08:57.530
And you can see here combination of several messages inside one message.

08:57.530 --> 09:03.080
And then to finish let's go back here and let's go to standard.

09:03.080 --> 09:06.200
So STD solves standard services.

09:06.320 --> 09:13.760
You see we have service folder and we have used the set bull previously.

09:13.790 --> 09:15.740
You can find set bull is here.

09:15.770 --> 09:20.870
Of course, we have the three dashes to separate the request from the response.

09:20.900 --> 09:21.200
Okay.

09:21.230 --> 09:26.870
And as you can see, this is exactly what we saw in the terminal when we did Ros2 interface show.

09:26.870 --> 09:29.330
And so we have also primitive data types.

09:29.330 --> 09:31.250
If you want you could also include messages.

09:31.250 --> 09:34.010
So you cannot include a service inside the service.

09:34.040 --> 09:34.190
Okay.

09:34.220 --> 09:37.010
It's very important you just include messages.

09:37.010 --> 09:41.900
So any message you create for a topic you can use it for topics, but you can also include it inside

09:41.900 --> 09:43.670
a service definition.

09:43.700 --> 09:44.060
Okay.

09:44.090 --> 09:47.750
You could have a vector three here as a request.

09:47.780 --> 09:48.050
Okay.

09:48.080 --> 09:51.320
So you can include messages inside services.

09:51.320 --> 09:53.660
But you cannot include services inside services.

09:53.660 --> 09:54.800
And well that's about it.

09:54.800 --> 10:00.680
Now we're going to practice of course and see how to create all that by ourselves with our own packages

10:00.680 --> 10:01.880
inside the workspace.

10:01.880 --> 10:07.430
So what you've seen for now is a bit more about what Ros2 interfaces are, how to create them with message

10:07.430 --> 10:08.570
and service definitions.

10:08.570 --> 10:13.220
And you've also discovered some of the most common existing interfaces.
