1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-13 19:40:31 +03:00
This commit is contained in:
ahmedsalah52 2024-12-12 15:46:04 +01:00
parent 7a2b1ce412
commit e0ff8463c4

View file

@ -270,8 +270,7 @@ void updateSensorOffset(sensorState_t *sensor) {
float newOffset = sensor->currentAltReadingCm - kf.estimatedValue; float newOffset = sensor->currentAltReadingCm - kf.estimatedValue;
if (sensor->penalityIters > 0) { if (sensor->penalityIters > 0) {
sensor->zeroAltOffsetCm = 0.5f * (newOffset + sensor->zeroAltOffsetCm); sensor->zeroAltOffsetCm = 0.5f * (newOffset + sensor->zeroAltOffsetCm);
} } else { // detect a ramp in the sensor readings by accumulating the error
else { // detect a ramp in the sensor readings by accumulating the error
sensor->offsetError += newOffset - sensor->zeroAltOffsetCm; sensor->offsetError += newOffset - sensor->zeroAltOffsetCm;
if (fabsf(sensor->offsetError) > SENSOR_MAX_OFFSET_ERROR) { if (fabsf(sensor->offsetError) > SENSOR_MAX_OFFSET_ERROR) {
sensor->zeroAltOffsetCm = 0.01f * newOffset + 0.99f * sensor->zeroAltOffsetCm; sensor->zeroAltOffsetCm = 0.01f * newOffset + 0.99f * sensor->zeroAltOffsetCm;