Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
BaseStateMachine Class Referenceabstract

Base class for flight state machines driven by IMU/altimeter data. More...

#include <BaseStateMachine.h>

Inheritance diagram for BaseStateMachine:
Inheritance graph
Collaboration diagram for BaseStateMachine:
Collaboration graph

Public Types

using StateEntryCallback = void (*)()

Public Member Functions

 BaseStateMachine (FlightState initialState=STATE_UNARMED)
virtual ~BaseStateMachine ()=default
virtual int update (const AccelerationTriplet &accel, const DataPoint &alt)=0
 Advance the state machine with the latest measurements.
virtual uint8_t getState () const
 Current discrete state identifier.
bool registerOnStateEntry (FlightState targetState, StateEntryCallback functionPtr)
 Register a callback to invoke each time a target state is entered.

Static Public Member Functions

static constexpr std::size_t getMaxStateEntryCallbacks ()

Static Public Attributes

static constexpr std::size_t kMaxStateEntryCallbacks = 32

Protected Member Functions

bool changeState (FlightState newState)
 Transition to a new state and trigger registered on-entry callbacks.
FlightState getFlightState () const
 Current state as FlightState enum.

Detailed Description

Base class for flight state machines driven by IMU/altimeter data.

Note
When to use: derive a concrete state machine to map sensor inputs to discrete flight phases without changing call sites. This class owns current-state tracking plus on-entry callback dispatch with no dynamic memory allocation.

Definition at line 19 of file BaseStateMachine.h.

Member Typedef Documentation

◆ StateEntryCallback

Definition at line 22 of file BaseStateMachine.h.

Constructor & Destructor Documentation

◆ BaseStateMachine()

BaseStateMachine::BaseStateMachine ( FlightState initialState = STATE_UNARMED)
explicit

Definition at line 3 of file BaseStateMachine.cpp.

◆ ~BaseStateMachine()

virtual BaseStateMachine::~BaseStateMachine ( )
virtualdefault

Member Function Documentation

◆ changeState()

bool BaseStateMachine::changeState ( FlightState newState)
protected

Transition to a new state and trigger registered on-entry callbacks.

Parameters
newStateState to transition into.
Returns
true if state changed, false if already in newState.

Definition at line 33 of file BaseStateMachine.cpp.

◆ getFlightState()

FlightState BaseStateMachine::getFlightState ( ) const
protected

Current state as FlightState enum.

Definition at line 51 of file BaseStateMachine.cpp.

◆ getMaxStateEntryCallbacks()

constexpr std::size_t BaseStateMachine::getMaxStateEntryCallbacks ( )
inlinestaticconstexpr

Definition at line 54 of file BaseStateMachine.h.

◆ getState()

uint8_t BaseStateMachine::getState ( ) const
virtual

Current discrete state identifier.

Note
When to use: downstream logic (ejection, logging, UI) queries this to decide actions.

Definition at line 5 of file BaseStateMachine.cpp.

◆ registerOnStateEntry()

bool BaseStateMachine::registerOnStateEntry ( FlightState targetState,
StateEntryCallback functionPtr )

Register a callback to invoke each time a target state is entered.

Parameters
targetStateThe state that triggers the callback.
functionPtrFunction to call when entering targetState.
Returns
true if callback was registered, false for nullptr, duplicate, or full callback buffer.

Definition at line 9 of file BaseStateMachine.cpp.

◆ update()

virtual int BaseStateMachine::update ( const AccelerationTriplet & accel,
const DataPoint & alt )
pure virtual

Advance the state machine with the latest measurements.

Parameters
accelAcceleration vector readings.
altAltimeter sample.
Note
When to use: call every sensor update; return codes can signal events or errors.

Implemented in BurnoutStateMachine, and StateMachine.

Member Data Documentation

◆ kMaxStateEntryCallbacks

std::size_t BaseStateMachine::kMaxStateEntryCallbacks = 32
staticconstexpr

Definition at line 24 of file BaseStateMachine.h.


The documentation for this class was generated from the following files: