altos: Support staging by going back to boost as needed
authorKeith Packard <keithp@keithp.com>
Wed, 21 Sep 2011 18:40:56 +0000 (11:40 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 21 Sep 2011 18:45:05 +0000 (11:45 -0700)
Detect additional motor burns by looking for high positive
acceleration in coast or fast modes.

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

index 85c1825bddfebf68c06f2d2b055c511eddae4164..a5cf7468f439728617bfe5877c55d6341ac6becd 100644 (file)
@@ -34,7 +34,7 @@
 /* Main flight thread. */
 
 __pdata enum ao_flight_state   ao_flight_state;        /* current flight state */
-__pdata uint16_t               ao_launch_tick;         /* time of launch detect */
+__pdata uint16_t               ao_boost_tick;          /* time of launch detect */
 
 /*
  * track min/max data over a long interval to detect
@@ -151,7 +151,7 @@ ao_flight(void)
                                )
                        {
                                ao_flight_state = ao_flight_boost;
-                               ao_launch_tick = ao_sample_tick;
+                               ao_boost_tick = ao_sample_tick;
 
                                /* start logging data */
                                ao_log_start();
@@ -184,7 +184,7 @@ ao_flight(void)
                         * (15 seconds) has past.
                         */
                        if ((ao_accel < AO_MSS_TO_ACCEL(-2.5) && ao_height > AO_M_TO_HEIGHT(100)) ||
-                           (int16_t) (ao_sample_tick - ao_launch_tick) > BOOST_TICKS_MAX)
+                           (int16_t) (ao_sample_tick - ao_boost_tick) > BOOST_TICKS_MAX)
                        {
 #if HAS_ACCEL
                                ao_flight_state = ao_flight_fast;
@@ -205,7 +205,8 @@ ao_flight(void)
                        {
                                ao_flight_state = ao_flight_coast;
                                ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
-                       }
+                       } else
+                               goto check_re_boost;
                        break;
 #endif
                case ao_flight_coast:
@@ -237,6 +238,16 @@ ao_flight(void)
                                ao_flight_state = ao_flight_drogue;
                                ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
                        }
+#if HAS_ACCEL
+                       else {
+                       check_re_boost:
+                               if (ao_accel > AO_MSS_TO_ACCEL(20)) {
+                                       ao_boost_tick = ao_sample_tick;
+                                       ao_flight_state = ao_flight_boost;
+                                       ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
+                               }
+                       }
+#endif
 
                        break;
                case ao_flight_drogue: