altos: Create custom nano flight code
authorKeith Packard <keithp@keithp.com>
Tue, 29 Mar 2011 01:18:50 +0000 (18:18 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 29 Mar 2011 01:18:50 +0000 (18:18 -0700)
No igniters, just 'pad/drogue/landed' modes (where 'drogue' ==
'flying'). A constant 1Hz telemetry and RDF rate.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/Makefile.proto
src/ao.h
src/ao_flight_nano.c [new file with mode: 0644]
src/ao_pins.h
src/ao_report.c
src/ao_telenano.c

index 8dd21a64f6d9186665b97b4c6ede394040fe1b2f..5aad445fa44c3aaff4efc9ad5c89b71bc02712b7 100644 (file)
@@ -204,13 +204,12 @@ TMINI_BASE_SRC = \
 # Sources for TeleNano
 TNANO_DRIVER_SRC = \
        ao_adc.c \
-       ao_ignite.c \
        ao_config.c \
        ao_storage.c \
        ao_intflash.c
 
 TNANO_TASK_SRC = \
-       ao_flight.c \
+       ao_flight_nano.c \
        ao_sample.c \
        ao_kalman.c \
        ao_log.c \
index 42c3edda85ec41c1121470a673077b6dc7a2995c..89109fd964449926bb4141020f61aa90c0982df1 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -708,6 +708,13 @@ ao_flight(void);
 void
 ao_flight_init(void);
 
+/*
+ * ao_flight_nano.c
+ */
+
+void
+ao_flight_nano_init(void);
+
 /*
  * ao_sample.c
  */
diff --git a/src/ao_flight_nano.c b/src/ao_flight_nano.c
new file mode 100644 (file)
index 0000000..64c1d8d
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "ao.h"
+
+/* Main flight thread. */
+
+__pdata enum ao_flight_state   ao_flight_state;        /* current flight state */
+__pdata uint16_t               ao_launch_tick;         /* time of launch detect */
+
+/*
+ * track min/max data over a long interval to detect
+ * resting
+ */
+__pdata uint16_t               ao_interval_end;
+__pdata int16_t                        ao_interval_min_height;
+__pdata int16_t                        ao_interval_max_height;
+
+__xdata uint8_t                        ao_flight_force_idle;
+
+/* Landing is detected by getting constant readings from both pressure and accelerometer
+ * for a fairly long time (AO_INTERVAL_TICKS)
+ */
+#define AO_INTERVAL_TICKS      AO_SEC_TO_TICKS(5)
+
+static void
+ao_flight_nano(void)
+{
+       ao_sample_init();
+       ao_flight_state = ao_flight_startup;
+
+       for (;;) {
+               /*
+                * Process ADC samples, just looping
+                * until the sensors are calibrated.
+                */
+               if (!ao_sample())
+                       continue;
+
+               switch (ao_flight_state) {
+               case ao_flight_startup:
+                       if (ao_flight_force_idle) {
+                               /* Set idle mode */
+                               ao_flight_state = ao_flight_idle;
+                       } else {
+                               ao_flight_state = ao_flight_pad;
+                               /* Disable packet mode in pad state */
+                               ao_packet_slave_stop();
+
+                               /* Turn on telemetry system */
+                               ao_rdf_set(1);
+                               ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_PAD);
+                       }
+                       /* signal successful initialization by turning off the LED */
+                       ao_led_off(AO_LED_RED);
+
+                       /* wakeup threads due to state change */
+                       ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
+                       break;
+               case ao_flight_pad:
+                       if (ao_height> AO_M_TO_HEIGHT(20)) {
+                               ao_flight_state = ao_flight_drogue;
+                               ao_launch_tick = ao_sample_tick;
+                               ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
+                       }
+                       break;
+               case ao_flight_drogue:
+                       /* drogue/main to land:
+                        *
+                        * barometer: altitude stable
+                        */
+
+                       if (ao_height < ao_interval_min_height)
+                               ao_interval_min_height = ao_height;
+                       if (ao_height > ao_interval_max_height)
+                               ao_interval_max_height = ao_height;
+
+                       if ((int16_t) (ao_sample_tick - ao_interval_end) >= 0) {
+                               if (ao_interval_max_height - ao_interval_min_height < AO_M_TO_HEIGHT(5))
+                               {
+                                       ao_flight_state = ao_flight_landed;
+
+                                       /* turn off the ADC capture */
+                                       ao_timer_set_adc_interval(0);
+                                       ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
+                               }
+                               ao_interval_min_height = ao_interval_max_height = ao_height;
+                               ao_interval_end = ao_sample_tick + AO_INTERVAL_TICKS;
+                       }
+                       break;
+               }
+       }
+}
+
+static __xdata struct ao_task  flight_task;
+
+void
+ao_flight_nano_init(void)
+{
+       ao_flight_state = ao_flight_startup;
+       ao_add_task(&flight_task, ao_flight_nano, "flight");
+}
index a4a93aab6690d90c829472af7812806de2b155e4..30f2decc1e92987e6d7a594f81a20a8e36df2677 100644 (file)
@@ -40,6 +40,7 @@
        #define HAS_EXTERNAL_TEMP       0
        #define HAS_ACCEL_REF           0
        #define HAS_ACCEL               1
+       #define HAS_IGNITE              1
 #endif
 
 #if defined(TELEMETRUM_V_1_1)
@@ -68,6 +69,7 @@
        #define M25_CS_MASK             0x02    /* CS0 is P1_1 */
        #define M25_MAX_CHIPS           1
        #define HAS_ACCEL               1
+       #define HAS_IGNITE              1
 #endif
 
 #if defined(TELEDONGLE_V_0_2)
@@ -89,6 +91,7 @@
        #define LEDS_AVAILABLE          (AO_LED_RED|AO_LED_GREEN)
        #define SPI_CS_ON_P1            1
        #define SPI_CS_ON_P0            0
+       #define HAS_IGNITE              0
 #endif
 
 #if defined(TELEMINI_V_0_1)
        #define LEDS_AVAILABLE          (AO_LED_RED|AO_LED_GREEN)
        #define HAS_EXTERNAL_TEMP       0
        #define HAS_ACCEL               0
+       #define HAS_IGNITE              1
 #endif
 
 #if defined(TELENANO_V_0_1)
        #define LEDS_AVAILABLE          (AO_LED_RED|AO_LED_GREEN)
        #define HAS_EXTERNAL_TEMP       0
        #define HAS_ACCEL               0
+       #define HAS_IGNITE              0
 #endif
 
 #if defined(TELEMETRUM_V_0_1)
        #define SPI_CS_ON_P1            1
        #define SPI_CS_ON_P0            0
        #define HAS_ACCEL               1
+       #define HAS_IGNITE              1
 #endif
 
 #if defined(TELEDONGLE_V_0_1)
        #define LEDS_AVAILABLE          (AO_LED_RED|AO_LED_GREEN)
        #define SPI_CS_ON_P1            0
        #define SPI_CS_ON_P0            1
+       #define HAS_IGNITE              0
 #endif
 
 #if defined(TIDONGLE)
        #define LEDS_AVAILABLE          (AO_LED_RED)
        #define SPI_CS_ON_P1            0
        #define SPI_CS_ON_P0            1
+       #define HAS_IGNITE              0
 #endif
 
 #if DBG_ON_P1
 #error Please define HAS_DBG
 #endif
 
+#ifndef HAS_IGNITE
+#error Please define HAS_IGNITE
+#endif
+
 #ifndef PACKET_HAS_MASTER
 #error Please define PACKET_HAS_MASTER
 #endif
index 4f7fd65786743fef7ba86b5fa3794c40b83bb545..b9dc5bb419979d5d5f960a67f23aa89eba186fad 100644 (file)
@@ -109,6 +109,7 @@ ao_report_altitude(void)
        }
 }
 
+#if HAS_IGNITE
 static uint8_t
 ao_report_igniter_ready(enum ao_igniter igniter)
 {
@@ -146,6 +147,7 @@ ao_report_continuity(void) __reentrant
        while (c-- && ao_flight_state == ao_flight_pad)
                pause(AO_MS_TO_TICKS(100));
 }
+#endif
 
 void
 ao_report(void)
@@ -155,10 +157,12 @@ ao_report(void)
                if (ao_flight_state == ao_flight_landed)
                        ao_report_altitude();
                ao_report_beep();
+#if HAS_IGNITE
                if (ao_flight_state == ao_flight_idle)
                        ao_report_continuity();
                while (ao_flight_state == ao_flight_pad)
                        ao_report_continuity();
+#endif
                __critical {
                        while (ao_report_state == ao_flight_state)
                                ao_sleep(DATA_TO_XDATA(&ao_flight_state));
index dbc3b74c097bc2ab655c39b80d4d421c9f79137d..47b7b3c3b1852bc01c4a8c6d63c7cc47251d0e1c 100644 (file)
@@ -39,13 +39,12 @@ main(void)
        ao_adc_init();
        ao_cmd_init();
        ao_storage_init();
-       ao_flight_init();
+       ao_flight_nano_init();
        ao_log_init();
        ao_report_init();
        ao_telemetry_tiny_init();
        ao_radio_init();
        ao_packet_slave_init(TRUE);
-       ao_igniter_init();
        ao_config_init();
        ao_start_scheduler();
 }