- name
- ros2-lifecycle
- description
- Author and debug ROS 2 managed (lifecycle) nodes, lifecycle publishers, ordered bringup, and bond-style managers (Nav2-like). Use when implementing configure/activate/deactivate, inactive topics dropping data, or lifecycle managers.
# ROS 2 Lifecycle (Managed Nodes)
## State machine
`unconfigured → inactive → active → finalized`
Error from any state → `on_error` → typically back to unconfigured.
| Transition | Put here |
|------------|----------|
| `on_configure` | Allocate, declare params, create pubs/subs that should exist while inactive; load plugins |
| `on_activate` | Start processing; activate lifecycle publishers; start bonds |
| `on_deactivate` | Stop commanding; keep allocations; deactivate lifecycle pubs |
| `on_cleanup` | Destroy entities, unload plugins → unconfigured |
| `on_shutdown` | Final teardown |
| `on_error` | Best-effort recover; assume hardware may be wedged |
## Lifecycle publishers
A `LifecyclePublisher` **does not publish while inactive**. Ordinary `create_publisher` **will** — do not mix unless intentional (e.g. diagnostics always on).
## Ordered bringup (Nav2-style)
Activate **dependencies first**: drivers / maps → localization → planning → control → mission. Deactivate **reverse**.
Prefer a **lifecycle manager** (service transitions + optional **bond/heartbeat**) over launch `TimerAction` sleeps. If a bonded node dies, deactivate dependents so controllers stop commanding.
## CLI
```bash
ros2 lifecycle list /node
ros2 lifecycle get /node
ros2 lifecycle set /node configure
ros2 lifecycle set /node activate
ros2 lifecycle set /node deactivate
```
Launch: `LifecycleNode` + `ChangeState` / `OnStateTransition`, or a manager node.
## Failure modes
- Stuck `unconfigured`: `on_configure` FAILURE — params, device open, plugin load.
- Publisher in graph but silence: still **inactive**, or lifecycle pub not activated.
- Crash on activate: work that needed live data done in the wrong transition.
- Double-create across cycles: destroy in `on_cleanup`.
## Tests
configure-fail; activate; deactivate→reactivate (no leak / no double subscribe); shutdown from each state; kill process under bond and assert safe stop.
GitHub에서 보기