From ac9d5f8a5c477715fd465950a3c150cf6bbf42af Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Tue, 10 Apr 2018 02:26:52 -0700 Subject: [PATCH] AP_NavEKF: Make the status unions use bool, add static asserts --- libraries/AP_NavEKF/AP_Nav_Common.h | 56 +++++++++++++++-------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/libraries/AP_NavEKF/AP_Nav_Common.h b/libraries/AP_NavEKF/AP_Nav_Common.h index 72ba494756..826ec91e79 100644 --- a/libraries/AP_NavEKF/AP_Nav_Common.h +++ b/libraries/AP_NavEKF/AP_Nav_Common.h @@ -18,42 +18,46 @@ union nav_filter_status { struct { - uint16_t attitude : 1; // 0 - true if attitude estimate is valid - uint16_t horiz_vel : 1; // 1 - true if horizontal velocity estimate is valid - uint16_t vert_vel : 1; // 2 - true if the vertical velocity estimate is valid - uint16_t horiz_pos_rel : 1; // 3 - true if the relative horizontal position estimate is valid - uint16_t horiz_pos_abs : 1; // 4 - true if the absolute horizontal position estimate is valid - uint16_t vert_pos : 1; // 5 - true if the vertical position estimate is valid - uint16_t terrain_alt : 1; // 6 - true if the terrain height estimate is valid - uint16_t const_pos_mode : 1; // 7 - true if we are in const position mode - uint16_t pred_horiz_pos_rel : 1; // 8 - true if filter expects it can produce a good relative horizontal position estimate - used before takeoff - uint16_t pred_horiz_pos_abs : 1; // 9 - true if filter expects it can produce a good absolute horizontal position estimate - used before takeoff - uint16_t takeoff_detected : 1; // 10 - true if optical flow takeoff has been detected - uint16_t takeoff : 1; // 11 - true if filter is compensating for baro errors during takeoff - uint16_t touchdown : 1; // 12 - true if filter is compensating for baro errors during touchdown - uint16_t using_gps : 1; // 13 - true if we are using GPS position - uint16_t gps_glitching : 1; // 14 - true if GPS glitching is affecting navigation accuracy + bool attitude : 1; // 0 - true if attitude estimate is valid + bool horiz_vel : 1; // 1 - true if horizontal velocity estimate is valid + bool vert_vel : 1; // 2 - true if the vertical velocity estimate is valid + bool horiz_pos_rel : 1; // 3 - true if the relative horizontal position estimate is valid + bool horiz_pos_abs : 1; // 4 - true if the absolute horizontal position estimate is valid + bool vert_pos : 1; // 5 - true if the vertical position estimate is valid + bool terrain_alt : 1; // 6 - true if the terrain height estimate is valid + bool const_pos_mode : 1; // 7 - true if we are in const position mode + bool pred_horiz_pos_rel : 1; // 8 - true if filter expects it can produce a good relative horizontal position estimate - used before takeoff + bool pred_horiz_pos_abs : 1; // 9 - true if filter expects it can produce a good absolute horizontal position estimate - used before takeoff + bool takeoff_detected : 1; // 10 - true if optical flow takeoff has been detected + bool takeoff : 1; // 11 - true if filter is compensating for baro errors during takeoff + bool touchdown : 1; // 12 - true if filter is compensating for baro errors during touchdown + bool using_gps : 1; // 13 - true if we are using GPS position + bool gps_glitching : 1; // 14 - true if GPS glitching is affecting navigation accuracy } flags; uint16_t value; }; +static_assert(sizeof(uint16_t) == sizeof(nav_filter_status), "nav_filter_status must be uint16_t"); + union nav_gps_status { struct { - uint16_t bad_sAcc : 1; // 0 - true if reported gps speed accuracy is insufficient to start using GPS - uint16_t bad_hAcc : 1; // 1 - true if reported gps horizontal position accuracy is insufficient to start using GPS - uint16_t bad_yaw : 1; // 2 - true if EKF yaw errors are too large to start using GPS - uint16_t bad_sats : 1; // 3 - true if the number of satellites is insufficient to start using GPS - uint16_t bad_VZ : 1; // 4 - true if the vertical velocity is inconsistent with the inertial/baro - uint16_t bad_horiz_drift : 1; // 5 - true if the GPS horizontal position is drifting (this check assumes vehicle is static) - uint16_t bad_hdop : 1; // 6 - true if the reported HDoP is insufficient to start using GPS - uint16_t bad_vert_vel : 1; // 7 - true if the GPS vertical speed is too large to start using GPS (this check assumes vehicle is static) - uint16_t bad_fix : 1; // 8 - true if the GPS is not providing a 3D fix - uint16_t bad_horiz_vel : 1; // 9 - true if the GPS horizontal speed is excessive (this check assumes the vehicle is static) - uint16_t bad_vAcc : 1; // 10 - true if reported gps vertical position accuracy is insufficient to start using GPS + bool bad_sAcc : 1; // 0 - true if reported gps speed accuracy is insufficient to start using GPS + bool bad_hAcc : 1; // 1 - true if reported gps horizontal position accuracy is insufficient to start using GPS + bool bad_yaw : 1; // 2 - true if EKF yaw errors are too large to start using GPS + bool bad_sats : 1; // 3 - true if the number of satellites is insufficient to start using GPS + bool bad_VZ : 1; // 4 - true if the vertical velocity is inconsistent with the inertial/baro + bool bad_horiz_drift : 1; // 5 - true if the GPS horizontal position is drifting (this check assumes vehicle is static) + bool bad_hdop : 1; // 6 - true if the reported HDoP is insufficient to start using GPS + bool bad_vert_vel : 1; // 7 - true if the GPS vertical speed is too large to start using GPS (this check assumes vehicle is static) + bool bad_fix : 1; // 8 - true if the GPS is not providing a 3D fix + bool bad_horiz_vel : 1; // 9 - true if the GPS horizontal speed is excessive (this check assumes the vehicle is static) + bool bad_vAcc : 1; // 10 - true if reported gps vertical position accuracy is insufficient to start using GPS } flags; uint16_t value; }; +static_assert(sizeof(uint16_t) == sizeof(nav_gps_status), "nav_gps_status must be uint16_t"); + /* structure to hold EKF timing statistics */