# Lifecycle

A lifecycle defines the operational boundaries of a mode, from its activation to its completion or transition to another mode. It is responsible for initializing, managing, and safely terminating a mode’s operation, ensuring predictable transitions, consistent state handling, and controlled execution of mode-specific logic. A mode represents a functional state of the robot, such as Guard, SLAM, or Navigation, and each mode runs within a lifecycle that determines how and when it starts, executes, and ends.

![](https://2120135774-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ft8vMsruGqqhYpVx9qhd5%2Fuploads%2Fgit-blob-504979dedd445aaa901da518a4cd55b4c006f301%2Flifecycle.png?alt=media)

Conceptual Model

* Lifecycle – Defines the start, execution, and end of a mode.
* Stage – Represents a logical phase within the lifecycle (e.g., startup, entry, active, exit).
* Hook – A programmable event point that executes specific actions at key stages.
* Mode – The operational context governed by the lifecycle.

In short: Lifecycle controls the flow → Stages define phases → Hooks perform actions → Mode defines behavior.

### Stages and Hooks

* Each lifecycle is composed of several stages.
* Hooks are executed at specific points in these stages to perform initialization, cleanup, or handling tasks.

Stages and associated hooks:

#### Startup Stage

Triggered by ON\_STARTUP

Executes system-level initialization before any mode begins.

#### Entry Stage

Triggered by ON\_ENTRY

Runs when entering a mode; prepares mode-specific resources and context.

#### Active Stage

Represents the main operational phase of the mode.

No fixed hook; mode logic runs continuously during this stage.

#### Exit Stage

Triggered by ON\_EXIT

Executes cleanup, saves state, and prepares for the next transition.

#### Timeout Stage

Triggered by ON\_TIMEOUT

Handles cases where a mode exceeds its defined duration or fails to complete expected actions.

#### Shutdown Stage

Triggered by ON\_SHUTDOWN

Performs final cleanup and safe termination of the lifecycle management system.
