Add velocity check for boost detect via accelerometer
authorKeith Packard <keithp@keithp.com>
Wed, 13 May 2009 17:59:04 +0000 (10:59 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 13 May 2009 17:59:04 +0000 (10:59 -0700)
Bumping the rocket can cause a brief period of high acceleration, which may
cause a mistaken boost detection. Require both a high acceleration and
reasonable velocity to trigger boost phase.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao_flight.c

index 3bc6b97..d50d37e 100644 (file)
@@ -83,6 +83,7 @@ __pdata int16_t ao_raw_accel, ao_raw_accel_prev, ao_raw_pres;
 #define ACCEL_VEL_MACH VEL_MPS_TO_COUNT(200)
 #define ACCEL_VEL_APOGEE       VEL_MPS_TO_COUNT(2)
 #define ACCEL_VEL_MAIN VEL_MPS_TO_COUNT(100)
+#define ACCEL_VEL_BOOST        VEL_MPS_TO_COUNT(5)
 
 /*
  * Barometer calibration
@@ -242,7 +243,7 @@ ao_flight(void)
 
                        /* pad to boost:
                         *
-                        * accelerometer: > 2g
+                        * accelerometer: > 2g AND velocity > 5m/s
                         *             OR
                         * barometer: > 20m vertical motion
                         *
@@ -250,7 +251,8 @@ ao_flight(void)
                         * the barometer, but we use both to make sure this
                         * transition is detected
                         */
-                       if (ao_flight_accel < ao_ground_accel - ACCEL_BOOST ||
+                       if ((ao_flight_accel < ao_ground_accel - ACCEL_BOOST &&
+                            ao_flight_vel > ACCEL_VEL_BOOST) ||
                            ao_flight_pres < ao_ground_pres - BARO_LAUNCH)
                        {
                                ao_flight_state = ao_flight_boost;