From 118fe84c9ff1cc9d1653e67a2315e22e19d60a14 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 15 Jan 2011 11:26:31 -0800 Subject: [PATCH] altos: average 512 accel/baro samples at startup instead of 1000 This lets us use a simple shift instead of a divide, saving a huge amount of code space. Signed-off-by: Keith Packard --- src/ao_flight.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ao_flight.c b/src/ao_flight.c index 7fe85cb1..9f651ae2 100644 --- a/src/ao_flight.c +++ b/src/ao_flight.c @@ -196,17 +196,17 @@ ao_flight(void) /* startup state: * - * Collect 1000 samples of acceleration and pressure + * Collect 512 samples of acceleration and pressure * data and average them to find the resting values */ - if (nsamples < 1000) { + if (nsamples < 512) { ao_raw_accel_sum += ao_raw_accel; ao_raw_pres_sum += ao_raw_pres; ++nsamples; continue; } - ao_ground_accel = (ao_raw_accel_sum / nsamples); - ao_ground_pres = (ao_raw_pres_sum / nsamples); + ao_ground_accel = ao_raw_accel_sum >> 9; + ao_ground_pres = ao_raw_pres_sum >> 9; ao_min_pres = ao_ground_pres; ao_config_get(); ao_main_pres = ao_altitude_to_pres(ao_pres_to_altitude(ao_ground_pres) + ao_config.main_deploy); -- 2.30.2