@@ -43,7 +43,8 @@ pub trait MeasurementModel {
4343}
4444/// GPS position measurement model
4545#[ derive( Clone , Debug , Default ) ]
46- pub struct GPSPositionMeasurement { // <-- Check this model for degree/radian consistency
46+ pub struct GPSPositionMeasurement {
47+ // <-- Check this model for degree/radian consistency
4748 /// latitude in degrees
4849 pub latitude : f64 ,
4950 /// longitude in degrees
@@ -183,9 +184,9 @@ impl MeasurementModel for GPSPositionAndVelocityMeasurement {
183184 }
184185}
185186
186- /// A relative relative altitude measurement derived from barometric pressure.
187- /// Note that this measurement model is an altitude measurement derived from
188- /// a barometric altimeter and not a direct calculation of altitude from the
187+ /// A relative relative altitude measurement derived from barometric pressure.
188+ /// Note that this measurement model is an altitude measurement derived from
189+ /// a barometric altimeter and not a direct calculation of altitude from the
189190/// barometric pressure.
190191#[ derive( Clone , Debug , Default ) ]
191192pub struct RelativeAltitudeMeasurement {
@@ -205,7 +206,8 @@ impl MeasurementModel for RelativeAltitudeMeasurement {
205206 DMatrix :: from_diagonal ( & DVector :: from_vec ( vec ! [ 5.0 ] ) ) // 1 mm noise
206207 }
207208 fn get_sigma_points ( & self , state_sigma_points : & DMatrix < f64 > ) -> DMatrix < f64 > {
208- let mut measurement_sigma_points = DMatrix :: < f64 > :: zeros ( self . get_dimension ( ) , state_sigma_points. ncols ( ) ) ;
209+ let mut measurement_sigma_points =
210+ DMatrix :: < f64 > :: zeros ( self . get_dimension ( ) , state_sigma_points. ncols ( ) ) ;
209211 for ( i, sigma_point) in state_sigma_points. column_iter ( ) . enumerate ( ) {
210212 measurement_sigma_points[ ( 0 , i) ] = sigma_point[ 2 ] ;
211213 }
@@ -244,7 +246,7 @@ pub struct StrapdownParams {
244246/// Note that, internally, angles are always stored in radians (both for the attitude and the position),
245247/// however, the user can choose to convert them to degrees when retrieving the state vector and the UKF
246248/// and underlying strapdown state can be constructed from data in degrees by using the boolean `in_degrees`
247- /// toggle where applicable. Generally speaking, the design of this crate is such that methods that expect
249+ /// toggle where applicable. Generally speaking, the design of this crate is such that methods that expect
248250/// a WGS84 coordinate (e.g. latitude or longitude) will expect the value in degrees, whereas trigonometric
249251/// functions (e.g. sine, cosine, tangent) will expect the value in radians.
250252pub struct UKF {
@@ -370,7 +372,7 @@ impl UKF {
370372 lambda,
371373 state_size,
372374 weights_mean,
373- weights_cov
375+ weights_cov,
374376 }
375377 }
376378 /// Predicts the state using the strapdown equations and IMU measurements.
@@ -389,20 +391,20 @@ impl UKF {
389391 let mut sigma_points = self . get_sigma_points ( ) ;
390392 for i in 0 ..sigma_points. ncols ( ) {
391393 let mut sigma_point_vec = sigma_points. column ( i) . clone_owned ( ) ;
392- let mut state = StrapdownState {
393- latitude : sigma_point_vec[ 0 ] ,
394- longitude : sigma_point_vec[ 1 ] ,
395- altitude : sigma_point_vec[ 2 ] ,
396- velocity_north : sigma_point_vec[ 3 ] ,
397- velocity_east : sigma_point_vec[ 4 ] ,
398- velocity_down : sigma_point_vec[ 5 ] ,
394+ let mut state = StrapdownState {
395+ latitude : sigma_point_vec[ 0 ] ,
396+ longitude : sigma_point_vec[ 1 ] ,
397+ altitude : sigma_point_vec[ 2 ] ,
398+ velocity_north : sigma_point_vec[ 3 ] ,
399+ velocity_east : sigma_point_vec[ 4 ] ,
400+ velocity_down : sigma_point_vec[ 5 ] ,
399401 attitude : Rotation3 :: from_euler_angles (
400- sigma_point_vec[ 6 ] ,
401- sigma_point_vec[ 7 ] ,
402- sigma_point_vec[ 8 ]
402+ sigma_point_vec[ 6 ] ,
403+ sigma_point_vec[ 7 ] ,
404+ sigma_point_vec[ 8 ] ,
403405 ) ,
404406 coordinate_convention : true ,
405- } ;
407+ } ;
406408 forward ( & mut state, imu_data, dt) ;
407409 // Update the sigma point with the new state
408410 sigma_point_vec[ 0 ] = state. latitude ;
@@ -478,10 +480,7 @@ impl UKF {
478480 /// # Arguments
479481 /// * `measurement` - The measurement vector to update the state with.
480482 /// * `measurement_sigma_points` - The measurement sigma points to use for the update.
481- pub fn update < M : MeasurementModel > (
482- & mut self ,
483- measurement : M ,
484- ) {
483+ pub fn update < M : MeasurementModel > ( & mut self , measurement : M ) {
485484 let measurement_sigma_points = measurement. get_sigma_points ( & self . get_sigma_points ( ) ) ;
486485 // Calculate expected measurement
487486 let mut z_hat = DVector :: < f64 > :: zeros ( measurement. get_dimension ( ) ) ;
@@ -498,7 +497,8 @@ impl UKF {
498497 s += measurement. get_noise ( ) ;
499498 // Calculate the cross-covariance
500499 let sigma_points = self . get_sigma_points ( ) ;
501- let mut cross_covariance = DMatrix :: < f64 > :: zeros ( self . state_size , measurement. get_dimension ( ) ) ;
500+ let mut cross_covariance =
501+ DMatrix :: < f64 > :: zeros ( self . state_size , measurement. get_dimension ( ) ) ;
502502 for ( i, measurement_sigma_point) in measurement_sigma_points. column_iter ( ) . enumerate ( ) {
503503 let measurement_diff = measurement_sigma_point - & z_hat;
504504 let state_diff = sigma_points. column ( i) - & self . mean_state ;
@@ -525,7 +525,9 @@ impl UKF {
525525 let I = DMatrix :: < f64 > :: identity ( self . state_size , self . state_size ) ;
526526 let P = self . covariance . clone ( ) ;
527527 //self.covariance -= &k * s * &k.transpose();
528- self . covariance = ( & I - & k * & cross_covariance) * & P * ( & I - & k * & cross_covariance) . transpose ( ) + & k * measurement. get_noise ( ) * & k. transpose ( ) ;
528+ self . covariance =
529+ ( & I - & k * & cross_covariance) * & P * ( & I - & k * & cross_covariance) . transpose ( )
530+ + & k * measurement. get_noise ( ) * & k. transpose ( ) ;
529531 }
530532}
531533#[ derive( Clone , Debug , Default ) ]
@@ -667,8 +669,8 @@ impl ParticleFilter {
667669/// Tests
668670#[ cfg( test) ]
669671mod tests {
670- use crate :: earth;
671672 use super :: * ;
673+ use crate :: earth;
672674 use assert_approx_eq:: assert_approx_eq;
673675 use nalgebra:: Vector3 ;
674676
@@ -706,10 +708,7 @@ mod tests {
706708 BETA ,
707709 KAPPA ,
708710 ) ;
709- assert_eq ! (
710- ukf. mean_state. len( ) ,
711- 18
712- ) ;
711+ assert_eq ! ( ukf. mean_state. len( ) , 18 ) ;
713712 let wms = ukf. weights_mean ;
714713 let wcs = ukf. weights_cov ;
715714 assert_eq ! ( wms. len( ) , ( 2 * ukf. state_size) + 1 ) ;
@@ -777,12 +776,12 @@ mod tests {
777776 ukf. mean_state. len( ) == 15 //+ measurement_bias.len()
778777 ) ;
779778 let measurement = GPSPositionMeasurement {
780- latitude : 0.0 ,
781- longitude : 0.0 ,
782- altitude : 0.0 ,
783- horizontal_noise_std : 1e-3 ,
784- vertical_noise_std : 1e-3 ,
785- } ;
779+ latitude : 0.0 ,
780+ longitude : 0.0 ,
781+ altitude : 0.0 ,
782+ horizontal_noise_std : 1e-3 ,
783+ vertical_noise_std : 1e-3 ,
784+ } ;
786785 ukf. update ( measurement) ;
787786 // Check that the state has not changed
788787 assert_approx_eq ! ( ukf. mean_state[ 0 ] , 0.0 , 1e-3 ) ;
0 commit comments