summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2011-01-15 11:26:31 -0800
committerKeith Packard <keithp@keithp.com>2011-01-16 14:35:29 -0800
commit118fe84c9ff1cc9d1653e67a2315e22e19d60a14 (patch)
treed53c7b770776adecbf0235e9dde8906366e42961
parent8a775b8f9ecefa143050653d74dfd218b32b9bb5 (diff)
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 <keithp@keithp.com>
-rw-r--r--src/ao_flight.c8
1 files 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);