AP_Compass: fixed zero compass diagonals

this fixes a regression from 4.2 to 4.3.

previously we automatically set the diagnoals to 1,1,1 if they were
0,0,0. We don't do that any more. I was helping a user who had copied
an old config with 0,0,0 for diagonals and did not understand two
things:

- the compass did not work in 4.3
- large vehicle mag cal didn't work
This commit is contained in:
Andrew Tridgell 2023-02-09 09:15:16 +11:00
parent 6d117528e4
commit 4d002e5895
2 changed files with 23 additions and 18 deletions

View File

@ -87,6 +87,7 @@ void AP_Compass_Backend::correct_field(Vector3f &mag, uint8_t i)
} }
// apply eliptical correction // apply eliptical correction
if (!diagonals.is_zero()) {
Matrix3f mat( Matrix3f mat(
diagonals.x, offdiagonals.x, offdiagonals.y, diagonals.x, offdiagonals.x, offdiagonals.y,
offdiagonals.x, diagonals.y, offdiagonals.z, offdiagonals.x, diagonals.y, offdiagonals.z,
@ -94,6 +95,7 @@ void AP_Compass_Backend::correct_field(Vector3f &mag, uint8_t i)
); );
mag = mat * mag; mag = mat * mag;
}
#if COMPASS_MOT_ENABLED #if COMPASS_MOT_ENABLED
const Vector3f &mot = state.motor_compensation.get(); const Vector3f &mot = state.motor_compensation.get();

View File

@ -450,7 +450,12 @@ bool Compass::get_uncorrected_field(uint8_t instance, Vector3f &field) const
// form eliptical correction matrix and invert it. This is // form eliptical correction matrix and invert it. This is
// needed to remove the effects of the eliptical correction // needed to remove the effects of the eliptical correction
// when calculating new offsets // when calculating new offsets
// get corrected field
field = get_field(instance);
const Vector3f &diagonals = get_diagonals(instance); const Vector3f &diagonals = get_diagonals(instance);
if (!diagonals.is_zero()) {
const Vector3f &offdiagonals = get_offdiagonals(instance); const Vector3f &offdiagonals = get_offdiagonals(instance);
Matrix3f mat { Matrix3f mat {
diagonals.x, offdiagonals.x, offdiagonals.y, diagonals.x, offdiagonals.x, offdiagonals.y,
@ -461,11 +466,9 @@ bool Compass::get_uncorrected_field(uint8_t instance, Vector3f &field) const
return false; return false;
} }
// get corrected field
field = get_field(instance);
// remove impact of diagonals and off-diagonals // remove impact of diagonals and off-diagonals
field = mat * field; field = mat * field;
}
// remove impact of offsets // remove impact of offsets
field -= get_offsets(instance); field -= get_offsets(instance);