nyx_space/od/filter/
mod.rs

1/*
2    Nyx, blazing fast astrodynamics
3    Copyright (C) 2018-onwards Christopher Rabotin <christopher.rabotin@gmail.com>
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU Affero General Public License as published
7    by the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU Affero General Public License for more details.
14
15    You should have received a copy of the GNU Affero General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17*/
18
19use self::kalman::Residual;
20
21use super::estimate::Estimate;
22use super::process::ResidRejectCrit;
23use super::snc::SNC;
24use super::ODError;
25pub use crate::dynamics::Dynamics;
26use crate::linalg::allocator::Allocator;
27use crate::linalg::{DefaultAllocator, DimName, OMatrix, OVector};
28pub use crate::{State, TimeTagged};
29pub mod kalman;
30
31/// Defines a Filter trait where S is the size of the estimated state, A the number of acceleration components of the EOMs (used for process noise matrix size), M the size of the measurements.
32pub trait Filter<T, A, M>
33where
34    A: DimName,
35    M: DimName,
36    T: State,
37    DefaultAllocator: Allocator<M>
38        + Allocator<<T as State>::Size>
39        + Allocator<<T as State>::VecLength>
40        + Allocator<A>
41        + Allocator<M, M>
42        + Allocator<M, <T as State>::Size>
43        + Allocator<<T as State>::Size, <T as State>::Size>
44        + Allocator<A, A>
45        + Allocator<<T as State>::Size, A>
46        + Allocator<A, <T as State>::Size>,
47{
48    type Estimate: Estimate<T>;
49
50    /// Returns the previous estimate
51    fn previous_estimate(&self) -> &Self::Estimate;
52
53    /// Set the previous estimate
54    fn set_previous_estimate(&mut self, est: &Self::Estimate);
55
56    /// Update the sensitivity matrix (or "H tilde"). This function **must** be called prior to each
57    /// call to `measurement_update`.
58    fn update_h_tilde(&mut self, h_tilde: OMatrix<f64, M, <T as State>::Size>);
59
60    /// Computes a time update/prediction at the provided nominal state (i.e. advances the filter estimate with the updated STM).
61    ///
62    /// Returns an error if the STM was not updated.
63    fn time_update(&mut self, nominal_state: T) -> Result<Self::Estimate, ODError>;
64
65    /// Computes the measurement update with a provided real observation and computed observation.
66    ///
67    /// The nominal state is the state used for the computed observation.
68    /// The real observation is the observation that was actually measured.
69    /// The computed observation is the observation that was computed from the nominal state.
70    ///
71    /// Returns the updated estimate and the residual. The residual may be zero if the residual ratio check prevented the ingestion of this measurement.
72    ///
73    /// # Arguments
74    ///
75    /// * `nominal_state`: the nominal state at which the observation was computed.
76    /// * `real_obs`: the real observation that was measured.
77    /// * `computed_obs`: the computed observation from the nominal state.
78    /// * `measurement_covar`: the measurement covariance associated with this time update (i./e. the square of the standard deviation)
79    /// * `resid_rejection`: the automatic residual rejection criteria, if enabled.
80    fn measurement_update(
81        &mut self,
82        nominal_state: T,
83        real_obs: &OVector<f64, M>,
84        computed_obs: &OVector<f64, M>,
85        measurement_covar: OMatrix<f64, M, M>,
86        resid_rejection: Option<ResidRejectCrit>,
87    ) -> Result<(Self::Estimate, Residual<M>), ODError>;
88
89    /// Returns whether the filter is an extended filter (e.g. EKF)
90    fn is_extended(&self) -> bool;
91
92    /// Sets the filter to be extended or not depending on the value of status
93    fn set_extended(&mut self, status: bool);
94
95    /// Sets the process noise matrix of the estimated state
96    fn set_process_noise(&mut self, snc: SNC<A>);
97}