mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-02 14:30:59 +08:00
fix(ekf2): prevent emergency yaw reset to unconverged EKF-GSF after in-flight GNSS re-enabling
This commit is contained in:
1 parent
fe87271f9c
commit
1cfd3f8895
3 files changed
+38
-2
No files matched your search
@@ -43,7 +43,7 @@ void Ekf::controlGpsFusion(const imuSample &imu_delayed)
|
||||
{
|
||||
_fc.gps.available = (_params.ekf2_gps_ctrl != 0);
|
||||
|
||||
if (!_gps_buffer || !_fc.gps.intended()) {
|
||||
if (!_gps_buffer) {
|
||||
stopGnssFusion();
|
||||
return;
|
||||
}
|
||||
@@ -52,11 +52,15 @@ void Ekf::controlGpsFusion(const imuSample &imu_delayed)
|
||||
_yawEstimator.setGyroBias(getGyroBias(), _control_status.flags.vehicle_at_rest);
|
||||
}
|
||||
|
||||
// run EKF-GSF yaw estimator once per imu_delayed update
|
||||
_yawEstimator.predict(imu_delayed.delta_ang, imu_delayed.delta_ang_dt,
|
||||
imu_delayed.delta_vel, imu_delayed.delta_vel_dt,
|
||||
(_control_status.flags.in_air && !_control_status.flags.vehicle_at_rest));
|
||||
|
||||
if (!_fc.gps.intended()) {
|
||||
stopGnssFusion();
|
||||
return;
|
||||
}
|
||||
|
||||
_gps_intermittent = !isNewestSampleRecent(_time_last_gps_buffer_push, 2 * GNSS_MAX_INTERVAL);
|
||||
|
||||
// check for arrival of new sensor data at the fusion time horizon
|
||||
@@ -387,6 +391,26 @@ void Ekf::controlGnssYawEstimator(estimator_aid_source3d_s &aid_src_vel)
|
||||
|
||||
_yawEstimator.fuseVelocity(vel_xy, vel_accuracy, _control_status.flags.in_air);
|
||||
|
||||
if (_yawEstimator.isActive()) {
|
||||
if (_time_yaw_estimator_activated_us == 0) {
|
||||
_time_yaw_estimator_activated_us = _time_delayed_us;
|
||||
_yaw_estimator_restarted_in_air = _control_status.flags.in_air
|
||||
&& _yaw_estimator_was_active_in_air;
|
||||
}
|
||||
|
||||
if (_control_status.flags.in_air) {
|
||||
_yaw_estimator_was_active_in_air = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
_time_yaw_estimator_activated_us = 0;
|
||||
}
|
||||
|
||||
if (!_control_status.flags.in_air) {
|
||||
_yaw_estimator_was_active_in_air = false;
|
||||
_yaw_estimator_restarted_in_air = false;
|
||||
}
|
||||
|
||||
// Try to align yaw using estimate if available
|
||||
if (((_params.ekf2_gps_ctrl & static_cast<int32_t>(GnssCtrl::VEL))
|
||||
|| (_params.ekf2_gps_ctrl & static_cast<int32_t>(GnssCtrl::HPOS)))
|
||||
@@ -475,6 +499,7 @@ void Ekf::stopGnssFusion()
|
||||
#endif // CONFIG_EKF2_GNSS_YAW
|
||||
|
||||
_yawEstimator.reset();
|
||||
_time_yaw_estimator_activated_us = 0;
|
||||
}
|
||||
|
||||
void Ekf::stopGnssVelFusion()
|
||||
@@ -524,6 +549,12 @@ bool Ekf::isYawFailure() const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_yaw_estimator_restarted_in_air
|
||||
&& ((_time_yaw_estimator_activated_us == 0)
|
||||
|| !isTimedOut(_time_yaw_estimator_activated_us, _params.EKFGSF_min_active_time))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const float euler_yaw = getEulerYaw(_R_to_earth);
|
||||
const float yaw_error = wrap_pi(euler_yaw - _yawEstimator.getYaw());
|
||||
|
||||
|
||||
@@ -394,6 +394,7 @@ struct parameters {
|
||||
float ekf2_gsf_tas{15.0f}; ///< default airspeed value assumed during fixed wing flight if no airspeed measurement available (m/s)
|
||||
const unsigned EKFGSF_reset_delay{1000000}; ///< Number of uSec of bad innovations on main filter in immediate post-takeoff phase before yaw is reset to EKF-GSF value
|
||||
const float EKFGSF_yaw_err_max{0.262f}; ///< Composite yaw 1-sigma uncertainty threshold used to check for convergence (rad)
|
||||
const unsigned EKFGSF_min_active_time{10'000'000}; ///< Minimum period of continuous EKF-GSF velocity fusion after an in-flight restart
|
||||
|
||||
#endif // CONFIG_EKF2_GNSS
|
||||
|
||||
|
||||
@@ -969,6 +969,10 @@ private:
|
||||
// yaw estimator instance
|
||||
EKFGSF_yaw _yawEstimator{};
|
||||
|
||||
uint64_t _time_yaw_estimator_activated_us{0};
|
||||
bool _yaw_estimator_was_active_in_air{false};
|
||||
bool _yaw_estimator_restarted_in_air{false};
|
||||
|
||||
#endif // CONFIG_EKF2_GNSS
|
||||
|
||||
#if defined(CONFIG_EKF2_RANGING_BEACON)
|
||||
|
||||
Reference in new issue
Block a user