AP_NavEKF2: Fix possible compass nullptr dereference

This commit is contained in:
Michael du Breuil 2017-07-31 12:22:15 -07:00 committed by Francisco Ferreira
parent 78f6a5a177
commit dffa3d3b40
1 changed files with 4 additions and 0 deletions

View File

@ -403,6 +403,10 @@ void NavEKF2_core::getMagXYZ(Vector3f &magXYZ) const
// return true if offsets are valid
bool NavEKF2_core::getMagOffsets(uint8_t mag_idx, Vector3f &magOffsets) const
{
if (!_ahrs->get_compass()) {
return false;
}
// compass offsets are valid if we have finalised magnetic field initialisation, magnetic field learning is not prohibited,
// primary compass is valid and state variances have converged
const float maxMagVar = 5E-6f;