Lifecycle nodes — managing nodes through explicit states
Atlasbot · 17/8/2026 · 11 min read
A conventional C++/Python node (rclcpp::Node) that runs logic directly in the — constructor has no standard way of "notifying but not running". With interdependent multiple node systems such as Nav2 (amcl must be ready before planner_server starts to receive commands), this causes asynchronous booting. Lifecycle Node (rclcpp_lifecycle::LifecycleNode) solves this problem with an explicit state machine.
Key concepts
Four main states:
- Unconfigured — created, resource not allocated (no port opened, no config read)
- Inactive — configured (resource allocated) but data not processed — publisher exists but not published, subscriber has not received callback
- Active— fully operational, publisher/subscriber/timer real run
- Finalized— terminal state, freed all resources, no return
Switching between states via transition (configure, activate, deactivate, cleanup, shutdown) — each transition corresponds to a callback you override in the code:
class MotorLifecycleNode : public rclcpp_lifecycle::LifecycleNode {
public:
MotorLifecycleNode() : LifecycleNode("motor_node") {}
CallbackReturn on_configure(const rclcpp_lifecycle::State &) override {
pub_ = create_publisher<std_msgs::msg::Float32>("motor_status", 10);
return CallbackReturn::SUCCESS;
}
CallbackReturn on_activate(const rclcpp_lifecycle::State &) override {
pub_->on_activate(); // publisher only actually publishes after this step
return CallbackReturn::SUCCESS;
}
private:
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<std_msgs::msg::Float32>> pub_;
};
Finally: Core differences from normal nodes: publishers of Lifecycle Node exist as early as
on_configure()but only actually sends data afteron_activate()— allowing external systems to accurately control when the node begins affecting the rest.
How it works
lifecycle_manager— coordinates multiple nodes simultaneously, exactly the mechanism Nav2 uses to ensure map_server is available before amcl is active, amcl is active before planner_server/controller_server starts receiving commands:
ros2 lifecycle set /motor_node configure
ros2 lifecycle set /motor_node activate
ros2 lifecycle get /motor_node # view current state
lifecycle_manager (package nav2_lifecycle_manager) correctly automates this command string for a list of nodes in declared order, instead of you having to manually invoke each ros2 lifecycle set.
Technical details
Parameters
In addition to the four stated "stable" states, the ROS2 lifecycle standard also has transitional short - term states while handling callback:
| Forward Status | When did this happen? |
|---|---|
Configuring | Running on_configure(), before entering Inactive |
Activating | Running on_activate(), before entering Active |
Deactivating | Running on_deactivate(), before returning to Inactive |
CleaningUp | Running on_cleanup(), before returning to Unconfigured |
ErrorProcessing | Callback failed, running on_error() for recovery |
Protocol
The non-internal hidden mechanism — transitions per Lifecycle Node automatically reveal 2 Standard Services: change_state (requires status transfer) and get_state (read current status) — this is exactly the 2 Services that ros2 lifecycle set/get calls below, and also the way lifecycle_manager communicates with each node it manages. Similar to the model seen at Parameter (using the Standard Service get_parameters/set_parameters), lifecycle is another example of ROS2 building high - level features on top of learned service blocks.
Practical applications
Lifecycle Node is particularly suited for a node requiring costly resource allocation — VD: 1 node driver camera preloaded 1 object recognition AI model to GPU memory in on_configure() (may take several seconds), then it is possible to deactivate/activate multiple times very fast (only toggle publication, not model reload) when the system switches between different operating modes — much faster than shutting down and restarting the node from the start (consuming model reload each time).
Practical example
$ ros2 lifecycle set /motor_node configure
Output:
Transitioning successful
$ ros2 lifecycle get /motor_node
Output:
inactive [2]
$ ros2 lifecycle set /motor_node activate
Output:
Transitioning successful
The [2] number next to the status name is the internal code of that status according to the — standard which is useful when reading status processing code in numbers instead of string names.
Common mistakes
- Call
activatebeforeconfigure— state machine invalid transition (cannot jump fromUnconfiguredstraight toActive), rejected with apparent error — always in the correct orderconfigure→activate. - The erroneous
pub_->on_activate()/on_deactivate()statement in the callback— differs from the usualrclcpp::Publisher,LifecyclePublisherdoes not automatically begin publication only because the node has entered the stateActive— The omission of this line causes the publisher to "seem" active (no errors) but not actually send any data. lifecycle_managertimeout when 1 node takes too long to configure— ifon_configure()of 1 node takes longer than the default timeout (e.g., load model AI large),lifecycle_managercan be considered an error even though the node is still processing normally — needs to increase the configurational timeout to match the real-world initialization time.- Failure to implement
on_error()causes configuration error causing crash instead of controlled recovery— if 1 callback returnsFAILUREwithout logic processing aton_error(), the system loses soft recovery, which must restart entire node instead of just retry the error transition.
Conclusion
Lifecycle Node brings explicit control of when 1 node is truly "living" — critical for tight boot order dependent multiple node systems such as Nav2, and for the node that needs to separate the costly resource allocation step from the data processing step. Not all nodes need this complexity — to be used only when detailed life cycle control is really needed. The next article in the column is about the Composition — technique of including multiple nodes in one process to reduce system overhead.
Get new articles and lessons by email
When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.
Unsubscribe any time with the link in each email. See our Privacy policy.