Skip to content

Commit

Permalink
AP_NavEKF3: ensure EK3 does not read GPS when disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed May 29, 2024
1 parent e27dea7 commit 7f42611
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions libraries/AP_NavEKF3/AP_NavEKF3_Measurements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ void NavEKF3_core::readGpsData()
// check for new GPS data
const auto &gps = dal.gps();

if (frontend->sources.getPosXYSource() != AP_NavEKF_Source::SourceXY::GPS) {
// don't read GPS data when disabled in the current source set
return;
}

// limit update rate to avoid overflowing the FIFO buffer
if (gps.last_message_time_ms(selected_gps) - lastTimeGpsReceived_ms <= frontend->sensorIntervalMin_ms) {
return;
Expand Down
6 changes: 4 additions & 2 deletions libraries/AP_NavEKF3/AP_NavEKF3_Outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ bool NavEKF3_core::getPosNE(Vector2f &posNE) const
// In constant position mode the EKF position states are at the origin, so we cannot use them as a position estimate
if(validOrigin) {
auto &gps = dal.gps();
if ((gps.status(selected_gps) >= AP_DAL_GPS::GPS_OK_FIX_2D)) {
if (frontend->sources.getPosXYSource() == AP_NavEKF_Source::SourceXY::GPS
&& gps.status(selected_gps) >= AP_DAL_GPS::GPS_OK_FIX_2D) {
// If the origin has been set and we have GPS, then return the GPS position relative to the origin
const Location &gpsloc = gps.location(selected_gps);
posNE = public_origin.get_distance_NE_ftype(gpsloc).tofloat();
Expand Down Expand Up @@ -344,7 +345,8 @@ bool NavEKF3_core::getLLH(Location &loc) const
bool NavEKF3_core::getGPSLLH(Location &loc) const
{
const auto &gps = dal.gps();
if ((gps.status(selected_gps) >= AP_DAL_GPS::GPS_OK_FIX_3D)) {
if (frontend->sources.getPosXYSource() == AP_NavEKF_Source::SourceXY::GPS &&
gps.status(selected_gps) >= AP_DAL_GPS::GPS_OK_FIX_3D) {
loc = gps.location(selected_gps);
return true;
}
Expand Down

0 comments on commit 7f42611

Please sign in to comment.