Skip to content

Commit a38c01a

Browse files
committed
AP_NavEKF3: Adjust sensor height when EK3_OGN_HGT_MASK bit 2 is set
1 parent bec2450 commit a38c01a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

libraries/AP_NavEKF3/AP_NavEKF3_Measurements.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,10 @@ void NavEKF3_core::readGpsData()
685685
gpsDataNew.lat = gpsloc.lat;
686686
gpsDataNew.lng = gpsloc.lng;
687687
if ((frontend->_originHgtMode & (1<<2)) == 0) {
688+
// the height adjustment to match GPS is being achieved by adjusting the origin height
688689
gpsDataNew.hgt = (ftype)((double)0.01 * (double)gpsloc.alt - ekfGpsRefHgt);
689690
} else {
691+
// the height adjustment to match GPS is being achieved by adjusting the measurements
690692
gpsDataNew.hgt = 0.01 * (gpsloc.alt - EKF_origin.alt);
691693
}
692694
storedGPS.push(gpsDataNew);

libraries/AP_NavEKF3/AP_NavEKF3_PosVelFusion.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,11 @@ void NavEKF3_core::selectHeightForFusion()
12781278
hgtMea = MAX(rangeDataDelayed.rng * prevTnb.c.z, rngOnGnd);
12791279
// correct for terrain position relative to datum
12801280
hgtMea -= terrainState;
1281+
// correct sensor so that local position height adjusts to match GPS
1282+
if (frontend->_originHgtMode & (1 << 1) && frontend->_originHgtMode & (1 << 2)) {
1283+
// offset has to be applied to the measurement, not the NED origin
1284+
hgtMea += (float)(ekfGpsRefHgt - 0.01 * (double)EKF_origin.alt);
1285+
}
12811286
velPosObs[5] = -hgtMea;
12821287
// enable fusion
12831288
fuseHgtData = true;
@@ -1304,6 +1309,10 @@ void NavEKF3_core::selectHeightForFusion()
13041309
} else if (baroDataToFuse && (activeHgtSource == AP_NavEKF_Source::SourceZ::BARO)) {
13051310
// using Baro data
13061311
hgtMea = baroDataDelayed.hgt - baroHgtOffset;
1312+
// correct sensor so that local position height adjusts to match GPS
1313+
if (frontend->_originHgtMode & (1 << 0) && frontend->_originHgtMode & (1 << 2)) {
1314+
hgtMea += (float)(ekfGpsRefHgt - 0.01 * (double)EKF_origin.alt);
1315+
}
13071316
// enable fusion
13081317
fuseHgtData = true;
13091318
// set the observation noise

0 commit comments

Comments
 (0)