AP_NavEKF: Enforce alignment of realigned earth mag field with declination
This prevents bad inertial or GPS data combined with the post takeoff heading alignment check used by plane from resulting in earth field states that have an incorrect declination
This commit is contained in:
parent
b1d8805114
commit
c1c5e3598a
@ -4397,10 +4397,10 @@ Quaternion NavEKF::calcQuatAndFieldStates(float roll, float pitch)
|
||||
// calculate initial Tbn matrix and rotate Mag measurements into NED
|
||||
// to set initial NED magnetic field states
|
||||
initQuat.rotation_matrix(Tbn);
|
||||
initMagNED = Tbn * magData;
|
||||
state.earth_magfield = Tbn * magData;
|
||||
|
||||
// write to earth magnetic field state vector
|
||||
state.earth_magfield = initMagNED;
|
||||
// align the NE earth magnetic field states with the published declination
|
||||
alignMagStateDeclination();
|
||||
|
||||
// clear bad magnetometer status
|
||||
badMag = false;
|
||||
@ -5183,4 +5183,18 @@ void NavEKF::getQuaternion(Quaternion& ret) const
|
||||
ret = state.quat;
|
||||
}
|
||||
|
||||
// align the NE earth magnetic field states with the published declination
|
||||
void NavEKF::alignMagStateDeclination()
|
||||
{
|
||||
// get the magnetic declination
|
||||
float magDecAng = use_compass() ? _ahrs->get_compass()->get_declination() : 0;
|
||||
|
||||
// rotate the NE values so that the declination matches the published value
|
||||
Vector3f initMagNED = state.earth_magfield;
|
||||
float magLengthNE = pythagorous2(initMagNED.x,initMagNED.y);
|
||||
state.earth_magfield.x = magLengthNE * cosf(magDecAng);
|
||||
state.earth_magfield.y = magLengthNE * sinf(magDecAng);
|
||||
}
|
||||
|
||||
|
||||
#endif // HAL_CPU_CLASS
|
||||
|
@ -453,6 +453,9 @@ private:
|
||||
// check if the vehicle has taken off during optical flow navigation by looking at inertial and range finder data
|
||||
void detectOptFlowTakeoff(void);
|
||||
|
||||
// align the NE earth magnetic field states with the published declination
|
||||
void alignMagStateDeclination();
|
||||
|
||||
// EKF Mavlink Tuneable Parameters
|
||||
AP_Float _gpsHorizVelNoise; // GPS horizontal velocity measurement noise : m/s
|
||||
AP_Float _gpsVertVelNoise; // GPS vertical velocity measurement noise : m/s
|
||||
|
Loading…
Reference in New Issue
Block a user