2.7 KiB
Also known as managed Nodes in ROS2. The ROS2 - NAV2 Library library makes good use of it. From ROS2 Design:
A managed life cycle for nodes allows greater control over the state of ROS system. It will allow roslaunch to ensure that all components have been instantiated correctly before it allows any component to begin executing its behaviour. It will also allow nodes to be restarted or replaced on-line.
The most important concept of this document is that a managed node presents a known interface, executes according to a known life cycle state machine, and otherwise can be considered a black box. This allows freedom to the node developer on how they provide the managed life cycle functionality, while also ensuring that any tools created for managing nodes can work with any compliant node.
There are 4 primary states: unconfigured, inactive, active, finalized There are 7 transitions: create, configure, cleanup, activate, deactivate, shutdown and destroy
States
All nodes start with the unconfigured state, which is kind of like an empty state where everything starts but it might also end there More important is the inactive state. its purpose is to breath life into a node. It allows the user to read parameters, add subscriptions and publications and (re)configure it such that it can fulfill its job. This is done while the node is not running. While a node is in this state it will not receive any data from other processes.
Transition Callbacks
The main functions to implement for a custom node in the lifecycle scheme are:
onConfigure()
Here the things are implemented that are executed only once in the Node's lifetime, such as obtaining permanent memory buffers and setting up topic publications/subscriptions that do not change.
onCleanup()
This is the transition function that is called when a Node is being taken out of service (essentially the oposite of onConfigure(). Essentially it leaves the node without a state, such that there is no difference between a node that got cleaned up and another that was just created.
onActivate()
This callback is responsible to implement any final preparations before the node is executing its main purpose. Examples are acquiring resources needed for execution such as access to hardware (it should return fast without a lengthy hardware startup).
onDeactivate()
This callback should undo anything that onActivate() did.
Management Interface
This is a common interface to allow a managing node to manage the different lifecycle nodes accordingly.
Managing Node
This is the node that loads the different lifecycle nodes and is responsible to bring them from one state into the next and handle any error they feed back.