altos: Remove spurious ao_mma655x_spi_index variable
[fw/altos] / src / kernel / ao_flight.c
index f06125cd1329f361f7e91e92afcaadc2be420b38..c2700d20bddb41801bacb0d560291a50aaad4bb0 100644 (file)
@@ -21,7 +21,7 @@
 #include <ao_log.h>
 #endif
 
-#if HAS_MPU6000
+#if HAS_MPU6000 || HAS_MPU9250
 #include <ao_quaternion.h>
 #endif
 
@@ -48,7 +48,8 @@
 /* Main flight thread. */
 
 __pdata enum ao_flight_state   ao_flight_state;        /* current flight state */
-__pdata uint16_t               ao_boost_tick;          /* time of launch detect */
+__pdata uint16_t               ao_boost_tick;          /* time of most recent boost detect */
+__pdata uint16_t               ao_launch_tick;         /* time of first boost detect */
 __pdata uint16_t               ao_motor_number;        /* number of motors burned so far */
 
 #if HAS_SENSOR_ERRORS
@@ -199,7 +200,7 @@ ao_flight(void)
                                )
                        {
                                ao_flight_state = ao_flight_boost;
-                               ao_boost_tick = ao_sample_tick;
+                               ao_launch_tick = ao_boost_tick = ao_sample_tick;
 
                                /* start logging data */
                                ao_log_start();
@@ -233,7 +234,7 @@ ao_flight(void)
                         * deceleration, or by waiting until the maximum burn duration
                         * (15 seconds) has past.
                         */
-                       if ((ao_accel < AO_MSS_TO_ACCEL(-2.5) && ao_height > AO_M_TO_HEIGHT(100)) ||
+                       if ((ao_accel < AO_MSS_TO_ACCEL(-2.5)) ||
                            (int16_t) (ao_sample_tick - ao_boost_tick) > BOOST_TICKS_MAX)
                        {
 #if HAS_ACCEL
@@ -269,7 +270,7 @@ ao_flight(void)
                         * number of seconds.
                         */
                        if (ao_config.apogee_lockout) {
-                               if ((int16_t) (ao_sample_tick - ao_boost_tick) <
+                               if ((int16_t) (ao_sample_tick - ao_launch_tick) <
                                    AO_SEC_TO_TICKS(ao_config.apogee_lockout))
                                        break;
                        }
@@ -310,7 +311,7 @@ ao_flight(void)
 #if HAS_ACCEL
                        else {
                        check_re_boost:
-                               ao_coast_avg_accel = ao_coast_avg_accel - (ao_coast_avg_accel >> 6) + (ao_accel >> 6);
+                               ao_coast_avg_accel = ao_coast_avg_accel + ((ao_accel - ao_coast_avg_accel) >> 5);
                                if (ao_coast_avg_accel > AO_MSS_TO_ACCEL(20)) {
                                        ao_boost_tick = ao_sample_tick;
                                        ao_flight_state = ao_flight_boost;