Skip to content

Commit 84e4f43

Browse files
Mitigate the very rare cases where the Sk inversion fails
1 parent c5d3ec8 commit 84e4f43

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/od/filter/kalman.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,14 @@ where
300300
// Compute the prefit ratio for the automatic rejection.
301301
// The measurement covariance is the square of the measurement itself.
302302
// So we compute its Cholesky decomposition to return to the non squared values.
303-
dbg!(epoch);
304-
dbg!(&r_k);
305-
dbg!(&s_k);
306-
let r_k_chol = s_k.clone().cholesky().ok_or(ODError::SingularNoiseRk)?.l();
303+
let r_k_chol = match s_k.clone().cholesky() {
304+
Some(r_k_clone) => r_k_clone.l(),
305+
None => {
306+
// In very rare case, when there isn't enough noise in the measurements,
307+
// the inverting of S_k fails. If so, we revert back to the nominal Kalman derivation.
308+
r_k.clone().cholesky().ok_or(ODError::SingularNoiseRk)?.l()
309+
}
310+
};
307311

308312
// Compute the ratio as the average of each component of the prefit over the square root of the measurement
309313
// matrix r_k. Refer to ODTK MathSpec equation 4.10.

tests/orbit_determination/simulator.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ fn od_with_modulus_cov_test(
257257

258258
println!("{estimate}");
259259

260-
let kf = KF::no_snc(estimate);
260+
let sigma_q = 1e-12_f64.powi(2);
261+
let process_noise = SNC3::from_diagonal(2 * Unit::Minute, &[sigma_q, sigma_q, sigma_q]);
262+
let kf = KF::new(estimate, process_noise);
261263

262264
let setup = Propagator::default(SpacecraftDynamics::new(OrbitalDynamics::two_body()));
263265
let prop = setup.with(spacecraft.with_stm(), almanac.clone());

0 commit comments

Comments
 (0)