Skip to content

Commit 44274da

Browse files
author
Eugene
committed
More disabling of GPS measurements when using externalNav
1 parent 871d542 commit 44274da

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

libraries/AP_NavEKF3/AP_NavEKF3_PosVelFusion.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ void NavEKF3_core::SelectVelPosFusion()
607607

608608
// if we are using GPS, check for a change in receiver and reset position and height
609609
if (gpsDataToFuse && (PV_AidingMode == AID_ABSOLUTE) && (posxy_source == AP_NavEKF_Source::SourceXY::GPS) && (gpsDataDelayed.sensor_idx != last_gps_idx || posxy_source_reset)) {
610-
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "fuse gps 2, %u", gpsDataToFuse);
611610
// mark a source reset as consumed
612611
posxy_source_reset = false;
613612

@@ -844,8 +843,6 @@ void NavEKF3_core::FuseVelPosNED()
844843
varInnovVelPos[3] = P[7][7] + R_OBS_DATA_CHECKS[3];
845844
varInnovVelPos[4] = P[8][8] + R_OBS_DATA_CHECKS[4];
846845

847-
// TODO (EF): enabling this pos check causes conflict with GPS using external nav
848-
if (gpsDataToFuse) {
849846
// Apply an innovation consistency threshold test
850847
// Don't allow test to fail if not navigating and using a constant position
851848
// assumption to constrain tilt errors because innovations can become large
@@ -857,7 +854,7 @@ void NavEKF3_core::FuseVelPosNED()
857854
if (posTestRatio < 1.0f || (PV_AidingMode == AID_NONE)) {
858855
posCheckPassed = true;
859856
lastGpsPosPassTime_ms = imuSampleTime_ms;
860-
} else if ((frontend->_gpsGlitchRadiusMax <= 0) && (PV_AidingMode != AID_NONE)) {
857+
} else if ((gpsDataToFuse && frontend->_gpsGlitchRadiusMax <= 0) && (PV_AidingMode != AID_NONE)) {
861858
// Handle the special case where the glitch radius parameter has been set to a non-positive number.
862859
// The innovation variance is increased to limit the state update to an amount corresponding
863860
// to a test ratio of 1.
@@ -873,8 +870,23 @@ void NavEKF3_core::FuseVelPosNED()
873870
if (posCheckPassed || posTimeout || badIMUdata) {
874871
// if timed out or outside the specified uncertainty radius, reset to the external sensor
875872
// if velocity drift is being constrained, dont reset until gps passes quality checks
876-
const bool posVarianceIsTooLarge = (frontend->_gpsGlitchRadiusMax > 0) && (P[8][8] + P[7][7]) > sq(ftype(frontend->_gpsGlitchRadiusMax));
877-
if ((posTimeout || posVarianceIsTooLarge) && (!velAiding || gpsGoodToAlign)) {
873+
bool posVarianceIsTooLarge = false;
874+
if (extNavDataToFuse)
875+
{
876+
posVarianceIsTooLarge = (P[8][8] + P[7][7]) > sq(ftype(extNavDataDelayed.posErr));
877+
}
878+
else if (gpsDataToFuse)
879+
{
880+
posVarianceIsTooLarge = (frontend->_gpsGlitchRadiusMax > 0) && (P[8][8] + P[7][7]) > sq(ftype(frontend->_gpsGlitchRadiusMax));
881+
}
882+
else
883+
{
884+
// (EF): This triggers on the ground
885+
// TODO (EF): Do we need to handle this case for beacons?
886+
// GCS_SEND_TEXT(MAV_SEVERITY_INFO, "posVarianceIsTooLarge w/o extnav or GPS");
887+
}
888+
889+
if ((posTimeout || posVarianceIsTooLarge) && (!velAiding || (gpsGoodToAlign && gpsDataToFuse))) {
878890
// reset the position to the current external sensor position
879891
ResetPosition(resetDataSource::DEFAULT);
880892

@@ -884,7 +896,19 @@ void NavEKF3_core::FuseVelPosNED()
884896
// Reset the position variances and corresponding covariances to a value that will pass the checks
885897
zeroRows(P,7,8);
886898
zeroCols(P,7,8);
887-
P[7][7] = sq(ftype(0.5f*frontend->_gpsGlitchRadiusMax));
899+
if (extNavDataToFuse)
900+
{
901+
P[7][7] = sq(ftype(0.5f*extNavDataDelayed.posErr));
902+
}
903+
else if (gpsDataToFuse)
904+
{
905+
P[7][7] = sq(ftype(0.5f*frontend->_gpsGlitchRadiusMax));
906+
}
907+
else
908+
{
909+
// (EF): Doesn't seem to trigger
910+
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "reset pos variance w/o extnav or GPS");
911+
}
888912
P[8][8] = P[7][7];
889913

890914
// Reset the normalised innovation to avoid failing the bad fusion tests
@@ -904,7 +928,6 @@ void NavEKF3_core::FuseVelPosNED()
904928
} else {
905929
fusePosData = false;
906930
}
907-
}
908931
}
909932

910933
// Test velocity measurements
@@ -933,7 +956,7 @@ void NavEKF3_core::FuseVelPosNED()
933956
if (velTestRatio < 1.0) {
934957
velCheckPassed = true;
935958
lastVelPassTime_ms = imuSampleTime_ms;
936-
} else if (frontend->_gpsGlitchRadiusMax <= 0) {
959+
} else if (gpsDataToFuse && frontend->_gpsGlitchRadiusMax <= 0) {
937960
// Handle the special case where the glitch radius parameter has been set to a non-positive number.
938961
// The innovation variance is increased to limit the state update to an amount corresponding
939962
// to a test ratio of 1.

libraries/AP_NavEKF3/AP_NavEKF3_core.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,17 @@ void NavEKF3_core::ConstrainVariances()
18941894

18951895
// if vibration affected use sensor observation variances to set a floor on the state variances
18961896
if (badIMUdata) {
1897-
P[6][6] = fmaxF(P[6][6], sq(frontend->_gpsVertVelNoise));
1897+
#if EK3_FEATURE_EXTERNAL_NAV
1898+
if (useExtNavVel) {
1899+
P[6][6] = fmaxF(P[6][6], sq(extNavVelDelayed.err));
1900+
} else if (gpsDataToFuse)
1901+
#endif
1902+
{
1903+
P[6][6] = fmaxF(P[6][6], sq(frontend->_gpsVertVelNoise));
1904+
}
1905+
else {
1906+
// TODO (EF): other vel source case?
1907+
}
18981908
P[9][9] = fmaxF(P[9][9], sq(frontend->_baroAltNoise));
18991909
} else if (P[6][6] < VEL_STATE_MIN_VARIANCE) {
19001910
// handle collapse of the vertical velocity variance
@@ -1912,11 +1922,14 @@ void NavEKF3_core::ConstrainVariances()
19121922
#if EK3_FEATURE_EXTERNAL_NAV
19131923
if (useExtNavVel) {
19141924
P[6][6] = sq(extNavVelDelayed.err);
1915-
} else
1925+
} else if (gpsDataToFuse)
19161926
#endif
19171927
{
19181928
P[6][6] = sq(frontend->_gpsVertVelNoise);
19191929
}
1930+
else {
1931+
// TODO (EF): other vel source case?
1932+
}
19201933
vertVelVarClipCounter = 0;
19211934
}
19221935
}

0 commit comments

Comments
 (0)