AP_NavEKF3: Add handlers for external lat lng position set

This commit is contained in:
Paul Riseborough 2023-05-14 09:55:30 +10:00 committed by Andrew Tridgell
parent 48f0edaffc
commit 3677cb025d
5 changed files with 71 additions and 0 deletions

View File

@ -1408,6 +1408,26 @@ bool NavEKF3::setOriginLLH(const Location &loc)
return ret;
}
bool NavEKF3::setLatLng(const Location &loc, float posAccuracy, uint32_t timestamp_ms)
{
#if EK3_FEATURE_POSITION_RESET
AP::dal().log_SetLatLng(loc, posAccuracy, timestamp_ms);
if (!core) {
return false;
}
bool ret = false;
for (uint8_t i=0; i<num_cores; i++) {
ret |= core[i].setLatLng(loc, posAccuracy, timestamp_ms);
}
// return true if any core accepts the new origin
return ret;
#else
return false;
#endif // EK3_FEATURE_POSITION_RESET
}
// return estimated height above ground level
// return false if ground height is not being estimated.
bool NavEKF3::getHAGL(float &HAGL) const

View File

@ -152,6 +152,11 @@ public:
// Returns false if the filter has rejected the attempt to set the origin
bool setOriginLLH(const Location &loc);
// Set the EKF's NE horizontal position states and their corresponding variances from a supplied WGS-84 location and uncertainty
// The altitude element of the location is not used.
// Returns true if the set was successful
bool setLatLng(const Location &loc, float posErr, uint32_t timestamp_ms);
// return estimated height above ground level
// return false if ground height is not being estimated.
bool getHAGL(float &HAGL) const;

View File

@ -144,6 +144,42 @@ void NavEKF3_core::ResetPosition(resetDataSource posResetSource)
lastPosPassTime_ms = imuSampleTime_ms;
}
#if EK3_FEATURE_POSITION_RESET
// Sets the EKF's NE horizontal position states and their corresponding variances from a supplied WGS-84 location and uncertainty
// The altitude element of the location is not used.
// Returns true if the set was successful
bool NavEKF3_core::setLatLng(const Location &loc, float posAccuracy, uint32_t timestamp_ms)
{
if ((imuSampleTime_ms - lastPosPassTime_ms) < frontend->deadReckonDeclare_ms ||
(PV_AidingMode == AID_NONE)
|| !validOrigin) {
return false;
}
// Store the position before the reset so that we can record the reset delta
posResetNE.x = stateStruct.position.x;
posResetNE.y = stateStruct.position.y;
// reset the corresponding covariances
zeroRows(P,7,8);
zeroCols(P,7,8);
// set the variances using the position measurement noise parameter
P[7][7] = P[8][8] = sq(MAX(posAccuracy,frontend->_gpsHorizPosNoise));
// Correct the position for time delay relative to fusion time horizon assuming a constant velocity
// Limit time stamp to a range between current time and 5 seconds ago
const uint32_t timeStampConstrained_ms = MAX(MIN(timestamp_ms, imuSampleTime_ms), imuSampleTime_ms - 5000);
const int32_t delta_ms = int32_t(imuDataDelayed.time_ms - timeStampConstrained_ms);
const ftype delaySec = 1E-3F * ftype(delta_ms);
const Vector2F newPosNE = EKF_origin.get_distance_NE_ftype(loc) - stateStruct.velocity.xy() * delaySec;
ResetPositionNE(newPosNE.x,newPosNE.y);
return true;
}
#endif // EK3_FEATURE_POSITION_RESET
// 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

View File

@ -230,6 +230,11 @@ public:
// returns false if Absolute aiding and GPS is being used or if the origin is already set
bool setOriginLLH(const Location &loc);
// Set the EKF's NE horizontal position states and their corresponding variances from a supplied WGS-84 location and uncertainty
// The altitude element of the location is not used.
// Returns true if the set was successful
bool setLatLng(const Location &loc, float posAccuracy, uint32_t timestamp_ms);
// return estimated height above ground level
// return false if ground height is not being estimated.
bool getHAGL(float &HAGL) const;

View File

@ -7,6 +7,7 @@
#include <AP_Vehicle/AP_Vehicle_Type.h>
#include <AP_HAL/AP_HAL_Boards.h>
#include <AP_Beacon/AP_Beacon_config.h>
#include <AP_AHRS/AP_AHRS_config.h>
// define for when to include all features
#define EK3_FEATURE_ALL APM_BUILD_TYPE(APM_BUILD_AP_DAL_Standalone) || APM_BUILD_TYPE(APM_BUILD_Replay)
@ -30,3 +31,7 @@
#ifndef EK3_FEATURE_BEACON_FUSION
#define EK3_FEATURE_BEACON_FUSION AP_BEACON_ENABLED
#endif
#ifndef EK3_FEATURE_POSITION_RESET
#define EK3_FEATURE_POSITION_RESET EK3_FEATURE_ALL || AP_AHRS_POSITION_RESET_ENABLED
#endif