State
The State class in MMFS serves as the central data aggregator, coordinating all sensors, optionally fusing data via a filter (e.g. a Kalman filter), and determining the current flight stage. This class is typically passed into MMFSSystem for high-level control of the flight software.
Overview
The State class is responsible for:
- Sensor updates – polling and managing all registered sensors
- Sensor fusion (optional) – using a provided
Filterto compute position/velocity/acceleration - Flight stage logic – calling a user-implemented
determineStage()to manage the rocket’s flight state machine
Expected Usage
You are expected to subclass State and implement:
This method determines the current flight phase (e.g., pad, boost, coast, recovery) based on sensor values like altitude, acceleration, or velocity.
In your subclass, you'll typically query sensors like so:
Constructor
sensors: an array of pointers to various Sensor-derived classes (e.g. GPS, IMU, Barometer)numSensors: number of sensors in the arrayfilter: optional pointer to aFilterobject for data fusion (e.g. Kalman filter)
Lifecycle and Core Methods
Initialization
Initializes all valid sensors and optionally enables bias correction. Failing sensors are disabled and logged.
State Update
Called once per loop. This does the following:
- Records
lastTimeand updatescurrentTime - Calls
updateSensors()on all valid sensors - Calls
updateKF()orupdateWithoutKF()depending on filter presence - Updates orientation, heading, and positional fields
- Finally calls
determineStage()(which you override)
Sensor Access
Sensors can be accessed by type using:
Returned sensors can then be downcasted to the appropriate type (e.g. Barometer, GPS).
Internal State Variables
These are updated every loop and can be queried with get*() methods:
Vector<3> position— Displacement in metersVector<3> velocity— m/sVector<3> acceleration— m/s²Quaternion orientation— current rotation from IMUVector<3> eulerAngles— roll, pitch, yaw (derived)Vector<2> coordinates— lat/lon (from GPS)float heading— direction of travelint stage— user-defined flight stage value
These are all exposed via DataReporter for logging and telemetry.
Kalman Filter Integration
If a Filter is passed into the constructor:
- It will be initialized during
init() - Called on each
updateState()to fuse sensor data - Internal
stateVarswill be allocated to store the filter’s output
You must ensure your Filter subclass implements the expected interface (e.g., initialize(), update(), etc.).
Example Implementation
This shows a basic launch detection using either IMU acceleration or barometric altitude.
Integration with MMFSSystem
Once your State is initialized, pass it to MMFSSystem like so:
MMFSSystem will handle calling updateState() and routing stage transitions.
Summary
Statecentralizes sensor access, fusion, and stage tracking- You override
determineStage()to define flight logic - Sensors are polled and filtered each update cycle
- Internal state is auto-logged via
DataReporter - Integrates directly with
MMFSSystem
Written by ChatGPT. Information may not be accurate.