altos: average 512 accel/baro samples at startup instead of 1000
authorKeith Packard <keithp@keithp.com>
Sat, 15 Jan 2011 19:26:31 +0000 (11:26 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 16 Jan 2011 22:35:29 +0000 (14:35 -0800)
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>
src/ao_flight.c

index 7fe85cb1522ac786579b824cd714c97dc088d9f3..9f651ae29d214f759efa96a7986590a6d755afcd 100644 (file)
@@ -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);