X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fao_kalman.c;h=ee01949e5e54a416bc9737e56bb20a03261f8bc1;hb=01aee9ebe517ed657692e0a39a31ae0ddfb5b8b0;hp=4e6cbb06c332561939589935aea4da8c65022d46;hpb=146a0ab223e8d9b376125d1e59f597f6d7851a9b;p=fw%2Faltos diff --git a/src/ao_kalman.c b/src/ao_kalman.c index 4e6cbb06..ee01949e 100644 --- a/src/ao_kalman.c +++ b/src/ao_kalman.c @@ -38,6 +38,8 @@ __pdata int16_t ao_height; __pdata int16_t ao_speed; __pdata int16_t ao_accel; __pdata int16_t ao_max_height; +static __pdata int32_t ao_avg_height_scaled; +__pdata int16_t ao_avg_height; __pdata int16_t ao_error_h; __pdata int16_t ao_error_h_sq_avg; @@ -275,6 +277,15 @@ ao_kalman(void) ao_accel = from_fix(ao_k_accel); if (ao_height > ao_max_height) ao_max_height = ao_height; + ao_avg_height_scaled = ao_avg_height_scaled - ao_avg_height + ao_sample_height; +#ifdef AO_FLIGHT_TEST + if (ao_sample_tick - ao_sample_prev_tick > 50) + ao_avg_height = (ao_avg_height_scaled + 1) >> 1; + else if (ao_sample_tick - ao_sample_prev_tick > 5) + ao_avg_height = (ao_avg_height_scaled + 7) >> 4; + else +#endif + ao_avg_height = (ao_avg_height_scaled + 63) >> 7; #ifdef AO_FLIGHT_TEST ao_sample_prev_tick = ao_sample_tick; #endif