use anise::almanac::Almanac;
use anise::errors::AlmanacResult;
use hifitime::Epoch;
use indexmap::IndexSet;
use nalgebra::{DimName, OMatrix, OVector};
use rand_pcg::Pcg64Mcg;
use crate::Orbit;
use crate::io::ConfigRepr;
use crate::linalg::DefaultAllocator;
use crate::linalg::allocator::Allocator;
use crate::md::prelude::{Frame, Traj};
use crate::md::trajectory::Interpolatable;
use crate::od::ODError;
use crate::od::msr::MeasurementType;
use crate::od::msr::measurement::Measurement as NewMeasurement;
pub trait TrackingDevice<MsrIn>: Clone + ConfigRepr
where
MsrIn: Interpolatable,
DefaultAllocator:
Allocator<MsrIn::Size> + Allocator<MsrIn::Size, MsrIn::Size> + Allocator<MsrIn::VecLength>,
{
fn name(&self) -> String;
fn measurement_types(&self) -> &IndexSet<MeasurementType>;
fn measure(
&mut self,
epoch: Epoch,
traj: &Traj<MsrIn>,
rng: Option<&mut Pcg64Mcg>,
almanac: &Almanac,
) -> Result<Option<NewMeasurement>, ODError>;
fn location(&self, epoch: Epoch, frame: Frame, almanac: &Almanac) -> AlmanacResult<Orbit>;
fn measure_instantaneous(
&mut self,
rx: MsrIn,
rng: Option<&mut Pcg64Mcg>,
almanac: &Almanac,
) -> Result<Option<NewMeasurement>, ODError>;
fn measurement_covar(&self, msr_type: MeasurementType, epoch: Epoch) -> Result<f64, ODError>;
fn measurement_bias(&self, msr_type: MeasurementType, epoch: Epoch) -> Result<f64, ODError>;
fn measurement_covar_matrix<M: DimName>(
&self,
msr_types: &IndexSet<MeasurementType>,
epoch: Epoch,
) -> Result<OMatrix<f64, M, M>, ODError>
where
DefaultAllocator: Allocator<M, M>,
{
let mut r_mat = OMatrix::<f64, M, M>::zeros();
for (i, msr_type) in msr_types.iter().enumerate() {
if self.measurement_types().contains(msr_type) {
r_mat[(i, i)] = self.measurement_covar(*msr_type, epoch)?;
}
}
Ok(r_mat)
}
fn measurement_bias_vector<M: DimName>(
&self,
msr_types: &IndexSet<MeasurementType>,
epoch: Epoch,
) -> Result<OVector<f64, M>, ODError>
where
DefaultAllocator: Allocator<M>,
{
let mut b_vec = OVector::<f64, M>::zeros();
for (i, msr_type) in msr_types.iter().enumerate() {
if self.measurement_types().contains(msr_type) {
b_vec[i] = self.measurement_bias(*msr_type, epoch)?;
}
}
Ok(b_vec)
}
}