mirror of https://github.com/ArduPilot/ardupilot
AP_NavEKF: Make NED origin independent of home position
This enables the filter to report the last known position after disarm. The LLH location of the filters NED origin is published and should be logged every time the vehicle is armed to assist with post-flight trajectory reconstruction. The LLH location of the filters NED origin can be set externally whilst the vehicle is disarmed.
This commit is contained in:
parent
f0ea858e4c
commit
3d46680348
|
@ -3639,9 +3639,10 @@ void NavEKF::getMagXYZ(Vector3f &magXYZ) const
|
||||||
// return the last calculated latitude, longitude and height
|
// return the last calculated latitude, longitude and height
|
||||||
bool NavEKF::getLLH(struct Location &loc) const
|
bool NavEKF::getLLH(struct Location &loc) const
|
||||||
{
|
{
|
||||||
loc.lat = _ahrs->get_home().lat;
|
if(validOrigin) {
|
||||||
loc.lng = _ahrs->get_home().lng;
|
loc.lat = EKF_origin.lat;
|
||||||
loc.alt = _ahrs->get_home().alt - state.position.z*100;
|
loc.lng = EKF_origin.lng;
|
||||||
|
loc.alt = EKF_origin.alt - state.position.z*100;
|
||||||
loc.flags.relative_alt = 0;
|
loc.flags.relative_alt = 0;
|
||||||
loc.flags.terrain_alt = 0;
|
loc.flags.terrain_alt = 0;
|
||||||
if (constPosMode) {
|
if (constPosMode) {
|
||||||
|
@ -3650,6 +3651,9 @@ bool NavEKF::getLLH(struct Location &loc) const
|
||||||
location_offset(loc, state.position.x, state.position.y);
|
location_offset(loc, state.position.x, state.position.y);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the estimated height above ground level
|
// return the estimated height above ground level
|
||||||
|
@ -3964,9 +3968,15 @@ void NavEKF::readGpsData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// read latitutde and longitude from GPS and convert to NE position
|
// read latitutde and longitude from GPS and convert to local NE position relative to the stored origin
|
||||||
|
// If we don't have an origin, then set it to the current GPS coordinates
|
||||||
|
if (validOrigin) {
|
||||||
const struct Location &gpsloc = _ahrs->get_gps().location();
|
const struct Location &gpsloc = _ahrs->get_gps().location();
|
||||||
gpsPosNE = location_diff(_ahrs->get_home(), gpsloc);
|
gpsPosNE = location_diff(EKF_origin, gpsloc);
|
||||||
|
} else {
|
||||||
|
setOrigin();
|
||||||
|
gpsPosNE.zero();
|
||||||
|
}
|
||||||
// calculate a position offset which is applied to NE position and velocity wherever it is used throughout code to allow GPS position jumps to be accommodated gradually
|
// calculate a position offset which is applied to NE position and velocity wherever it is used throughout code to allow GPS position jumps to be accommodated gradually
|
||||||
decayGpsOffset();
|
decayGpsOffset();
|
||||||
}
|
}
|
||||||
|
@ -4372,6 +4382,7 @@ void NavEKF::InitialiseVariables()
|
||||||
inhibitMagStates = true;
|
inhibitMagStates = true;
|
||||||
gndOffsetValid = false;
|
gndOffsetValid = false;
|
||||||
flowXfailed = false;
|
flowXfailed = false;
|
||||||
|
validOrigin = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return true if we should use the airspeed sensor
|
// return true if we should use the airspeed sensor
|
||||||
|
@ -4548,8 +4559,11 @@ void NavEKF::performArmingChecks()
|
||||||
}
|
}
|
||||||
// zero stored velocities used to do dead-reckoning
|
// zero stored velocities used to do dead-reckoning
|
||||||
heldVelNE.zero();
|
heldVelNE.zero();
|
||||||
// zero last known position used to deadreckon if GPS is lost
|
// zero last known position used to deadreckon if GPS is lost when arming
|
||||||
|
// keep position during disarm to provide continuing indication of last known position
|
||||||
|
if (vehicleArmed) {
|
||||||
lastKnownPositionNE.zero();
|
lastKnownPositionNE.zero();
|
||||||
|
}
|
||||||
// set various useage modes based on the condition at arming. These are then held until the vehicle is disarmed.
|
// set various useage modes based on the condition at arming. These are then held until the vehicle is disarmed.
|
||||||
if (!vehicleArmed) {
|
if (!vehicleArmed) {
|
||||||
PV_AidingMode = AID_NONE; // When dis-armed, we only estimate orientation & height using the constant position mode
|
PV_AidingMode = AID_NONE; // When dis-armed, we only estimate orientation & height using the constant position mode
|
||||||
|
@ -4598,4 +4612,31 @@ void NavEKF::performArmingChecks()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the NED origin to be used until the next filter reset
|
||||||
|
void NavEKF::setOrigin()
|
||||||
|
{
|
||||||
|
EKF_origin = _ahrs->get_gps().location();
|
||||||
|
validOrigin = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the LLH location of the filters NED origin
|
||||||
|
bool NavEKF::getOriginLLH(struct Location &loc) const
|
||||||
|
{
|
||||||
|
if (validOrigin) {
|
||||||
|
loc = EKF_origin;
|
||||||
|
}
|
||||||
|
return validOrigin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the LLH location of the filters NED origin
|
||||||
|
bool NavEKF::setOriginLLH(struct Location &loc)
|
||||||
|
{
|
||||||
|
if (vehicleArmed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
EKF_origin = loc;
|
||||||
|
validOrigin = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // HAL_CPU_CLASS
|
#endif // HAL_CPU_CLASS
|
||||||
|
|
|
@ -139,6 +139,17 @@ public:
|
||||||
// return the last calculated latitude, longitude and height
|
// return the last calculated latitude, longitude and height
|
||||||
bool getLLH(struct Location &loc) const;
|
bool getLLH(struct Location &loc) const;
|
||||||
|
|
||||||
|
// return the latitude and longitude and height used to set the NED origin
|
||||||
|
// All NED positions calculated by the filter are relative to this location
|
||||||
|
// Returns false if the origin has not been set
|
||||||
|
bool getOriginLLH(struct Location &loc) const;
|
||||||
|
|
||||||
|
// set the latitude and longitude and height used to set the NED origin
|
||||||
|
// All NED positions calcualted by the filter will be relative to this location
|
||||||
|
// The origin cannot be set if the filter is in a flight mode (eg vehicle armed)
|
||||||
|
// Returns false if the filter has rejected the attempt to set the origin
|
||||||
|
bool setOriginLLH(struct Location &loc);
|
||||||
|
|
||||||
// return estimated height above ground level
|
// return estimated height above ground level
|
||||||
// return false if ground height is not being estimated.
|
// return false if ground height is not being estimated.
|
||||||
bool getHAGL(float &HAGL) const;
|
bool getHAGL(float &HAGL) const;
|
||||||
|
@ -379,6 +390,9 @@ private:
|
||||||
// Check arm status and perform required checks and mode changes
|
// Check arm status and perform required checks and mode changes
|
||||||
void performArmingChecks();
|
void performArmingChecks();
|
||||||
|
|
||||||
|
// Set the NED origin to be used until the next filter reset
|
||||||
|
void setOrigin();
|
||||||
|
|
||||||
// EKF Mavlink Tuneable Parameters
|
// EKF Mavlink Tuneable Parameters
|
||||||
AP_Float _gpsHorizVelNoise; // GPS horizontal velocity measurement noise : m/s
|
AP_Float _gpsHorizVelNoise; // GPS horizontal velocity measurement noise : m/s
|
||||||
AP_Float _gpsVertVelNoise; // GPS vertical velocity measurement noise : m/s
|
AP_Float _gpsVertVelNoise; // GPS vertical velocity measurement noise : m/s
|
||||||
|
@ -572,6 +586,8 @@ private:
|
||||||
bool gpsNotAvailable; // bool true when valid GPS data is not available
|
bool gpsNotAvailable; // bool true when valid GPS data is not available
|
||||||
bool vehicleArmed; // true when the vehicle is disarmed
|
bool vehicleArmed; // true when the vehicle is disarmed
|
||||||
bool prevVehicleArmed; // vehicleArmed from previous frame
|
bool prevVehicleArmed; // vehicleArmed from previous frame
|
||||||
|
struct Location EKF_origin; // LLH origin of the NED axis system - do not change unless filter is reset
|
||||||
|
bool validOrigin; // true when the EKF origin is valid
|
||||||
|
|
||||||
// Used by smoothing of state corrections
|
// Used by smoothing of state corrections
|
||||||
float gpsIncrStateDelta[10]; // vector of corrections to attitude, velocity and position to be applied over the period between the current and next GPS measurement
|
float gpsIncrStateDelta[10]; // vector of corrections to attitude, velocity and position to be applied over the period between the current and next GPS measurement
|
||||||
|
|
Loading…
Reference in New Issue