extern crate serde;
use crate::celestia::TimeTagged;
use crate::dimensions::allocator::Allocator;
use crate::dimensions::{DefaultAllocator, DimName, MatrixMN, VectorN};
use crate::time::Epoch;
use dynamics::Dynamics;
use std::fmt;
use std::ops::Add;
use crate::io::{CovarFormat, EpochFormat};
pub mod kalman;
pub mod ranging;
pub mod estimate;
pub mod residual;
pub mod ui;
pub mod srif;
pub trait Estimable<N>
where
Self: Dynamics + Sized,
{
type LinStateSize: DimName;
fn extract_estimated_state(
&self,
prop_state: &Self::StateType,
) -> VectorN<f64, Self::LinStateSize>
where
DefaultAllocator: Allocator<f64, Self::LinStateSize>;
fn estimated_state(&self) -> VectorN<f64, Self::LinStateSize>
where
DefaultAllocator: Allocator<f64, Self::LinStateSize>,
{
self.extract_estimated_state(&self.state())
}
fn set_estimated_state(&mut self, new_state: VectorN<f64, Self::LinStateSize>)
where
DefaultAllocator: Allocator<f64, Self::LinStateSize>;
fn stm(&self) -> MatrixMN<f64, Self::LinStateSize, Self::LinStateSize>
where
DefaultAllocator: Allocator<f64, Self::LinStateSize>
+ Allocator<f64, Self::LinStateSize, Self::LinStateSize>,
{
self.extract_stm(&self.state())
}
fn to_measurement(&self, prop_state: &Self::StateType) -> N;
fn extract_stm(
&self,
prop_state: &Self::StateType,
) -> MatrixMN<f64, Self::LinStateSize, Self::LinStateSize>
where
DefaultAllocator: Allocator<f64, Self::LinStateSize>
+ Allocator<f64, Self::LinStateSize, Self::LinStateSize>;
}
pub trait Filter<S, A, M, T>
where
S: DimName,
A: DimName,
M: DimName,
T: EstimableState<S>,
DefaultAllocator: Allocator<f64, M>
+ Allocator<f64, S>
+ Allocator<f64, M, M>
+ Allocator<f64, M, S>
+ Allocator<f64, S, S>
+ Allocator<f64, A, A>
+ Allocator<f64, S, A>
+ Allocator<f64, A, S>,
{
type Estimate: estimate::Estimate<S, T>;
fn previous_estimate(&self) -> &Self::Estimate;
fn update_stm(&mut self, new_stm: MatrixMN<f64, S, S>);
fn update_h_tilde(&mut self, h_tilde: MatrixMN<f64, M, S>);
fn time_update(&mut self, nominal_state: T) -> Result<Self::Estimate, FilterError>;
fn measurement_update(
&mut self,
nominal_state: T,
real_obs: VectorN<f64, M>,
computed_obs: VectorN<f64, M>,
) -> Result<(Self::Estimate, residual::Residual<M>), FilterError>;
fn is_extended(&self) -> bool;
fn set_extended(&mut self, status: bool);
fn set_process_noise(&mut self, prc: MatrixMN<f64, A, A>);
}
#[derive(Debug, PartialEq)]
pub enum FilterError {
StateTransitionMatrixNotUpdated,
SensitivityNotUpdated,
GainSingular,
StateTransitionMatrixSingular,
}
impl fmt::Display for FilterError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
FilterError::StateTransitionMatrixNotUpdated => {
write!(f, "STM was not updated prior to time or measurement update")
}
FilterError::SensitivityNotUpdated => write!(
f,
"The measurement matrix H_tilde was not updated prior to measurement update"
),
FilterError::GainSingular => write!(
f,
"Gain could not be computed because H*P_bar*H + R is singular"
),
FilterError::StateTransitionMatrixSingular => {
write!(f, "STM is singular, smoothing cannot proceed")
}
}
}
}
pub trait Measurement: TimeTagged
where
Self: Sized,
DefaultAllocator: Allocator<f64, Self::MeasurementSize>
+ Allocator<f64, Self::MeasurementSize, Self::StateSize>,
{
type StateSize: DimName;
type MeasurementSize: DimName;
fn observation(&self) -> VectorN<f64, Self::MeasurementSize>
where
DefaultAllocator: Allocator<f64, Self::MeasurementSize>;
fn sensitivity(&self) -> MatrixMN<f64, Self::MeasurementSize, Self::StateSize>
where
DefaultAllocator: Allocator<f64, Self::StateSize, Self::MeasurementSize>;
fn visible(&self) -> bool;
}
pub trait MeasurementDevice<Msr, MsrIn>
where
Self: Sized,
Msr: Measurement,
DefaultAllocator: Allocator<f64, Msr::StateSize>
+ Allocator<f64, Msr::StateSize, Msr::MeasurementSize>
+ Allocator<f64, Msr::MeasurementSize>
+ Allocator<f64, Msr::MeasurementSize, Msr::StateSize>,
{
fn measure(&self, input: &MsrIn) -> Option<Msr>;
}
pub trait EstimableState<S: DimName>:
TimeTagged + Add<VectorN<f64, S>, Output = Self> + Clone + PartialEq + fmt::Display + fmt::LowerExp
where
Self: Sized,
DefaultAllocator: Allocator<f64, S>,
{
}