Skip to content

Commit 1342723

Browse files
authored
Merge pull request #78 from jbrodovsky:dataset_dev
Add GPS degradation functionality
2 parents 821d907 + d0465b0 commit 1342723

4 files changed

Lines changed: 35 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "strapdown-rs"
33
authors = ["James Brodovsky"]
4-
version = "0.3.0"
4+
version = "0.3.1"
55
edition = "2024"
66
description = "A toolbox for building and analyzing strapdown inertial navigation systems."
77
license = "MIT"

core/src/main.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use clap::Parser;
22
use csv::ReaderBuilder;
33
use std::error::Error;
44
use std::path::PathBuf;
5-
use strapdown::sim::{NavigationResult, TestDataRecord, closed_loop, dead_reckoning};
5+
use strapdown::sim::{NavigationResult, TestDataRecord, closed_loop, dead_reckoning, degrade_measurements};
66

77
/// Command line arguments
8-
// ...existing code...
98
#[derive(Parser, Debug)]
109
#[clap(author, version, about, long_about = None)]
1110
struct Args {
@@ -22,11 +21,11 @@ struct Args {
2221
#[clap(long, value_parser, help = "Interval (in seconds) between GPS measurements; used to simulate GPS outages")]
2322
gps_interval: Option<f64>,
2423
/// Optional: GPS degradation factor
25-
#[clap(long, value_parser, default_value = "1.0", help = "Factor by which GPS accuracy is degraded. 1.0 is no degradation. >= 1.0 is a degradation factor.")]
26-
gps_degradation: Option<f32>,
24+
#[clap(long, value_parser, default_value = "1.0", help = "Factor by which GPS accuracy is degraded. 1.0 is no degradation. >= 1.0 is a degradation factor. This factor is applied as a scalar multiplier to the recorded GPS accuracy.")]
25+
gps_degradation: Option<f64>,
2726
/// Optional: GPS spoofing offset
2827
#[clap(long, value_parser, default_value = "0.0", help = "Offset to apply to GPS coordinates (in meters)")]
29-
gps_spoofing_offset: Option<f32>,
28+
gps_spoofing_offset: Option<f64>,
3029
}
3130
fn main() -> Result<(), Box<dyn Error>> {
3231
let args = Args::parse();
@@ -36,12 +35,16 @@ fn main() -> Result<(), Box<dyn Error>> {
3635
}
3736
// Read the input CSV file
3837
let mut rdr = ReaderBuilder::new().from_path(&args.input)?;
39-
let records: Vec<TestDataRecord> = rdr.deserialize().collect::<Result<_, _>>()?;
38+
let mut records: Vec<TestDataRecord> = rdr.deserialize().collect::<Result<_, _>>()?;
4039
println!(
4140
"Read {} records from {}",
4241
records.len(),
4342
&args.input.display()
4443
);
44+
records = match args.gps_degradation {
45+
Some(value) => degrade_measurements(records, value),
46+
None => records,
47+
};
4548
let results: Vec<NavigationResult>;
4649
if args.mode == "closed-loop" {
4750
println!(

core/src/sim.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,30 @@ pub fn initialize_ukf(
10631063
0.0,
10641064
)
10651065
}
1066+
/// Degrades the certainty of GPS/GNSS measurements by a scalar factor of all specified accuracy metrics.
1067+
///
1068+
/// # Arguments
1069+
///
1070+
/// * `measurements`: A vector of TestDataRecord structs representing the measurements to be degraded.
1071+
/// * `factor`: A scalar factor by which to degrade the accuracy metrics.
1072+
///
1073+
/// # Returns
1074+
///
1075+
/// A vector of TestDataRecord structs with degraded accuracy metrics.
1076+
pub fn degrade_measurements(measurements: Vec<TestDataRecord>, factor: f64) -> Vec<TestDataRecord> {
1077+
let degraded: Vec<TestDataRecord> = measurements
1078+
.into_iter()
1079+
.map(|mut record| {
1080+
record.horizontal_accuracy *= factor;
1081+
record.vertical_accuracy *= factor;
1082+
record.speed_accuracy *= factor;
1083+
record.bearing_accuracy *= factor;
1084+
record
1085+
})
1086+
.collect();
1087+
degraded
1088+
}
1089+
10661090
#[cfg(test)]
10671091
mod tests {
10681092
use super::*;

0 commit comments

Comments
 (0)