Skip to content

Commit

Permalink
AP_NavEKF3: handle external nav position reset
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Apr 30, 2020
1 parent cbb2531 commit f79d5d2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
66 changes: 65 additions & 1 deletion libraries/AP_NavEKF3/AP_NavEKF3_PosVelFusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,64 @@ void NavEKF3_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 NavEKF3_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<imu_buffer_length; i++) {
storedOutput[i].position.x += posResetNE.x;
storedOutput[i].position.y += posResetNE.y;
}
outputDataNew.position.x += posResetNE.x;
outputDataNew.position.y += posResetNE.y;
outputDataDelayed.position.x += posResetNE.x;
outputDataDelayed.position.y += posResetNE.y;

// store the time of the reset
lastPosReset_ms = imuSampleTime_ms;
}

// reset the stateStruct's D position
// posResetD is updated to hold the change in position
// storedOutput, outputDataNew and outputDataDelayed are updated with the change in position
// lastPosResetD_ms is updated with the time of the reset
void NavEKF3_core::ResetPositionD(float posD)
{
// Store the position before the reset so that we can record the reset delta
const float posDOrig = stateStruct.position.z;

// write to the state vector
stateStruct.position.z = posD;

// Calculate the position jump due to the reset
posResetD = stateStruct.position.z - posDOrig;

// Add the offset to the output observer states
outputDataNew.position.z += posResetD;
vertCompFiltState.pos = outputDataNew.position.z;
outputDataDelayed.position.z += posResetD;
for (uint8_t i=0; i<imu_buffer_length; i++) {
storedOutput[i].position.z += posResetD;
}

// store the time of the reset
lastPosResetD_ms = imuSampleTime_ms;
}

// reset the vertical position state using the last height measurement
void NavEKF3_core::ResetHeight(void)
{
Expand Down Expand Up @@ -426,7 +484,13 @@ void NavEKF3_core::SelectVelPosFusion()
}
}

// To-Do: add external nav position reset handling here?
// check for external nav position reset
if (extNavDataToFuse && (PV_AidingMode == AID_ABSOLUTE) && (frontend->_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
Expand Down
6 changes: 6 additions & 0 deletions libraries/AP_NavEKF3/AP_NavEKF3_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,12 @@ class NavEKF3_core : public NavEKF_core_common
// 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 the stateStruct's D position
void ResetPositionD(float posD);

// reset velocity states using the last GPS measurement
void ResetVelocity(void);

Expand Down

0 comments on commit f79d5d2

Please sign in to comment.