nyx_space/od/estimate/
mod.rs1use super::State;
20use crate::cosmic::Orbit;
21use crate::linalg::allocator::Allocator;
22use crate::linalg::{DefaultAllocator, OMatrix, OVector};
23use crate::Spacecraft;
24use hifitime::Epoch;
25use std::cmp::PartialEq;
26use std::fmt;
27
28pub mod residual;
29pub use residual::Residual;
30pub mod kfestimate;
31pub use kfestimate::KfEstimate;
32mod sc_uncertainty;
33pub use sc_uncertainty::SpacecraftUncertainty;
34
35pub trait Estimate<T: State>
37where
38 Self: Clone + PartialEq + Sized + fmt::Display,
39 DefaultAllocator: Allocator<<T as State>::Size>
40 + Allocator<<T as State>::Size, <T as State>::Size>
41 + Allocator<<T as State>::VecLength>,
42{
43 fn zeros(state: T) -> Self;
45 fn epoch(&self) -> Epoch {
47 self.state().epoch()
48 }
49 fn set_epoch(&mut self, dt: Epoch) {
51 self.state().set_epoch(dt);
52 }
53 fn state(&self) -> T {
55 self.nominal_state().add(self.state_deviation())
56 }
57 fn state_deviation(&self) -> OVector<f64, <T as State>::Size>;
59 fn nominal_state(&self) -> T;
61 fn covar(&self) -> OMatrix<f64, <T as State>::Size, <T as State>::Size>;
63 fn predicted_covar(&self) -> OMatrix<f64, <T as State>::Size, <T as State>::Size>;
65 fn set_state_deviation(&mut self, new_state: OVector<f64, <T as State>::Size>);
67 fn set_covar(&mut self, new_covar: OMatrix<f64, <T as State>::Size, <T as State>::Size>);
69 fn predicted(&self) -> bool;
71 fn stm(&self) -> &OMatrix<f64, <T as State>::Size, <T as State>::Size>;
73 fn within_sigma(&self, sigma: f64) -> bool {
76 let state = self.state_deviation();
77 let covar = self.covar();
78 for i in 0..state.len() {
79 let bound = covar[(i, i)].sqrt() * sigma;
80 if state[i] > bound || state[i] < -bound {
81 return false;
82 }
83 }
84 true
85 }
86 fn within_3sigma(&self) -> bool {
88 self.within_sigma(3.0)
89 }
90}
91
92pub trait NavSolution<T>: Estimate<Spacecraft>
94where
95 T: State,
96 DefaultAllocator: Allocator<<T as State>::Size>
97 + Allocator<<T as State>::Size, <T as State>::Size>
98 + Allocator<<T as State>::VecLength>,
99{
100 fn orbital_state(&self) -> Orbit;
101 fn expected_state(&self) -> Orbit;
103}
104
105impl NavSolution<Spacecraft> for KfEstimate<Spacecraft> {
106 fn orbital_state(&self) -> Orbit {
107 self.state().orbit
108 }
109 fn expected_state(&self) -> Orbit {
110 self.nominal_state().orbit
111 }
112}