attitude_estimator_q: fuse accel data only if close to 1g if GPS velocity not used

This reduces attitude drift on vehicles w/o GPS. The default behavior is
unchanged, to use it, disable ATT_ACC_COMP.
This commit is contained in:
Beat Küng
2018-05-11 09:34:26 +02:00
committed by Lorenz Meier
parent f77b8d9aa8
commit 9e24875131
@@ -606,7 +606,16 @@ bool AttitudeEstimatorQ::update(float dt)
(_q(0) * _q(0) - _q(1) * _q(1) - _q(2) * _q(2) + _q(3) * _q(3))
);
corr += (k % (_accel - _pos_acc).normalized()) * _w_accel;
// If we are not using acceleration compensation based on GPS velocity,
// fuse accel data only if its norm is close to 1 g (reduces drift).
const float accel_norm_sq = _accel.length_squared();
const float upper_accel_limit = CONSTANTS_ONE_G * 1.1f;
const float lower_accel_limit = CONSTANTS_ONE_G * 0.9f;
if (_acc_comp || (accel_norm_sq > lower_accel_limit * lower_accel_limit &&
accel_norm_sq < upper_accel_limit * upper_accel_limit)) {
corr += (k % (_accel - _pos_acc).normalized()) * _w_accel;
}
// Gyro bias estimation
if (spinRate < 0.175f) {