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
62 if (!ao_flight_force_idle)
64 /* Set pad mode - we can fly! */
65 ao_flight_state = ao_flight_pad;
67 /* Disable the USB controller in flight mode
73 /* Disable packet mode in pad state */
74 ao_packet_slave_stop();
76 /* Turn on telemetry system */
78 ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_BALLOON);
80 /* signal successful initialization by turning off the LED */
81 ao_led_off(AO_LED_RED);
84 ao_flight_state = ao_flight_idle;
86 /* signal successful initialization by turning off the LED */
87 ao_led_off(AO_LED_RED);
89 /* wakeup threads due to state change */
90 ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
97 * barometer: > 20m vertical motion
99 if (ao_height > AO_M_TO_HEIGHT(20))
101 ao_flight_state = ao_flight_drogue;
103 /* start logging data */
107 /* Record current GPS position by waking up GPS log tasks */
108 ao_gps_new = AO_GPS_NEW_DATA | AO_GPS_NEW_TRACKING;
109 ao_wakeup(&ao_gps_new);
112 ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
115 case ao_flight_drogue:
122 static __xdata struct ao_task flight_task;
127 ao_flight_state = ao_flight_startup;
128 ao_add_task(&flight_task, ao_flight, "flight");