diff --git a/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp b/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp index 34e7924431..2fd113a51c 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp @@ -146,6 +146,37 @@ void NavEKF2_core::ResetPosition(void) } +// reset the stateStruct's NE position to the specified position +// posResetNE is updated to hold the change in position +// storedOutput, outputDataNew and outputDataDelayed are updated with the change in position +// lastPosReset_ms is updated with the time of the reset +void NavEKF2_core::ResetPositionNE(float posN, float posE) +{ + // Store the position before the reset so that we can record the reset delta + const Vector3f posOrig = stateStruct.position; + + // Set the position states to the new position + stateStruct.position.x = posN; + stateStruct.position.y = posE; + + // Calculate the position offset due to the reset + posResetNE.x = stateStruct.position.x - posOrig.x; + posResetNE.y = stateStruct.position.y - posOrig.y; + + // Add the offset to the output observer states + for (uint8_t i=0; i_fusionModeGPS == 3) && extNavDataDelayed.posReset) { + ResetPositionNE(extNavDataDelayed.pos.x, extNavDataDelayed.pos.y); + if (activeHgtSource == HGT_SOURCE_EXTNAV) { + ResetPositionD(-hgtMea); + } + } + // If we are operating without any aiding, fuse in the last known position // to constrain tilt drift. This assumes a non-manoeuvring vehicle // Do this to coincide with the height fusion diff --git a/libraries/AP_NavEKF2/AP_NavEKF2_core.h b/libraries/AP_NavEKF2/AP_NavEKF2_core.h index 6c3e83baf5..70544ea79b 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2_core.h +++ b/libraries/AP_NavEKF2/AP_NavEKF2_core.h @@ -668,12 +668,18 @@ private: // reset the horizontal position states uing the last GPS measurement void ResetPosition(void); + // reset the stateStruct's NE position to the specified position + void ResetPositionNE(float posN, float posE); + // reset velocity states using the last GPS measurement void ResetVelocity(void); // reset the vertical position state using the last height measurement void ResetHeight(void); + // reset the stateStruct's D position + void ResetPositionD(float posD); + // return true if we should use the airspeed sensor bool useAirspeed(void) const;