Along with the life cycle nodes.
Roscoe also offers a command line interface to manage these type of nodes to view their state and to
view their available transition while in the current state, and also to activate certain transitions
that change the life cycle nodes state.
To see how all of this works and how we can use this interface.
Let's start the lifecycle nodes that we create in the previous lesson.
So let's open a new terminal.
Let's go to the workspace and let's source it.
And now let's run like a normal node from the Arduino boot CP Examples package.
The life cycle Node.
So the one that we called Simple Life Cycle Node and let's press enter.
At the startup.
This node does nothing and just initialize the life cycle node.
And so we can confirm this.
If we open a new terminal and here we can start interacting with the command line of Ros to which the
life cycle nodes with the command ros2 life cycle.
And then let's use the nodes command to have a list of all the life cycle nodes that are currently available
in Ros two.
And we can see that among these there is only one node.
And so this is the simple life cycle node that we have just created and started.
Now, of course it will be in the Unconfigured state since we just started it and we can verify.
So by using the command ros2 lifecycle, get followed by the name of the node, which is the simple
lifecycle node.
So let's press enter.
And actually we can see that as we were expecting this node.
So this lifecycle node is in the Unconfigured state.
And furthermore, we also know that while the node is in this state, so in the Unconfigured state,
the node has not yet subscribed to any topic.
And indeed if we use the command Ros2 topic list, we can see that the topic chapter is not here in
the Unconfigured state.
So while the node is in this state, there are only two active transitions.
The configure transition, which would bring the state machine to the inactive state and the shutdown
transition, which instead would bring the state machine into the finalized state.
We can confirm this, so we can confirm that the only two available transition are the configure and
the shutdown by using the command ros2 lifecycle.
List.
And then we want the list of the transition active on the Simple Life Cycle node.
So let's press enter.
And indeed, we can confirm that in the current state there is available only the configured transition
and the shutdown transition.
So only these two transitions.
Let's activate, for example, the configure transition.
So the first one with the command Ros2 life cycle set, then the name of the node, which is the simple
life cycle node.
And then here let's activate the configure transition.
So let's type, configure.
So let's press enter.
We also get the output of the terminal that says that the transition ended successfully.
And also we can see that here in the terminal where we launched the Simple Life Cycle node, we get
notified that the on configure function has been called has been executed.
And also we can double check it by using again the command Ros2 life cycle get and let's get the status
of the simple life cycle node.
And now it is in the inactive state as we were expecting.
In this state.
The node has already created the subscription to the chatter topic.
And so if we open a new terminal and we launch the Ros2 topic list command, now we can see that the
chatter topic appears.
So this one since the node is in the inactive state and in this state is where the subscriber is created.
Anyway, if we try to publish a new message within this topic, so we trust to topic publish within
the chatter topic.
So here there are accepted messages of type string.
Then let's use a double quote and then let's for example, print the message I So if we press enter
now, basically this terminal is publishing repeatedly the message I and also if it is continuously
publishing this message to the chatter topic, we see that nothing happens in this simple lifecycle
node.
So nothing happens because the simple lifecycle node is in the inactive state.
And while in this state it is not receiving any message from the subscription, in order to do so,
it must be in the active state.
So to move this one to the active state, so the lifecycle node to the active state, we need to use
the command Ros2 lifecycle list.
And so the simple lifecycle node.
Now we can see that while in the inactive state there are only three transitions available.
The clean up, then the activate and then the shut down.
Let's change the status of the node.
So let's activate it with the command Ros2 life cycle set.
And so let's set the status of the simple cycle node.
So let's.
Use the activate transition.
So let's press enter.
And then now we can see that two things start to happen.
The first is that the on activate function is being called, and the second is that we are starting
receiving the messages that here in this terminal we are still publishing within the chatter topic.
And so finally it is in the active state and starts receiving the messages.
Again while in this state.
So while in the active state, let's see which are the transition that are available for our state machine
with the Ros life cycle.
List and then the name of the node.
And now we can see that while in the active state, there are only two transitions the deactivate and
the shut down.
For example, let's trigger the first one.
So the deactivate transaction with the Ros two lifecycle set.
And on the simple lifecycle node, let's set the transition, the activate.
So let's press enter.
And we can see that here.
We get notified that the on deactivate function has been called.
And also we can see that no more messages are printed in the terminal.
So we are not receiving any more messages from the chatter topic.
And as soon as we start it again.
So if we again move the state machine to the state active with the Activate transaction.
The flow of messages starts again.
And so the subscriber starts again to listen and to print messages in the terminal.