+
+ /* apogee to drogue deploy:
+ *
+ * accelerometer: integrated velocity < 10m/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 (ao_flight_vel < VEL_MPS_TO_COUNT(-10) ||
+ ao_flight_pres - BARO_APOGEE > ao_min_pres)
+ {
+ ao_ignite(ao_igniter_drogue);
+ 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) > 50m/s
+ * OR
+ * barometer: reach main deploy altitude
+ */
+ if (ao_flight_vel < VEL_MPS_TO_COUNT(-50) ||
+ ao_flight_vel > VEL_MPS_TO_COUNT(50) ||
+ 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 500m of the launch altitude
+ */
+ if ((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;
+ ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
+ }
+ break;
+ case ao_flight_landed:
+ ao_log_stop();