Skip to content

Commit bf6c881

Browse files
committed
Enhance gravity anomaly calculation by including Eotvos correction; add default implementation for NavigationResult struct and clean up unused imports
1 parent c1c0129 commit bf6c881

2 files changed

Lines changed: 16 additions & 49 deletions

File tree

core/src/earth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ pub fn gravity_anomaly(
362362
) -> f64 {
363363
let normal_gravity: f64 = gravity(latitude, &0.0);
364364
let eotvos_correction: f64 = eotvos(latitude, altitude, north_velocity, east_velocity);
365-
*gravity_observed - normal_gravity
365+
*gravity_observed - normal_gravity - eotvos_correction
366366
}
367367
/// Calculate the Eotvos correction for the local-level frame
368368
///

core/src/sim.rs

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ use std::fmt::Display;
1010
use std::io::{self};
1111
use std::path::Path;
1212

13-
use chrono::serde::ts_seconds;
1413
use chrono::{DateTime, Utc};
15-
use nalgebra::{DMatrix, DVector, Rotation, Rotation3, Vector3};
16-
use serde::{Deserialize, Deserializer, Serialize, Serializer};
14+
use nalgebra::{DMatrix, DVector, Rotation3, Vector3};
15+
use serde::{Deserialize, Serialize};
1716

1817
use crate::earth;
1918
use crate::earth::METERS_TO_DEGREES;
@@ -334,6 +333,12 @@ pub struct NavigationResult {
334333
/// Magnetic field strength anomaly in nT
335334
pub mag_anomaly: f64,
336335
}
336+
impl Default for NavigationResult {
337+
fn default() -> Self {
338+
Self::new()
339+
}
340+
}
341+
337342
impl NavigationResult {
338343
/// Creates a new NavigationResult with default values.
339344
pub fn new() -> Self {
@@ -519,7 +524,7 @@ impl NavigationResult {
519524
gyro_bias_x: state[12],
520525
gyro_bias_y: state[13],
521526
gyro_bias_z: state[14],
522-
latitude_cov: covariance_vec.get(0).cloned().unwrap_or(0.0),
527+
latitude_cov: covariance_vec.first().cloned().unwrap_or(0.0),
523528
longitude_cov: covariance_vec.get(1).cloned().unwrap_or(0.0),
524529
altitude_cov: covariance_vec.get(2).cloned().unwrap_or(0.0),
525530
velocity_n_cov: covariance_vec.get(3).cloned().unwrap_or(0.0),
@@ -666,9 +671,9 @@ impl From<(&DateTime<Utc>, &UKF, &IMUData, &f64, &f64, &f64, &f64)> for Navigati
666671
&state[0].to_radians(),
667672
&state[1].to_radians(),
668673
&state[2],
669-
&mag_x,
670-
&mag_y,
671-
&mag_z,
674+
mag_x,
675+
mag_y,
676+
mag_z,
672677
),
673678
}
674679
}
@@ -753,51 +758,13 @@ impl
753758
&state.latitude,
754759
&state.longitude,
755760
&state.altitude,
756-
&mag_x,
757-
&mag_y,
758-
&mag_z,
761+
mag_x,
762+
mag_y,
763+
mag_z,
759764
),
760765
}
761766
}
762767
}
763-
764-
/// Custom serializer for the covariance field to serialize it as a single string in CSV
765-
fn serialize_covariance<S>(cov: &Option<Vec<f64>>, serializer: S) -> Result<S::Ok, S::Error>
766-
where
767-
S: Serializer,
768-
{
769-
match cov {
770-
Some(vec) => {
771-
// Join the vector elements with commas and serialize as a single string
772-
let cov_str = vec
773-
.iter()
774-
.map(|v| v.to_string())
775-
.collect::<Vec<String>>()
776-
.join(",");
777-
serializer.serialize_str(&cov_str)
778-
}
779-
None => serializer.serialize_none(),
780-
}
781-
}
782-
/// Custom deserializer for the covariance field to deserialize from a string in CSV
783-
fn deserialize_covariance<'de, D>(deserializer: D) -> Result<Option<Vec<f64>>, D::Error>
784-
where
785-
D: Deserializer<'de>,
786-
{
787-
let s: Option<String> = Option::deserialize(deserializer)?;
788-
match s {
789-
Some(s) if !s.is_empty() => {
790-
// Parse the comma-separated string back to a Vec<f64>
791-
let values: Result<Vec<f64>, _> = s.split(',').map(|v| v.parse::<f64>()).collect();
792-
793-
match values {
794-
Ok(vec) => Ok(Some(vec)),
795-
Err(_) => Ok(None), // Handle parsing errors gracefully
796-
}
797-
}
798-
_ => Ok(None),
799-
}
800-
}
801768
/// Run dead reckoning or "open-loop" simulation using test data.
802769
///
803770
/// This function processes a sequence of sensor records through a StrapdownState, using

0 commit comments

Comments
 (0)