Skip to content

Commit 11cd51c

Browse files
committed
EKF: allow emergency reset in GNSS yaw and EV yaw aiding modes
1 parent 4ebfbc6 commit 11cd51c

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

src/modules/ekf2/EKF/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ union warning_event_status_u {
552552
bool stopping_mag_use : 1; ///< 8 - true when the filter has detected bad magnetometer data and is stopping further use of the magnetomer data
553553
bool vision_data_stopped : 1; ///< 9 - true when the vision system data has stopped for a significant time period
554554
bool emergency_yaw_reset_mag_stopped : 1; ///< 10 - true when the filter has detected bad magnetometer data, has reset the yaw to anothter source of data and has stopped further use of the magnetomer data
555+
bool emergency_yaw_reset_gps_yaw_stopped: 1; ///< 11 - true when the filter has detected bad GNSS yaw data, has reset the yaw to anothter source of data and has stopped further use of the GNSS yaw data
555556
} flags;
556557
uint32_t value;
557558
};

src/modules/ekf2/EKF/control.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,11 @@ void Ekf::controlGpsFusion()
566566

567567
// handle case where we are not currently using GPS, but need to align yaw angle using EKF-GSF before
568568
// we can start using GPS
569-
const bool align_yaw_using_gsf = !_control_status.flags.gps && _do_ekfgsf_yaw_reset
570-
&& isTimedOut(_ekfgsf_yaw_reset_time, 5000000);
569+
const bool align_yaw_using_gsf = !_control_status.flags.yaw_align
570+
&& (_params.mag_fusion_type == MAG_FUSE_TYPE_NONE);
571571

572-
if (align_yaw_using_gsf) {
572+
if ((align_yaw_using_gsf || _do_ekfgsf_yaw_reset)
573+
&& isTimedOut(_ekfgsf_yaw_reset_time, 5000000)){
573574
if (resetYawToEKFGSF()) {
574575
_ekfgsf_yaw_reset_time = _time_last_imu;
575576
_do_ekfgsf_yaw_reset = false;

src/modules/ekf2/EKF/ekf_helper.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,16 +1680,32 @@ bool Ekf::resetYawToEKFGSF()
16801680
_flt_mag_align_start_time = _imu_sample_delayed.time_us;
16811681
_control_status.flags.yaw_align = true;
16821682

1683-
if (_params.mag_fusion_type == MAG_FUSE_TYPE_NONE) {
1683+
const bool is_mag_fusion_active = _control_status.flags.mag_hdg
1684+
|| _control_status.flags.mag_3D;
1685+
const bool is_yaw_aiding_active = is_mag_fusion_active
1686+
|| _control_status.flags.gps_yaw
1687+
|| _control_status.flags.ev_yaw;
1688+
1689+
if (!is_yaw_aiding_active) {
16841690
_information_events.flags.yaw_aligned_to_imu_gps = true;
16851691
ECL_INFO("Yaw aligned using IMU and GPS");
16861692

16871693
} else {
1688-
// stop using the magnetometer in the main EKF otherwise it's fusion could drag the yaw around
1689-
// and cause another navigation failure
1690-
_control_status.flags.mag_fault = true;
1691-
_warning_events.flags.emergency_yaw_reset_mag_stopped = true;
1692-
ECL_WARN("Emergency yaw reset - mag use stopped");
1694+
if (is_mag_fusion_active) {
1695+
// stop using the magnetometer in the main EKF otherwise it's fusion could drag the yaw around
1696+
// and cause another navigation failure
1697+
_control_status.flags.mag_fault = true;
1698+
_warning_events.flags.emergency_yaw_reset_mag_stopped = true;
1699+
1700+
} else if (_control_status.flags.gps_yaw) {
1701+
_is_gps_yaw_faulty = true;
1702+
_warning_events.flags.emergency_yaw_reset_gps_yaw_stopped = true;
1703+
1704+
} else if (_control_status.flags.ev_yaw) {
1705+
_inhibit_ev_yaw_use = true;
1706+
}
1707+
1708+
ECL_WARN("Emergency yaw reset");
16931709
}
16941710

16951711
return true;

src/modules/ekf2/EKF/gps_checks.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,9 @@ bool Ekf::collect_gps(const gps_message &gps)
9191
_mag_strength_gps = get_mag_strength_gauss(lat, lon);
9292

9393
// request a reset of the yaw using the new declination
94-
if (_params.mag_fusion_type == MAG_FUSE_TYPE_NONE) {
95-
// try to reset the yaw using the EKF-GSF yaw estimator
96-
_do_ekfgsf_yaw_reset = true;
97-
_ekfgsf_yaw_reset_time = 0;
98-
99-
} else {
100-
if (!declination_was_valid) {
101-
_mag_yaw_reset_req = true;
102-
}
94+
if ((_params.mag_fusion_type != MAG_FUSE_TYPE_NONE)
95+
&& !declination_was_valid) {
96+
_mag_yaw_reset_req = true;
10397
}
10498

10599
// save the horizontal and vertical position uncertainty of the origin

0 commit comments

Comments
 (0)