Skip to content

Commit 37a7bf4

Browse files
committed
formating pass
1 parent 9ac97cc commit 37a7bf4

4 files changed

Lines changed: 32 additions & 31 deletions

File tree

core/src/earth.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
// Rotations can be handled using nalgebra's Rotation3 type, which can be converted to a DCM using the into() method. The Rotation3 type can be created from
4343
// Euler angles for the body to local-level frame rotation. The inverse of the Rotation3 type can be used to convert from the local-level frame to the body frame.
4444
// ----------
45+
use crate::{wrap_latitude, wrap_to_180};
4546
use ::nalgebra::{Matrix3, Vector3};
4647
use ::nav_types::{ECEF, WGS84};
47-
use crate::{wrap_to_180, wrap_latitude};
4848

4949
// Earth constants (WGS84)
5050
/// Earth's rotation rate rad/s ($\omega_{ie}$)
@@ -317,8 +317,8 @@ pub fn gravity(latitude: &f64, altitude: &f64) -> f64 {
317317
/// with the rotational effects of the Earth to calculate the effective gravity vector. This
318318
/// differs from the gravity scalar in that it includes the centrifugal effects of the Earth's
319319
/// rotation.
320-
///
321-
/// *Note:* Local level frame coordintaes are odd and mixed and can be defined as North, East,
320+
///
321+
/// *Note:* Local level frame coordintaes are odd and mixed and can be defined as North, East,
322322
/// Down (NED) or East, North, Up (ENU). This function uses the ENU convention, thus gravity acts
323323
/// along the negative Z-axis (downward) in the local-level frame.
324324
///
@@ -650,7 +650,6 @@ mod tests {
650650
assert_approx_eq!(grav[0], 0.0);
651651
assert_approx_eq!(grav[1], 0.0);
652652
assert_approx_eq!(grav[2], GP, 1e-2);
653-
654653
}
655654
#[test]
656655
fn magnetic_radial_field() {

core/src/filter.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl UKF {
467467
let mut cov_bar = DMatrix::<f64>::zeros(self.state_size, self.state_size);
468468
// Update the covariance through a naive loop
469469
for (i, sigma_point) in sigma_points.iter().enumerate() {
470-
//let sigma_point = &sigma_points[i];
470+
//let sigma_point = &sigma_points[i];
471471
let weight_cov = self.weights_cov[i];
472472
let diff = sigma_point.to_vector(false) - &mu_bar;
473473
cov_bar += weight_cov * (&diff * &diff.transpose());
@@ -577,17 +577,16 @@ impl UKF {
577577
sigma_points
578578
}
579579
/// Convert a Vec<SigmaPoint> to a DMatrix<f64>
580-
pub fn sigma_points_as_matrix(
581-
&self,
582-
) -> DMatrix<f64> {
583-
let p = (self.state_size as f64 + self.lambda) * self.covariance.clone();
580+
pub fn sigma_points_as_matrix(&self) -> DMatrix<f64> {
581+
let p = (self.state_size as f64 + self.lambda) * self.covariance.clone();
584582
let sqrt_p = matrix_square_root(&p);
585583
let mu = self.mean_state.clone();
586584
let mut pts = DMatrix::<f64>::zeros(self.state_size, 2 * self.state_size + 1);
587585
pts.column_mut(0).copy_from(&mu);
588586
for i in 0..sqrt_p.ncols() {
589-
pts.column_mut(i+1).copy_from(&(&mu + sqrt_p.column(i)));
590-
pts.column_mut(i+1+self.state_size).copy_from(&(&mu - sqrt_p.column(i)));
587+
pts.column_mut(i + 1).copy_from(&(&mu + sqrt_p.column(i)));
588+
pts.column_mut(i + 1 + self.state_size)
589+
.copy_from(&(&mu - sqrt_p.column(i)));
591590
}
592591
pts
593592
}
@@ -921,7 +920,7 @@ mod tests {
921920
// test forward propagation
922921
// Test at rest
923922
let imu_data = IMUData {
924-
accel: Vector3::new(0.0, 0.0, earth::gravity(&0.0, &0.0)),
923+
accel: Vector3::new(0.0, 0.0, earth::gravity(&0.0, &0.0)),
925924
gyro: Vector3::new(0.0, 0.0, 0.0),
926925
};
927926
let dt = 1.0;
@@ -1022,7 +1021,7 @@ mod tests {
10221021
assert_approx_eq!(wcs[0], wc_0, 1e-6);
10231022
for i in 1..wms.len() {
10241023
assert_approx_eq!(wms[i], w_i, 1e-6);
1025-
assert_approx_eq!(wcs[i], w_i, 1e-6);
1024+
assert_approx_eq!(wcs[i], w_i, 1e-6);
10261025
}
10271026
}
10281027
#[test]
@@ -1062,7 +1061,7 @@ mod tests {
10621061
);
10631062
let sigma_points = ukf.get_sigma_points();
10641063
assert_eq!(sigma_points.len(), (2 * ukf.state_size) + 1);
1065-
1064+
10661065
let mu = ukf.sigma_points_as_matrix() * ukf.weights_mean;
10671066
println!("mu: {}", mu);
10681067
assert_eq!(mu.nrows(), ukf.state_size);
@@ -1114,9 +1113,10 @@ mod tests {
11141113
);
11151114
let dt = 1.0;
11161115
let imu_data = IMUData::new_from_vec(
1117-
vec![0.0, 0.0, earth::gravity(&0.0, &0.0)],
1118-
vec![0.0, 0.0, 0.0]);
1119-
1116+
vec![0.0, 0.0, earth::gravity(&0.0, &0.0)],
1117+
vec![0.0, 0.0, 0.0],
1118+
);
1119+
11201120
ukf.predict(&imu_data, dt);
11211121
assert!(
11221122
ukf.mean_state.len()
@@ -1171,8 +1171,9 @@ mod tests {
11711171
#[test]
11721172
fn ukf_hover() {
11731173
let imu_data = IMUData::new_from_vec(
1174-
vec![0.0, 0.0, earth::gravity(&0.0, &0.0)],
1175-
vec![0.0, 0.0, 0.0]);
1174+
vec![0.0, 0.0, earth::gravity(&0.0, &0.0)],
1175+
vec![0.0, 0.0, 0.0],
1176+
);
11761177
let position = vec![0.0, 0.0, 0.0];
11771178
let velocity = [0.0, 0.0, 0.0];
11781179
let attitude = [0.0, 0.0, 0.0];
@@ -1209,8 +1210,8 @@ mod tests {
12091210
let measurement_noise = ukf.position_measurement_noise(true);
12101211
let measurement = DVector::from_vec(position.clone());
12111212
//for _i in 0..60 {
1212-
ukf.predict(&imu_data, dt);
1213-
//ukf.update(&measurement, &measurement_sigma_points, &measurement_noise);
1213+
ukf.predict(&imu_data, dt);
1214+
//ukf.update(&measurement, &measurement_sigma_points, &measurement_noise);
12141215
//}
12151216
assert_approx_eq!(ukf.mean_state[0], position[0], 1e-6);
12161217
assert_approx_eq!(ukf.mean_state[1], position[1], 1e-6);

core/src/sim.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,9 @@ pub fn closed_loop(records: &[TestDataRecord]) -> Vec<NavigationResult> {
574574
let total: usize = records.len();
575575
let mut i: usize = 1;
576576
for record in records.iter().skip(1) {
577-
println!("======================================================================================================");
577+
println!(
578+
"======================================================================================================"
579+
);
578580
i = print_progress(i, total, 10);
579581
print_ukf(&ukf, record);
580582
// Calculate time difference from the previous record

core/src/strapdown.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,12 @@ impl StrapdownState {
567567
let gravity = Vector3::new(
568568
0.0,
569569
0.0,
570-
earth::gravity(&self.latitude.to_degrees(), &self.altitude)
570+
earth::gravity(&self.latitude.to_degrees(), &self.altitude),
571571
);
572572
//let accel = &gravity;
573573
//println!("[StrapdownState::velocity_update] position: [{:?}, {:?}, {:?}]", self.latitude.to_degrees(), self.longitude.to_degrees(), self.altitude);
574574
//println!("[StrapdownState::velocity_update] gravity vector: [{:?}, {:?}, {:?}] | Gravity scalar {:?}", accel[0], accel[1], accel[2], (accel[0].powi(2) + accel[1].powi(2) + accel[2].powi(2)).sqrt());
575-
575+
576576
velocity + (f - gravity - r * (transport_rate + 2.0 * rotation_rate) * velocity) * dt
577577
}
578578
}
@@ -698,12 +698,12 @@ pub fn add(a: f64, b: f64) -> f64 {
698698
a + b
699699
}
700700
/// Wrap latitude to the range -90 to 90 degrees
701-
///
701+
///
702702
/// This function is generic and can be used with any type that implements the necessary traits.
703-
/// This function is useful for ensuring that latitude values remain within the valid range for
703+
/// This function is useful for ensuring that latitude values remain within the valid range for
704704
/// WGS84 coordinates. Keep in mind that the local level frame (NED/ENU) is typically used for
705-
/// navigation and positioning in middling latitudes.
706-
///
705+
/// navigation and positioning in middling latitudes.
706+
///
707707
/// # Arguments
708708
/// * `latitude` - The latitude to be wrapped, which can be of any type that implements the necessary traits.
709709
/// # Returns
@@ -847,15 +847,15 @@ mod tests {
847847
assert_eq!(state.velocity_down, 0.0);
848848
let imu_data = IMUData::new_from_vector(
849849
Vector3::new(0.0, 0.0, earth::gravity(&0.0, &0.0)), // free fall acceleration in m/s^2
850-
Vector3::new(0.0, 0.0, 0.0), // No rotation
850+
Vector3::new(0.0, 0.0, 0.0), // No rotation
851851
);
852852
let dt = 1.0; // Example time step in seconds
853853
state.forward(&imu_data, dt);
854854
// After a forward step, the state should still be at rest
855855
assert_approx_eq!(state.latitude, 0.0, 1e-6);
856856
assert_approx_eq!(state.longitude, 0.0, 1e-6);
857857
assert_approx_eq!(state.altitude, 0.0, 0.1);
858-
assert_approx_eq!(state.velocity_north, 0.0,1e-3);
858+
assert_approx_eq!(state.velocity_north, 0.0, 1e-3);
859859
assert_approx_eq!(state.velocity_east, 0.0, 1e-3);
860860
assert_approx_eq!(state.velocity_down, 0.0, 0.1);
861861
//assert_approx_eq!(state.attitude, Rotation3::identity(), 1e-3);
@@ -869,7 +869,6 @@ mod tests {
869869
assert_approx_eq!(attitude[(2, 0)], 0.0, 1e-3);
870870
assert_approx_eq!(attitude[(2, 1)], 0.0, 1e-3);
871871
assert_approx_eq!(attitude[(2, 2)], 0.0, 1e-3);
872-
873872
}
874873
#[test]
875874
fn test_wrap_to_180() {

0 commit comments

Comments
 (0)