Input Filtering¶
AURORA is built to use different filter techniques for apogee detection,
controlled by CONFIG_FILTER_TYPE.
Kalman Filter¶
One implementation uses a 2-state Kalman filter with vertical
acceleration as a control input
(guarded by CONFIG_FILTER and CONFIG_FILTER_KALMAN).
The filter tracks a two-element state vector, consisting of altitude and
vertical velocity, and is fed barometric altitude measurements that the baro
library converts from pressure via the ISA hypsometric formula.
On every state-machine tick the filter runs a predict/update cycle:
The predict step propagates altitude and velocity forward using the world-frame vertical acceleration as a control input (\(B = [\tfrac{1}{2} \Delta t^2,\; \Delta t]^\top\)) while growing the covariance by a process-noise term scaled with \(\Delta t\). \(\Delta t\) is clamped to 1 s to prevent filter blow-up.
The update step corrects the state with the latest barometric altitude reading through the standard Kalman gain. A normalised-innovation-squared (NIS / Mahalanobis) gate of 25 (\(\approx 5\sigma\)) rejects obvious sensor glitches; the gate is disabled for the first 30 updates (~3 s at 10 Hz) to ride out the initial transient before the prior covariance settles.
Apogee detection combines three criteria evaluated on every call to
filter_detect_apogee():
velocity estimate has gone non-positive,
the running peak altitude is no longer being beaten (descent), and
the last applied vertical acceleration sits inside a \(\pm 20\,\mathrm{m/s^2}\) coast band, which rejects boost-phase kinematics.
All three must hold for CONFIG_FILTER_APOGEE_DEBOUNCE_SAMPLES
consecutive samples before apogee is latched and the
\(\text{BURNOUT} \rightarrow \text{APOGEE}\) state transition is
reported. Once latched, the filter keeps reporting
apogee without re-evaluating the criteria.
Three tunable noise parameters (altitude process noise Q_alt, velocity process noise Q_vel, and measurement noise R) plus the debounce sample count are exposed as Kconfig options so they can be adjusted without recompiling the filter source.
A Python simulation tool (tools/sim_flight_kalman.py) reproduces the same algorithm with a realistic flight profile and MS5607 sensor-noise model, allowing the filter to be tuned and validated offline before flight. See sim_flight_kalman.py for usage and example output.
The filter and its hypsometric pipeline are covered by a ztest suite under aurora/tests/lib/filter/.
Configuration¶
Noise parameters are integer-scaled by 1000 in Kconfig.
The actual float value is CONFIG_FILTER_*_MILLISCALE / 1000.0.
Option |
Default |
Description |
|---|---|---|
|
100 |
Process noise for altitude state (Q_alt). Increase if altitude estimate lags behind reality. |
|
500 |
Process noise for velocity state (Q_vel). Increase for more aggressive response during boost. |
|
4000 |
Measurement noise variance (R). Higher values trust the barometer less. |
|
3 |
Consecutive |
API-Reference¶
-
int filter_init(struct filter *filter)¶
Initialize the filter.
Zeroes state, sets initial covariance, and loads process/measurement noise from Kconfig (scaled by FILTER_SCALE_DIVISOR).
- Parameters:
filter – Pointer to filter structure.
- Return values:
0 – on success.
-EINVAL – if
filteris NULL.
-
int filter_predict(struct filter *filter, int64_t dt, double a_vert)¶
Perform the filter prediction step.
Propagates state and covariance forward in time using a constant-acceleration model with
a_vertas the control input.- Parameters:
filter – Pointer to filter structure.
dt – Elapsed time in nanoseconds since last prediction.
a_vert – World-frame vertical acceleration (m/s^2), gravity-removed. Pass 0.0 to fall back to constant-velocity behavior when no acceleration input is available.
- Return values:
0 – on success.
-EINVAL – if
filteris NULL ordt<= 0.
-
int filter_update(struct filter *filter, double z)¶
Perform the filter measurement update step.
Computes Kalman gain and corrects the state estimate using a barometric altitude measurement.
A normalized-innovation-squared (NIS) gate rejects measurements that are statistically inconsistent with the current estimate (y*y/S above ~5-sigma), guarding against sensor glitches such as ejection pressure spikes. The gate only activates once the filter’s altitude variance has dropped to or below the measurement noise, so cold-start and wide-prior conditions still accept the first reads.
- Parameters:
filter – Pointer to filter structure.
z – Measured altitude in meters.
- Return values:
0 – if the measurement was applied.
1 – if the measurement was rejected by the innovation gate.
-EINVAL – if
filteris NULL.-EDOM – if the innovation covariance is singular.
-
int filter_detect_apogee(struct filter *filter)¶
Detect apogee using a three-criterion vote.
Combines three signals to reject noise-driven false positives:
Filtered vertical velocity is non-positive. Velocity is the leading indicator at apogee, so no hysteresis band is applied beyond the debounce below — it would only delay detection.
Filtered altitude is below the tracked peak, guarding against pad-side triggers where velocity jitter could briefly go negative before launch.
The most recent world-frame vertical acceleration is within a hard-coded sanity band (|a_vert| < ~20 m/s^2), ruling out boost and anomalous accel transients at the decision point.
All conditions must hold for
CONFIG_FILTER_APOGEE_DEBOUNCE_SAMPLESconsecutive calls before apogee is reported. Apogee is latched – once reported, subsequent calls return 0 until filter_init is called again.- Parameters:
filter – Pointer to filter structure.
- Return values:
1 – if apogee detected.
0 – if apogee not detected.
-EINVAL – if
filteris NULL.
-
FILTER_SCALE_DIVISOR¶
Divisor applied to Kconfig milliscale noise parameters.
-
struct filter¶
- #include <filter.h>
2-state Kalman filter structure for rocket state machine.
State vector: x[0] = altitude (m) x[1] = vertical velocity (m/s)
The filter uses a constant-acceleration model with vertical acceleration supplied as a control input to filter_predict(), and barometric altitude as the measurement input. Passing a_vert = 0.0 reduces the model to constant-velocity behavior.