State Machine

The state machine library provides a generic interface for initializing, updating, and querying the flight state. As almost everything else in AURORA, it features a dynamic selection of state machine types via Kconfig CONFIG_AURORA_STATE_MACHINE_TYPE. Currently only the simple state machine is implemented and it uses the following flight sequence:

Simple State Machine

The simple state machine implementation defines a 9-state flight sequence driven by sensor thresholds.

states
Signals

Signal

Comment

ARM

ARM signal from extern. Arms the pyro channels as well

DISARM

DISARM signal from extern. Disarms the pyro channels as well

Sensor Readings

Sensor Reading

Comment

TAB

Acceleration needed to go from ARMED to BOOST

TH

Altitude needed to go from ARMED to BOOST

TBB

Acceleration needed to go from BOOST to BURNOUT

TM

Altitude needed to go from APOGEE to MAIN

TL

Velocity needed to signal LANDED

Timers

Timer

Comment

DTAB

Time that T_AB and T_H shall be asserted for

DTL

Time that T_L shall be asserted

Timeouts

Timeout

Comment

TOA

Timeout for APOGEE state

TOR

Timeout for REDUNDANT state

State transitions are also driven by sensor thresholds configured via Kconfig (boost acceleration, main descent height, apogee timeout, etc.).

Shell Commands

Enabling CONFIG_AURORA_STATE_MACHINE_SHELL registers the state_machine command group. Audit-log commands are only available when CONFIG_AURORA_STATE_MACHINE_AUDIT is also enabled.

Command

Description

state_machine status

Print the active state-machine implementation and its current state.

state_machine transition <STATE>

Force a transition. The state name completes via tab. Because the state machine exposes no arbitrary setter, this deinitializes and reinitializes the machine, landing it in IDLE; a warning is printed when the requested target is not IDLE. Ground testing only.

state_machine audit

Dump the audit log (timestamped transitions and events). Requires CONFIG_AURORA_STATE_MACHINE_AUDIT.

state_machine audit_clear

Clear the audit log. Requires CONFIG_AURORA_STATE_MACHINE_AUDIT.

Valid state names for transition are IDLE, ARMED, BOOST, BURNOUT, APOGEE, MAIN, REDUNDANT, LANDED and ERROR.

Warning

state_machine transition bypasses normal flight logic and resets the machine. Do not use in flight.

API Reference

typedef int (*sm_error_cb_t)(void *args)

Callback invoked when the state machine encounters an error.

The implementation can define specific recovery logic.

Param args:

Pointer to an implementation-specific config structure.

Return:

0 if the error was mitigated, negative errno otherwise.

const char *sm_state_str(enum sm_state state)

Return a human-readable name for the given state.

Parameters:

state – State value.

Returns:

Pointer to a static string, or “UNKNOWN” if invalid.

void sm_init(const struct sm_thresholds *cfg, struct sm_error_handling_args *err_hdl)

Initialize the rocket state machine.

This function prepares the state machine, loads the threshold configuration, initializes internal timers, and sets the initial state to SM_IDLE.

Parameters:
  • cfg – Pointer to a threshold configuration structure.

  • err_hdl – Pointer to an error handling configuration (callback + args), or NULL.

void sm_deinit(void)

Deinitialize the rocket state machine.

This function resets the state machine, unloads the threshold configuration, stops internal timers, and sets the initial state.

void sm_update(const struct sm_inputs *inputs)

Update the state machine using current sensor readings.

Function evaluates sensor data and executes state transitions according to the flight logic diagram. Must be called regularly (e.g. at sensor update rate).

Parameters:

inputs – Pointer to populated sensor readings.

enum sm_state sm_get_state(void)

Retrieve the current state of the state machine.

Returns:

Current state (usually an enum implementation in state implementation).

void sm_get_inputs(struct sm_inputs *out)

Retrieve the most recent inputs the state machine evaluated.

When CONFIG_FILTER is enabled, altitude and velocity are the Kalman-filtered values; the remaining fields are passed through from the last sm_update() call. When CONFIG_FILTER is disabled, all fields are the raw sm_update() inputs (and velocity is whatever the caller set, typically 0).

Before the first sm_update() call the returned struct is zeroed.

Parameters:

out – Destination struct, must be non-NULL.

struct sm_thresholds
#include <simple.h>

Threshold configuration for the rocket state machine.

Defines thresholds for state transitions based on orientation, altitude, acceleration, and timing.

struct sm_inputs
#include <simple.h>

Sensor input structure for the state machine.

These values must be filled each update cycle to evaluate state transitions.

struct sm_error_handling_args
#include <state.h>

Error handling configuration for the state machine.