From c5d3ec8dbcb279f8dd4cdb0a547707ed05a7a6e9 Mon Sep 17 00:00:00 2001 From: Christopher Rabotin Date: Tue, 14 Jan 2025 15:06:58 -0600 Subject: [PATCH] Impl Mul and MulAssign for stochastic noise --- src/od/noise/gauss_markov.rs | 22 +++++++++++++--------- src/od/noise/mod.rs | 22 ++++++++++++++++++++++ src/od/noise/white.rs | 18 ++++++++++++++++++ tests/orbit_determination/simulator.rs | 10 +++++++++- 4 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/od/noise/gauss_markov.rs b/src/od/noise/gauss_markov.rs index 96b51b63..26433b02 100644 --- a/src/od/noise/gauss_markov.rs +++ b/src/od/noise/gauss_markov.rs @@ -23,7 +23,7 @@ use rand::Rng; use rand_distr::Normal; use serde_derive::{Deserialize, Serialize}; use std::fmt; -use std::ops::Mul; +use std::ops::{Mul, MulAssign}; use super::Stochastics; @@ -153,14 +153,18 @@ impl Mul for GaussMarkov { type Output = Self; /// Scale the Gauss Markov process by a constant, maintaining the same time constant. - fn mul(self, rhs: f64) -> Self::Output { - Self { - tau: self.tau, - process_noise: self.process_noise * rhs, - constant: None, - init_sample: None, - prev_epoch: None, - } + fn mul(mut self, rhs: f64) -> Self::Output { + self.process_noise *= rhs; + self.constant = None; + self.init_sample = None; + self.prev_epoch = None; + self + } +} + +impl MulAssign for GaussMarkov { + fn mul_assign(&mut self, rhs: f64) { + *self = *self * rhs; } } diff --git a/src/od/noise/mod.rs b/src/od/noise/mod.rs index b32d7332..ed78a417 100644 --- a/src/od/noise/mod.rs +++ b/src/od/noise/mod.rs @@ -27,6 +27,7 @@ use rand_pcg::Pcg64Mcg; use serde_derive::{Deserialize, Serialize}; use std::error::Error; use std::fs::File; +use std::ops::{Mul, MulAssign}; use std::path::Path; use std::sync::Arc; @@ -212,6 +213,27 @@ impl StochasticNoise { } } +impl Mul for StochasticNoise { + type Output = Self; + + fn mul(mut self, rhs: f64) -> Self::Output { + if let Some(mut wn) = &mut self.white_noise { + wn *= rhs; + } + if let Some(mut gm) = &mut self.bias { + gm *= rhs; + } + + self + } +} + +impl MulAssign for StochasticNoise { + fn mul_assign(&mut self, rhs: f64) { + *self = *self * rhs; + } +} + pub struct StochasticState { pub run: u32, pub dt_s: f64, diff --git a/src/od/noise/white.rs b/src/od/noise/white.rs index 305d1189..a8cea983 100644 --- a/src/od/noise/white.rs +++ b/src/od/noise/white.rs @@ -16,6 +16,8 @@ along with this program. If not, see . */ +use std::ops::{Mul, MulAssign}; + use anise::constants::SPEED_OF_LIGHT_KM_S; use hifitime::{Duration, Epoch}; use rand::Rng; @@ -77,6 +79,22 @@ impl Stochastics for WhiteNoise { } } +impl Mul for WhiteNoise { + type Output = Self; + + /// Scale the white noise sigmas by a constant. + fn mul(mut self, rhs: f64) -> Self::Output { + self.sigma *= rhs; + self + } +} + +impl MulAssign for WhiteNoise { + fn mul_assign(&mut self, rhs: f64) { + *self = *self * rhs; + } +} + #[cfg(test)] mod ut_wn { use hifitime::{Epoch, TimeUnits}; diff --git a/tests/orbit_determination/simulator.rs b/tests/orbit_determination/simulator.rs index b03d1d73..277702a8 100644 --- a/tests/orbit_determination/simulator.rs +++ b/tests/orbit_determination/simulator.rs @@ -216,7 +216,7 @@ fn continuous_tracking_cov_test(tracking_data: TrackingDataArc) { fn od_with_modulus_cov_test( spacecraft: Spacecraft, tracking_data: TrackingDataArc, - devices: BTreeMap, + mut devices: BTreeMap, trajectory: Trajectory, almanac: Arc, ) { @@ -227,6 +227,14 @@ fn od_with_modulus_cov_test( arc.set_moduli(MeasurementType::Range, jpl_dsn_code_length_km); arc.apply_moduli(); + // Increase the noise on the OD process + // Set a bias instead of assuming a modulus. + for (_, device) in &mut devices { + for (_, stochastics) in device.stochastic_noises.as_mut().unwrap().iter_mut() { + *stochastics *= 2.0; + } + } + let uncertainty = SpacecraftUncertainty::builder() .nominal(spacecraft) .frame(LocalFrame::RIC)