2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 #ifndef AO_FLIGHT_TEST
23 #error Please define HAS_ACCEL
27 #error Please define HAS_GPS
31 #error Please define HAS_USB
34 /* Main flight thread. */
36 __pdata enum ao_flight_state ao_flight_state; /* current flight state */
38 __pdata uint8_t ao_flight_force_idle;
44 ao_flight_state = ao_flight_startup;
48 * Process ADC samples, just looping
49 * until the sensors are calibrated.
54 switch (ao_flight_state) {
55 case ao_flight_startup:
57 /* Check to see what mode we should go to.
58 * - Invalid mode if accel cal appears to be out
59 * - pad mode if we're upright,
60 * - idle mode otherwise
63 if (ao_config.accel_plus_g == 0 ||
64 ao_config.accel_minus_g == 0 ||
65 ao_ground_accel < ao_config.accel_plus_g - ACCEL_NOSE_UP ||
66 ao_ground_accel > ao_config.accel_minus_g + ACCEL_NOSE_UP)
68 /* Detected an accel value outside -1.5g to 1.5g
69 * (or uncalibrated values), so we go into invalid mode
71 ao_flight_state = ao_flight_invalid;
73 /* Turn on packet system in invalid mode on TeleMetrum */
74 ao_packet_slave_start();
77 if (!ao_flight_force_idle
79 && ao_ground_accel < ao_config.accel_plus_g + ACCEL_NOSE_UP
83 /* Set pad mode - we can fly! */
84 ao_flight_state = ao_flight_pad;
86 /* Disable the USB controller in flight mode
93 /* Disable packet mode in pad state on TeleMini */
94 ao_packet_slave_stop();
97 /* Turn on telemetry system */
99 ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_BALLOON);
101 /* signal successful initialization by turning off the LED */
102 ao_led_off(AO_LED_RED);
105 ao_flight_state = ao_flight_idle;
108 /* Turn on packet system in idle mode on TeleMetrum */
109 ao_packet_slave_start();
112 /* signal successful initialization by turning off the LED */
113 ao_led_off(AO_LED_RED);
115 /* wakeup threads due to state change */
116 ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
123 * barometer: > 20m vertical motion
125 if (ao_height > AO_M_TO_HEIGHT(20))
127 ao_flight_state = ao_flight_drogue;
129 /* start logging data */
133 /* Record current GPS position by waking up GPS log tasks */
134 ao_wakeup(&ao_gps_data);
135 ao_wakeup(&ao_gps_tracking_data);
138 ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
141 case ao_flight_drogue:
148 static __xdata struct ao_task flight_task;
153 ao_flight_state = ao_flight_startup;
154 ao_add_task(&flight_task, ao_flight, "flight");