+
+ /* apogee detect to drogue deploy:
+ *
+ * accelerometer: abs(velocity) > min_velocity + 2m/s
+ * OR
+ * barometer: fall at least 10m
+ *
+ * If the barometer saturates because the flight
+ * goes over its measuring range (about 53k'),
+ * requiring a 10m fall will avoid prematurely
+ * detecting apogee; the accelerometer will take
+ * over in that case and the integrated velocity
+ * measurement should suffice to find apogee
+ */
+ if (abs(ao_flight_vel) > ao_min_vel + ACCEL_VEL_APOGEE ||
+ ao_flight_pres > ao_min_pres + BARO_APOGEE)
+ {
+ /* ignite the drogue charge */
+ ao_ignite(ao_igniter_drogue);
+
+ /* slow down the telemetry system */
+ ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_RECOVER);
+
+ /* Enable RDF beacon */
+ ao_rdf_set(1);
+
+ ao_flight_state = ao_flight_drogue;
+ ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
+ }
+ break;
+ case ao_flight_drogue:
+
+ /* drogue to main deploy:
+ *
+ * accelerometer: abs(velocity) > 100m/s (in case the drogue failed)
+ * OR
+ * barometer: reach main deploy altitude
+ */
+ if (ao_flight_vel < -ACCEL_VEL_MAIN ||
+ ao_flight_vel > ACCEL_VEL_MAIN ||
+ ao_flight_pres >= ao_main_pres)
+ {
+ ao_ignite(ao_igniter_main);
+ ao_flight_state = ao_flight_main;
+ ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
+ }
+ /* fall through... */
+ case ao_flight_main:
+
+ /* drogue/main to land:
+ *
+ * accelerometer: value stable and velocity less than 10m/s
+ * OR
+ * barometer: altitude stable and within 1000m of the launch altitude
+ */
+ if ((abs(ao_flight_vel) < ACCEL_VEL_LAND &&
+ (ao_interval_max_accel - ao_interval_min_accel) < ACCEL_INT_LAND) ||
+ (ao_flight_pres > ao_ground_pres - BARO_LAND &&
+ (ao_interval_max_pres - ao_interval_min_pres) < BARO_INT_LAND))
+ {
+ ao_flight_state = ao_flight_landed;
+
+ /* turn off the ADC capture */
+ ao_timer_set_adc_interval(0);
+
+ /* stop logging data */
+ ao_log_stop();
+
+ ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
+ }
+ break;
+ case ao_flight_landed: