Lifecycle (or Managed, more correctly) nodes are unique to ROS 2. They are nodes that contain state machine transitions or bring-up and teardown of ROS 2 servers. This helps in the deterministic behavior of ROS systems in startup and shutdown. It also helps users structure their programs in reasonable ways for commercial uses and debugging.
When a node is started, it is in the unconfigured state, only processing the node’s constructor which should not contain any ROS networking setup or parameter reading. By the launch system or the supplied lifecycle manager, the nodes need to be transitioned to inactive by configuring. After, it is possible to activate the node by transitioning through the activating stage.
This state will allow the node to process information and be fully set up to run. The configuration stage, triggering the on_configure()
method, will set up all parameters, ROS networking interfaces, and for safety systems, all dynamically allocated memory. The activation stage, triggering the on_activate()
method, will activate the ROS networking interfaces and set any states in the program to start processing information.
To shut down, we transition into deactivating, cleaning up, shutting down, and ending in the finalized state. The networking interfaces are deactivated and stop processing, deallocate memory, and exit cleanly, in those stages, respectively.
The lifecycle node framework is used extensively throughout this project and all servers utilize it. It is the best convention for all ROS systems to use lifecycle nodes if it is possible.
Within Nav2, we use a wrapper of LifecycleNodes, nav2_util LifecycleNode
. This wrapper wraps much of the complexities of LifecycleNodes for typical applications. It also includes a bond
connection for the lifecycle manager to ensure that after a server transitions up, it also remains active. If a server crashes, it lets the lifecycle manager know and transition down the system to prevent a critical failure.
Home Page: NAV 2
Next Page: Behavior Trees