Skip to content

Commit c5d3ec8

Browse files
Impl Mul and MulAssign for stochastic noise
1 parent 706ac28 commit c5d3ec8

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

src/od/noise/gauss_markov.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rand::Rng;
2323
use rand_distr::Normal;
2424
use serde_derive::{Deserialize, Serialize};
2525
use std::fmt;
26-
use std::ops::Mul;
26+
use std::ops::{Mul, MulAssign};
2727

2828
use super::Stochastics;
2929

@@ -153,14 +153,18 @@ impl Mul<f64> for GaussMarkov {
153153
type Output = Self;
154154

155155
/// Scale the Gauss Markov process by a constant, maintaining the same time constant.
156-
fn mul(self, rhs: f64) -> Self::Output {
157-
Self {
158-
tau: self.tau,
159-
process_noise: self.process_noise * rhs,
160-
constant: None,
161-
init_sample: None,
162-
prev_epoch: None,
163-
}
156+
fn mul(mut self, rhs: f64) -> Self::Output {
157+
self.process_noise *= rhs;
158+
self.constant = None;
159+
self.init_sample = None;
160+
self.prev_epoch = None;
161+
self
162+
}
163+
}
164+
165+
impl MulAssign<f64> for GaussMarkov {
166+
fn mul_assign(&mut self, rhs: f64) {
167+
*self = *self * rhs;
164168
}
165169
}
166170

src/od/noise/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use rand_pcg::Pcg64Mcg;
2727
use serde_derive::{Deserialize, Serialize};
2828
use std::error::Error;
2929
use std::fs::File;
30+
use std::ops::{Mul, MulAssign};
3031
use std::path::Path;
3132
use std::sync::Arc;
3233

@@ -212,6 +213,27 @@ impl StochasticNoise {
212213
}
213214
}
214215

216+
impl Mul<f64> for StochasticNoise {
217+
type Output = Self;
218+
219+
fn mul(mut self, rhs: f64) -> Self::Output {
220+
if let Some(mut wn) = &mut self.white_noise {
221+
wn *= rhs;
222+
}
223+
if let Some(mut gm) = &mut self.bias {
224+
gm *= rhs;
225+
}
226+
227+
self
228+
}
229+
}
230+
231+
impl MulAssign<f64> for StochasticNoise {
232+
fn mul_assign(&mut self, rhs: f64) {
233+
*self = *self * rhs;
234+
}
235+
}
236+
215237
pub struct StochasticState {
216238
pub run: u32,
217239
pub dt_s: f64,

src/od/noise/white.rs

+18
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19+
use std::ops::{Mul, MulAssign};
20+
1921
use anise::constants::SPEED_OF_LIGHT_KM_S;
2022
use hifitime::{Duration, Epoch};
2123
use rand::Rng;
@@ -77,6 +79,22 @@ impl Stochastics for WhiteNoise {
7779
}
7880
}
7981

82+
impl Mul<f64> for WhiteNoise {
83+
type Output = Self;
84+
85+
/// Scale the white noise sigmas by a constant.
86+
fn mul(mut self, rhs: f64) -> Self::Output {
87+
self.sigma *= rhs;
88+
self
89+
}
90+
}
91+
92+
impl MulAssign<f64> for WhiteNoise {
93+
fn mul_assign(&mut self, rhs: f64) {
94+
*self = *self * rhs;
95+
}
96+
}
97+
8098
#[cfg(test)]
8199
mod ut_wn {
82100
use hifitime::{Epoch, TimeUnits};

tests/orbit_determination/simulator.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn continuous_tracking_cov_test(tracking_data: TrackingDataArc) {
216216
fn od_with_modulus_cov_test(
217217
spacecraft: Spacecraft,
218218
tracking_data: TrackingDataArc,
219-
devices: BTreeMap<String, GroundStation>,
219+
mut devices: BTreeMap<String, GroundStation>,
220220
trajectory: Trajectory,
221221
almanac: Arc<Almanac>,
222222
) {
@@ -227,6 +227,14 @@ fn od_with_modulus_cov_test(
227227
arc.set_moduli(MeasurementType::Range, jpl_dsn_code_length_km);
228228
arc.apply_moduli();
229229

230+
// Increase the noise on the OD process
231+
// Set a bias instead of assuming a modulus.
232+
for (_, device) in &mut devices {
233+
for (_, stochastics) in device.stochastic_noises.as_mut().unwrap().iter_mut() {
234+
*stochastics *= 2.0;
235+
}
236+
}
237+
230238
let uncertainty = SpacecraftUncertainty::builder()
231239
.nominal(spacecraft)
232240
.frame(LocalFrame::RIC)

0 commit comments

Comments
 (0)