From 04844a04ed5e4a99992e672fb99c0f57fbe24b38 Mon Sep 17 00:00:00 2001 From: bresch Date: Tue, 16 Feb 2021 15:21:36 +0100 Subject: [PATCH] ekf control: move time_last_in_air/on_ground out of GPS control logic --- EKF/control.cpp | 9 --------- EKF/ekf.h | 2 -- EKF/estimator_interface.h | 13 ++++++++++++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/EKF/control.cpp b/EKF/control.cpp index 1b7926120b..92d40d0131 100644 --- a/EKF/control.cpp +++ b/EKF/control.cpp @@ -120,8 +120,6 @@ void Ekf::controlFusionModes() _delta_time_baro_us = _baro_sample_delayed.time_us - _delta_time_baro_us; } - - { // Get range data from buffer and check validity const bool is_rng_data_ready = _range_buffer.pop_first_older_than(_imu_sample_delayed.time_us, _range_sensor.getSampleAddress()); @@ -599,13 +597,6 @@ void Ekf::controlGpsFusion() could have been caused by bad GPS. */ - if (!_control_status.flags.in_air) { - _time_last_on_ground_us = _time_last_imu; - - } else { - _time_last_in_air = _time_last_imu; - } - const bool recent_takeoff_nav_failure = _control_status.flags.in_air && !isTimedOut(_time_last_on_ground_us, 30000000) && isTimedOut(_time_last_hor_vel_fuse, _params.EKFGSF_reset_delay) && diff --git a/EKF/ekf.h b/EKF/ekf.h index 55b9de04b1..e2f379eabb 100644 --- a/EKF/ekf.h +++ b/EKF/ekf.h @@ -959,8 +959,6 @@ private: EKFGSF_yaw _yawEstimator; int64_t _ekfgsf_yaw_reset_time{0}; ///< timestamp of last emergency yaw reset (uSec) - uint64_t _time_last_on_ground_us{0}; ///< last time we were on the ground (uSec) - uint64_t _time_last_in_air{0}; ///< last time we were in air (uSec) bool _do_ekfgsf_yaw_reset{false}; // true when an emergency yaw reset has been requested uint8_t _ekfgsf_yaw_reset_count{0}; // number of times the yaw has been reset to the EKF-GSF estimate diff --git a/EKF/estimator_interface.h b/EKF/estimator_interface.h index 2b78a50b16..f77f0eebbd 100644 --- a/EKF/estimator_interface.h +++ b/EKF/estimator_interface.h @@ -94,7 +94,16 @@ public: parameters *getParamHandle() { return &_params; } // set vehicle landed status data - void set_in_air_status(bool in_air) { _control_status.flags.in_air = in_air; } + void set_in_air_status(bool in_air) + { + if (!in_air) { + _time_last_on_ground_us = _time_last_imu; + + } else { + _time_last_in_air = _time_last_imu; + } + _control_status.flags.in_air = in_air; + } // return true if the attitude is usable bool attitude_valid() const { return ISFINITE(_output_new.quat_nominal(0)) && _control_status.flags.tilt_align; } @@ -320,6 +329,8 @@ protected: // [1] Vertical position drift rate (m/s) // [2] Filtered horizontal velocity (m/s) uint64_t _time_last_move_detect_us{0}; // timestamp of last movement detection event in microseconds + uint64_t _time_last_on_ground_us{0}; ///< last time we were on the ground (uSec) + uint64_t _time_last_in_air{0}; ///< last time we were in air (uSec) bool _gps_drift_updated{false}; // true when _gps_drift_metrics has been updated and is ready for retrieval // data buffer instances