WEBVTT

00:00.350 --> 00:02.390
Along with the life cycle nodes.

00:02.420 --> 00:09.890
Roscoe also offers a command line interface to manage these type of nodes to view their state and to

00:09.890 --> 00:15.950
view their available transition while in the current state, and also to activate certain transitions

00:15.980 --> 00:18.650
that change the life cycle nodes state.

00:19.340 --> 00:22.980
To see how all of this works and how we can use this interface.

00:23.000 --> 00:26.810
Let's start the lifecycle nodes that we create in the previous lesson.

00:26.990 --> 00:28.850
So let's open a new terminal.

00:29.750 --> 00:33.470
Let's go to the workspace and let's source it.

00:35.030 --> 00:46.340
And now let's run like a normal node from the Arduino boot CP Examples package.

00:46.370 --> 00:47.950
The life cycle Node.

00:47.960 --> 00:54.560
So the one that we called Simple Life Cycle Node and let's press enter.

00:55.280 --> 00:56.180
At the startup.

00:56.180 --> 01:00.410
This node does nothing and just initialize the life cycle node.

01:00.560 --> 01:02.300
And so we can confirm this.

01:02.330 --> 01:09.140
If we open a new terminal and here we can start interacting with the command line of Ros to which the

01:09.140 --> 01:14.950
life cycle nodes with the command ros2 life cycle.

01:15.650 --> 01:21.770
And then let's use the nodes command to have a list of all the life cycle nodes that are currently available

01:21.770 --> 01:22.400
in Ros two.

01:22.490 --> 01:25.750
And we can see that among these there is only one node.

01:25.760 --> 01:30.470
And so this is the simple life cycle node that we have just created and started.

01:31.090 --> 01:37.440
Now, of course it will be in the Unconfigured state since we just started it and we can verify.

01:37.450 --> 01:47.920
So by using the command ros2 lifecycle, get followed by the name of the node, which is the simple

01:47.920 --> 01:49.070
lifecycle node.

01:49.090 --> 01:51.070
So let's press enter.

01:51.070 --> 01:54.910
And actually we can see that as we were expecting this node.

01:54.910 --> 01:58.780
So this lifecycle node is in the Unconfigured state.

01:58.900 --> 02:04.630
And furthermore, we also know that while the node is in this state, so in the Unconfigured state,

02:04.660 --> 02:08.140
the node has not yet subscribed to any topic.

02:08.230 --> 02:17.830
And indeed if we use the command Ros2 topic list, we can see that the topic chapter is not here in

02:17.830 --> 02:19.450
the Unconfigured state.

02:19.450 --> 02:25.330
So while the node is in this state, there are only two active transitions.

02:25.360 --> 02:31.940
The configure transition, which would bring the state machine to the inactive state and the shutdown

02:31.940 --> 02:36.710
transition, which instead would bring the state machine into the finalized state.

02:37.010 --> 02:42.980
We can confirm this, so we can confirm that the only two available transition are the configure and

02:42.980 --> 02:49.040
the shutdown by using the command ros2 lifecycle.

02:49.940 --> 02:50.570
List.

02:51.140 --> 02:56.660
And then we want the list of the transition active on the Simple Life Cycle node.

02:56.720 --> 02:58.460
So let's press enter.

02:58.610 --> 03:05.210
And indeed, we can confirm that in the current state there is available only the configured transition

03:05.210 --> 03:07.190
and the shutdown transition.

03:07.190 --> 03:09.140
So only these two transitions.

03:09.650 --> 03:12.890
Let's activate, for example, the configure transition.

03:12.890 --> 03:23.270
So the first one with the command Ros2 life cycle set, then the name of the node, which is the simple

03:23.270 --> 03:24.280
life cycle node.

03:24.290 --> 03:29.780
And then here let's activate the configure transition.

03:29.780 --> 03:31.670
So let's type, configure.

03:31.940 --> 03:33.530
So let's press enter.

03:33.560 --> 03:39.860
We also get the output of the terminal that says that the transition ended successfully.

03:39.980 --> 03:45.770
And also we can see that here in the terminal where we launched the Simple Life Cycle node, we get

03:45.770 --> 03:51.120
notified that the on configure function has been called has been executed.

03:51.210 --> 04:01.380
And also we can double check it by using again the command Ros2 life cycle get and let's get the status

04:01.380 --> 04:03.060
of the simple life cycle node.

04:03.540 --> 04:08.160
And now it is in the inactive state as we were expecting.

04:08.870 --> 04:09.710
In this state.

04:09.710 --> 04:13.640
The node has already created the subscription to the chatter topic.

04:13.820 --> 04:22.880
And so if we open a new terminal and we launch the Ros2 topic list command, now we can see that the

04:22.880 --> 04:24.320
chatter topic appears.

04:24.320 --> 04:32.180
So this one since the node is in the inactive state and in this state is where the subscriber is created.

04:32.600 --> 04:41.360
Anyway, if we try to publish a new message within this topic, so we trust to topic publish within

04:41.360 --> 04:42.440
the chatter topic.

04:42.440 --> 04:46.730
So here there are accepted messages of type string.

04:47.210 --> 04:55.100
Then let's use a double quote and then let's for example, print the message I So if we press enter

04:55.130 --> 05:02.450
now, basically this terminal is publishing repeatedly the message I and also if it is continuously

05:02.450 --> 05:08.060
publishing this message to the chatter topic, we see that nothing happens in this simple lifecycle

05:08.060 --> 05:08.610
node.

05:08.610 --> 05:13.080
So nothing happens because the simple lifecycle node is in the inactive state.

05:13.080 --> 05:19.920
And while in this state it is not receiving any message from the subscription, in order to do so,

05:19.920 --> 05:22.080
it must be in the active state.

05:22.530 --> 05:28.320
So to move this one to the active state, so the lifecycle node to the active state, we need to use

05:28.320 --> 05:33.450
the command Ros2 lifecycle list.

05:34.740 --> 05:36.510
And so the simple lifecycle node.

05:37.470 --> 05:43.680
Now we can see that while in the inactive state there are only three transitions available.

05:43.710 --> 05:48.190
The clean up, then the activate and then the shut down.

05:48.210 --> 05:50.400
Let's change the status of the node.

05:50.400 --> 05:57.090
So let's activate it with the command Ros2 life cycle set.

05:57.240 --> 06:00.060
And so let's set the status of the simple cycle node.

06:00.060 --> 06:01.020
So let's.

06:03.310 --> 06:06.730
Use the activate transition.

06:06.730 --> 06:08.320
So let's press enter.

06:09.710 --> 06:12.950
And then now we can see that two things start to happen.

06:12.980 --> 06:19.190
The first is that the on activate function is being called, and the second is that we are starting

06:19.190 --> 06:25.730
receiving the messages that here in this terminal we are still publishing within the chatter topic.

06:25.850 --> 06:30.920
And so finally it is in the active state and starts receiving the messages.

06:31.950 --> 06:33.740
Again while in this state.

06:33.750 --> 06:39.990
So while in the active state, let's see which are the transition that are available for our state machine

06:39.990 --> 06:44.370
with the Ros life cycle.

06:45.920 --> 06:48.920
List and then the name of the node.

06:49.310 --> 06:56.060
And now we can see that while in the active state, there are only two transitions the deactivate and

06:56.060 --> 06:57.230
the shut down.

06:57.740 --> 07:00.380
For example, let's trigger the first one.

07:00.380 --> 07:08.120
So the deactivate transaction with the Ros two lifecycle set.

07:08.990 --> 07:15.090
And on the simple lifecycle node, let's set the transition, the activate.

07:15.110 --> 07:16.880
So let's press enter.

07:17.000 --> 07:18.440
And we can see that here.

07:18.440 --> 07:21.950
We get notified that the on deactivate function has been called.

07:21.950 --> 07:26.240
And also we can see that no more messages are printed in the terminal.

07:26.240 --> 07:30.560
So we are not receiving any more messages from the chatter topic.

07:30.560 --> 07:33.640
And as soon as we start it again.

07:33.650 --> 07:41.120
So if we again move the state machine to the state active with the Activate transaction.

07:42.490 --> 07:44.530
The flow of messages starts again.

07:44.530 --> 07:49.600
And so the subscriber starts again to listen and to print messages in the terminal.
