Skip to main content

rust_gnc/filters/
mod.rs

1//! # Signal Processing and Sensor Fusion
2//! 
3//! This module provides the abstractions and implementations for real-time 
4//! filtering. In a GNC (Guidance, Navigation, and Control) system, filters 
5//! are used to mitigate sensor noise and combat integration drift.
6//!
7//! ### Design Pattern
8//! We use a Trait-based approach to allow for static dispatch of various 
9//! filter implementations. This ensures `no_std` compatibility and 
10//! maximum performance on embedded hardware.
11
12use crate::Radians;
13
14pub mod complementary;
15
16/// The core abstraction for all state estimators and signal conditioners.
17///
18/// A `Filter` takes a stream of noisy inputs and produces a high-fidelity 
19/// output by maintaining an internal state across time steps (`dt`).
20pub trait Filter {
21    /// The raw sensor data or multi-sensor packet to be processed.
22    type Input;
23    /// The filtered estimate, usually a physical unit like `Radians`.
24    type Output;
25
26    /// Factory method to initialize a filter with a smoothing or trust coefficient.
27    /// 
28    /// ### Parameters
29    /// * `alpha` - A coefficient usually between 0.0 and 1.0 that defines the 
30    ///   filter's cutoff frequency or trust-weighting.
31    fn new(alpha: f32) -> Self where Self: Sized;
32
33    /// Advances the filter state by one time step.
34    /// 
35    /// ### Parameters
36    /// * `input` - The latest measurement.
37    /// * `dt` - The time elapsed since the last update in seconds.
38    fn update(&mut self, input: Self::Input, dt: f32) -> Self::Output;
39
40    /// Resets the internal state to a neutral default.
41    /// 
42    /// Critical for safety-critical systems to prevent "state carry-over" 
43    /// between different flight phases or after a system fault.
44    fn reset(&mut self);
45}
46
47// Re-export for ergonomic access: rust_gnc::filters::ComplementaryFilter
48pub use complementary::ComplementaryFilter;
49
50/// A standardized input structure for 6-DOF orientation filters.
51/// 
52/// In GNC, orientation estimation typically involves fusing two distinct signals:
53/// 1. **Rate**: High-frequency, low-latency data that is integrated (e.g., Gyroscope).
54/// 2. **Reference**: Low-frequency, stable data used to correct drift (e.g., Accelerometer).
55#[derive(Debug, Clone, Copy, PartialEq)]
56pub struct InertialInput {
57    /// The angular velocity (e.g., Rad/s from a Gyro).
58    pub rate: Radians,      
59    /// The absolute reference angle (e.g., Tilt from an Accelerometer).
60    pub reference: Radians, 
61}