Skip to content

Commit 5ff0192

Browse files
committed
Add serialization methods for NavigationResult
Fixes #52
1 parent 916cfe2 commit 5ff0192

3 files changed

Lines changed: 22 additions & 17 deletions

File tree

core/src/earth.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,21 @@ pub fn gravitation(latitude: &f64, longitude: &f64, altitude: &f64) -> Vector3<f
353353
gravity + rot * omega_ie * omega_ie * ecef_vec
354354
}
355355
/// Calculate local gravity anomaly from IMU accelerometer measurements
356+
///
357+
/// This function calculates the local gravity anomaly by comparing the observed gravity from the
358+
/// IMU accelerometer measurements (eg: $\sqrt(a_x^2 + a_y^2 + a_z^2)$) with the normal gravity
359+
/// at the given latitude and altitude via the Somigliana method. Additionally, this function
360+
/// compensates for the motion of the platform (if any) using the Eötvös correction.
361+
///
362+
/// # Parameters
363+
/// - `latitude` - The WGS84 latitude in degrees
364+
/// - `altitude` - The WGS84 altitude in meters
365+
/// - `north_velocity` - The northward velocity component in m/s
366+
/// - `east_velocity` - The eastward velocity component in m/s
367+
/// - `gravity_observed` - The observed gravity from the IMU accelerometer measurements in m/s^2
368+
///
369+
/// # Returns
370+
/// The local gravity anomaly in m/s^2, which is the difference between the observed gravity and the normal gravity at the given latitude and altitude, adjusted for the Eötvös correction.
356371
pub fn gravity_anomaly(
357372
latitude: &f64,
358373
altitude: &f64,

core/src/main.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,14 @@ struct Args {
2323
#[clap(long, value_parser)]
2424
gps_interval: Option<usize>,
2525
}
26-
27-
fn write_results_to_csv(
28-
// TODO: make this public and move to sim.rs
29-
results: &[NavigationResult],
30-
output: &PathBuf,
31-
) -> Result<(), Box<dyn Error>> {
32-
let mut wtr = WriterBuilder::new().from_path(output)?;
33-
for result in results {
34-
wtr.serialize(result)?;
35-
}
36-
wtr.flush()?;
37-
Ok(())
38-
}
3926
fn main() -> Result<(), Box<dyn Error>> {
4027
let args = Args::parse();
41-
// Read the input CSV file
42-
let mut rdr = ReaderBuilder::new().from_path(&args.input)?;
4328
// Validate the mode
4429
if args.mode != "open-loop" && args.mode != "closed-loop" {
4530
return Err("Invalid mode specified. Use 'open-loop' or 'closed-loop'.".into());
4631
}
32+
// Read the input CSV file
33+
let mut rdr = ReaderBuilder::new().from_path(&args.input)?;
4734
let records: Vec<TestDataRecord> = rdr.deserialize().collect::<Result<_, _>>()?;
4835
println!(
4936
"Read {} records from {}",
@@ -58,13 +45,15 @@ fn main() -> Result<(), Box<dyn Error>> {
5845
);
5946

6047
results = closed_loop(&records, args.gps_interval);
61-
match write_results_to_csv(&results, &args.output) {
48+
//match write_results_to_csv(&results, &args.output) {
49+
match NavigationResult::to_csv(&results, &args.output) {
6250
Ok(_) => println!("Results written to {}", args.output.display()),
6351
Err(e) => eprintln!("Error writing results: {}", e),
6452
};
6553
} else if args.mode == "open-loop" {
6654
results = dead_reckoning(&records);
67-
match write_results_to_csv(&results, &args.output) {
55+
// match write_results_to_csv(&results, &args.output) {
56+
match NavigationResult::to_csv(&results, &args.output) {
6857
Ok(_) => println!("Results written to {}", args.output.display()),
6958
Err(e) => eprintln!("Error writing results: {}", e),
7059
};

core/src/sim.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ impl
754754
}
755755
}
756756
}
757+
757758
/// Run dead reckoning or "open-loop" simulation using test data.
758759
///
759760
/// This function processes a sequence of sensor records through a StrapdownState, using

0 commit comments

Comments
 (0)