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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #ifndef AO_FLIGHT_TEST
24 #error Please define HAS_ACCEL
28 #error Please define HAS_GPS
32 #error Please define HAS_USB
36 /* Any sensor can set this to mark the flight computer as 'broken' */
37 __xdata uint8_t ao_sensor_errors;
40 __pdata uint16_t ao_motor_number; /* number of motors burned so far */
42 /* Main flight thread. */
44 __pdata enum ao_flight_state ao_flight_state; /* current flight state */
46 __pdata uint8_t ao_flight_force_idle;
52 ao_flight_state = ao_flight_startup;
56 * Process ADC samples, just looping
57 * until the sensors are calibrated.
62 switch (ao_flight_state) {
63 case ao_flight_startup:
65 /* Check to see what mode we should go to.
66 * - Invalid mode if accel cal appears to be out
67 * - pad mode if we're upright,
68 * - idle mode otherwise
70 if (!ao_flight_force_idle)
72 /* Set pad mode - we can fly! */
73 ao_flight_state = ao_flight_pad;
75 /* Disable the USB controller in flight mode
82 /* Disable packet mode in pad state */
83 ao_packet_slave_stop();
85 /* Turn on telemetry system */
87 ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_BALLOON);
89 /* signal successful initialization by turning off the LED */
90 ao_led_off(AO_LED_RED);
93 ao_flight_state = ao_flight_idle;
95 /* signal successful initialization by turning off the LED */
96 ao_led_off(AO_LED_RED);
98 /* wakeup threads due to state change */
99 ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
106 * barometer: > 20m vertical motion
108 if (ao_height > AO_M_TO_HEIGHT(20))
110 ao_flight_state = ao_flight_drogue;
112 /* start logging data */
116 /* Record current GPS position by waking up GPS log tasks */
117 ao_gps_new = AO_GPS_NEW_DATA | AO_GPS_NEW_TRACKING;
118 ao_wakeup(&ao_gps_new);
121 ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
130 static __xdata struct ao_task flight_task;
135 ao_flight_state = ao_flight_startup;
136 ao_add_task(&flight_task, ao_flight, "flight");