Get megametrum ready to at least log flight data
authorKeith Packard <keithp@keithp.com>
Sat, 26 May 2012 05:18:06 +0000 (23:18 -0600)
committerKeith Packard <keithp@keithp.com>
Sat, 26 May 2012 05:18:06 +0000 (23:18 -0600)
Doesn't track flight state changes correctly.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao_adc.h
src/core/ao_config.c
src/core/ao_kalman.c
src/core/ao_log.c
src/core/ao_log.h
src/core/ao_sample.h
src/megametrum-v0.1/Makefile
src/megametrum-v0.1/ao_megametrum.c
src/megametrum-v0.1/ao_pins.h
src/stm/ao_adc_stm.c

index db5bfab31c86f1e801fb13e9f703cf7dabcc129d..8ec740c458ae7b497329e581c43f0c556546c8fa 100644 (file)
 #ifndef _AO_ADC_H_
 #define _AO_ADC_H_
 
-
-
 /*
  * One set of samples read from the A/D converter or telemetry
  */
 
-
+#if AO_ADC_RING
 /*
  * ao_adc.c
  */
@@ -42,6 +40,7 @@ extern volatile __data uint8_t                ao_adc_head;
 #if HAS_ACCEL_REF
 extern volatile __xdata uint16_t       ao_accel_ref[AO_ADC_RING];
 #endif
+#endif
 
 /* Trigger a conversion sequence (called from the timer interrupt) */
 void
index 55fb8590eb74669eb2bf9fee6b2f62f7351cc91b..55ec9f406e35eb8e439b3092a123ae5a209bde12 100644 (file)
@@ -16,6 +16,9 @@
  */
 
 #include "ao.h"
+#include "ao_log.h"
+#include <ao_sample.h>
+#include <ao_data.h>
 
 __xdata struct ao_config ao_config;
 __pdata uint8_t ao_config_loaded;
@@ -64,11 +67,13 @@ ao_config_put(void)
 }
 #endif
 
+#if HAS_RADIO
 void
 ao_config_set_radio(void)
 {
        ao_config.radio_setting = ao_freq_to_set(ao_config.frequency, ao_config.radio_cal);
 }
+#endif /* HAS_RADIO */
 
 static void
 _ao_config_get(void)
@@ -100,8 +105,10 @@ _ao_config_get(void)
                        ao_config.accel_minus_g = 0;
                }
                /* Fixups for minor version 3 */
+#if HAS_RADIO
                if (ao_config.minor < 3)
                        ao_config.radio_cal = ao_radio_cal;
+#endif
                /* Fixups for minor version 4 */
                if (ao_config.minor < 4)
                        ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX;
@@ -121,7 +128,9 @@ _ao_config_get(void)
                ao_config.minor = AO_CONFIG_MINOR;
                ao_config_dirty = 1;
        }
+#if HAS_RADIO
        ao_config_set_radio();
+#endif
        ao_config_loaded = 1;
 }
 
@@ -176,6 +185,7 @@ ao_config_callsign_set(void) __reentrant
        _ao_config_edit_finish();
 }
 
+#if HAS_RADIO
 void
 ao_config_frequency_show(void) __reentrant
 {
@@ -195,6 +205,7 @@ ao_config_frequency_set(void) __reentrant
        _ao_config_edit_finish();
        ao_radio_recv_abort();
 }
+#endif
 
 #if HAS_FLIGHT
 
@@ -232,7 +243,7 @@ ao_config_accel_calibrate_auto(char *orientation) __reentrant
 {
        uint16_t        i;
        int32_t         accel_total;
-       uint8_t         cal_adc_ring;
+       uint8_t         cal_data_ring;
 
        printf("Orient antenna %s and press a key...", orientation);
        flush();
@@ -241,12 +252,14 @@ ao_config_accel_calibrate_auto(char *orientation) __reentrant
        puts("Calibrating..."); flush();
        i = ACCEL_CALIBRATE_SAMPLES;
        accel_total = 0;
-       cal_adc_ring = ao_sample_adc;
+       cal_data_ring = ao_sample_data;
        while (i) {
-               ao_sleep(DATA_TO_XDATA(&ao_sample_adc));
-               while (i && cal_adc_ring != ao_sample_adc) {
-                       accel_total += (int32_t) ao_adc_ring[cal_adc_ring].accel;
-                       cal_adc_ring = ao_adc_ring_next(cal_adc_ring);
+               ao_sleep(DATA_TO_XDATA(&ao_sample_data));
+               while (i && cal_data_ring != ao_sample_data) {
+                       int16_t accel = ao_data_accel(&ao_data_ring[cal_data_ring]);
+                       printf ("accel %d\n", accel);
+                       accel_total += (int32_t) ao_data_accel(&ao_data_ring[cal_data_ring]);
+                       cal_data_ring = ao_data_ring_next(cal_data_ring);
                        i--;
                }
        }
@@ -320,6 +333,7 @@ ao_config_apogee_lockout_set(void) __reentrant
 
 #endif /* HAS_FLIGHT */
 
+#if HAS_RADIO
 void
 ao_config_radio_cal_show(void) __reentrant
 {
@@ -337,6 +351,7 @@ ao_config_radio_cal_set(void) __reentrant
        ao_config_set_radio();
        _ao_config_edit_finish();
 }
+#endif
 
 #if HAS_LOG
 void
@@ -413,6 +428,7 @@ ao_config_pad_orientation_set(void) __reentrant
 }
 #endif
 
+#if HAS_RADIO
 void
 ao_config_radio_enable_show(void) __reentrant
 {
@@ -429,6 +445,7 @@ ao_config_radio_enable_set(void) __reentrant
        ao_config.radio_enable = ao_cmd_lex_i;
        _ao_config_edit_finish();
 }
+#endif /* HAS_RADIO */
        
 #if HAS_AES
 void
@@ -481,18 +498,22 @@ __code struct ao_config_var ao_config_vars[] = {
        { "L <seconds>\0Apogee detect lockout (s)",
          ao_config_apogee_lockout_set, ao_config_apogee_lockout_show, },
 #endif /* HAS_FLIGHT */
+#if HAS_RADIO
        { "F <freq>\0Frequency (kHz)",
          ao_config_frequency_set, ao_config_frequency_show },
        { "c <call>\0Callsign (8 char max)",
          ao_config_callsign_set,       ao_config_callsign_show },
        { "e <0 disable, 1 enable>\0Enable telemetry and RDF",
          ao_config_radio_enable_set, ao_config_radio_enable_show },
+#endif /* HAS_RADIO */
 #if HAS_ACCEL
        { "a <+g> <-g>\0Accel calib (0 for auto)",
          ao_config_accel_calibrate_set,ao_config_accel_calibrate_show },
 #endif /* HAS_ACCEL */
+#if HAS_RADIO
        { "f <cal>\0Radio calib (cal = rf/(xtal/2^16))",
          ao_config_radio_cal_set,      ao_config_radio_cal_show },
+#endif /* HAS_RADIO */
 #if HAS_LOG
        { "l <size>\0Flight log size (kB)",
          ao_config_log_set,            ao_config_log_show },
index ee01949e5e54a416bc9737e56bb20a03261f8bc1..68725f6978bf4c9cf3dc45b9ae97065624dde3ae 100644 (file)
 
 #ifndef AO_FLIGHT_TEST
 #include "ao.h"
+#include "ao_flight.h"
 #endif
 
+#include "ao_sample.h"
 #include "ao_kalman.h"
 
+
 static __pdata int32_t         ao_k_height;
 static __pdata int32_t         ao_k_speed;
 static __pdata int32_t         ao_k_accel;
index db60707d581a927a57027c3fc67fa6c3f3b97694..d696625efbf79ab5d6b9173bcb35ea63844b2cbe 100644 (file)
  */
 
 #include "ao.h"
+#include <ao_log.h>
 
 __pdata uint32_t ao_log_current_pos;
 __pdata uint32_t ao_log_end_pos;
 __pdata uint32_t ao_log_start_pos;
 __xdata uint8_t        ao_log_running;
-__pdata enum flight_state ao_log_state;
+__pdata enum ao_flight_state ao_log_state;
 __xdata uint16_t ao_flight_number;
 
 __code uint8_t ao_log_format = AO_LOG_FORMAT_FULL;
index 611c00d526f367fcb20f26f72aae39c0104ab732..e585750f9a73c20def2d4b101119e2b162ac46fa 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef _AO_LOG_H_
 #define _AO_LOG_H_
 
+#include <ao_flight.h>
+
 /*
  * ao_log.c
  */
@@ -32,7 +34,7 @@ extern __pdata uint32_t ao_log_current_pos;
 extern __pdata uint32_t ao_log_end_pos;
 extern __pdata uint32_t ao_log_start_pos;
 extern __xdata uint8_t ao_log_running;
-extern __pdata enum flight_state ao_log_state;
+extern __pdata enum ao_flight_state ao_log_state;
 
 /* required functions from the underlying log system */
 
@@ -41,6 +43,7 @@ extern __pdata enum flight_state ao_log_state;
 #define AO_LOG_FORMAT_TINY             2       /* two byte state/baro records */
 #define AO_LOG_FORMAT_TELEMETRY                3       /* 32 byte ao_telemetry records */
 #define AO_LOG_FORMAT_TELESCIENCE      4       /* 32 byte typed telescience records */
+#define AO_LOG_FORMAT_MEGAMETRUM       5       /* 32 byte typed megametrum records */
 #define AO_LOG_FORMAT_NONE             127     /* No log at all */
 
 extern __code uint8_t ao_log_format;
@@ -189,8 +192,65 @@ struct ao_log_record {
        } u;
 };
 
+struct ao_log_mega {
+       char                    type;                   /* 0 */
+       uint8_t                 csum;                   /* 1 */
+       uint16_t                tick;                   /* 2 */
+       union {                                         /* 4 */
+               struct {
+                       uint16_t        flight;         /* 4 */
+                       int16_t         ground_accel;   /* 6 */
+                       uint32_t        ground_pres;    /* 8 */
+                       uint32_t        ground_temp;    /* 12 */
+               } flight;                               /* 16 */
+               struct {
+                       uint16_t        state;
+                       uint16_t        reason;
+               } state;
+               struct {
+                       uint32_t        pres;           /* 4 */
+                       uint32_t        temp;           /* 8 */
+                       int16_t         accel_x;        /* 12 */
+                       int16_t         accel_y;        /* 14 */
+                       int16_t         accel_z;        /* 16 */
+                       int16_t         gyro_x;         /* 18 */
+                       int16_t         gyro_y;         /* 20 */
+                       int16_t         gyro_z;         /* 22 */
+               } sensor;       /* 24 */
+               struct {
+                       int16_t         v_batt;         /* 4 */
+                       int16_t         v_pbatt;        /* 8 */
+                       int16_t         n_sense;        /* 10 */
+                       int16_t         sense[10];      /* 12 */
+               } volt;                                 /* 32 */
+               struct {
+                       int32_t         latitude;       /* 4 */
+                       int32_t         longitude;      /* 8 */
+                       int16_t         altitude;       /* 12 */
+                       uint8_t         hour;           /* 14 */
+                       uint8_t         minute;         /* 15 */
+                       uint8_t         second;         /* 16 */
+                       uint8_t         flags;          /* 17 */
+                       uint8_t         year;           /* 18 */
+                       uint8_t         month;          /* 19 */
+                       uint8_t         day;            /* 20 */
+                       uint8_t         pad;            /* 21 */
+               } gps;  /* 22 */
+               struct {
+                       uint16_t        channels;       /* 4 */
+                       struct {
+                               uint8_t svid;
+                               uint8_t c_n;
+                       } sats[12];                     /* 6 */
+               } gps_sat;                              /* 30 */
+       } u;
+};
+
 /* Write a record to the eeprom log */
 uint8_t
 ao_log_data(__xdata struct ao_log_record *log) __reentrant;
 
+uint8_t
+ao_log_mega(__xdata struct ao_log_mega *log) __reentrant;
+
 #endif /* _AO_LOG_H_ */
index fb0e69e87e23c998fee745464e0ad33fb6d9f403..189b20197d81dfc7c6bf86e20cafcf4a2fb91e25 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef _AO_SAMPLE_H_
 #define _AO_SAMPLE_H_
 
+#include <ao_data.h>
+
 /*
  * ao_sample.c
  */
 #define AO_MSS_TO_ACCEL(mss)   ((int16_t) ((mss) * 16))
 
 extern __pdata uint16_t        ao_sample_tick;         /* time of last data */
-extern __pdata int16_t ao_sample_pres;         /* most recent pressure sensor reading */
-extern __pdata int16_t ao_sample_alt;          /* MSL of ao_sample_pres */
-extern __pdata int16_t ao_sample_height;       /* AGL of ao_sample_pres */
+extern __pdata pres_t  ao_sample_pres;         /* most recent pressure sensor reading */
+extern __pdata alt_t   ao_sample_alt;          /* MSL of ao_sample_pres */
+extern __pdata alt_t   ao_sample_height;       /* AGL of ao_sample_pres */
 extern __data uint8_t  ao_sample_adc;          /* Ring position of last processed sample */
+extern __data uint8_t  ao_sample_data;         /* Ring position of last processed sample */
 
 #if HAS_ACCEL
-extern __pdata int16_t ao_sample_accel;        /* most recent accel sensor reading */
+extern __pdata accel_t ao_sample_accel;        /* most recent accel sensor reading */
 #endif
 
-extern __pdata int16_t ao_ground_pres;         /* startup pressure */
-extern __pdata int16_t ao_ground_height;       /* MSL of ao_ground_pres */
+extern __pdata pres_t  ao_ground_pres;         /* startup pressure */
+extern __pdata alt_t   ao_ground_height;       /* MSL of ao_ground_pres */
 
 #if HAS_ACCEL
-extern __pdata int16_t ao_ground_accel;        /* startup acceleration */
-extern __pdata int16_t         ao_accel_2g;            /* factory accel calibration */
+extern __pdata accel_t ao_ground_accel;        /* startup acceleration */
+extern __pdata accel_t         ao_accel_2g;            /* factory accel calibration */
 extern __pdata int32_t ao_accel_scale;         /* sensor to m/s² conversion */
 #endif
 
index 6524d8b8442d63c9ddb53398d7e4549de4bb22ad..a07b25eeeab06eee19f53df24200416d7eb9cfe9 100644 (file)
@@ -9,6 +9,8 @@ INC = \
        ao.h \
        ao_arch.h \
        ao_arch_funcs.h \
+       ao_data.h \
+       ao_sample.h \
        ao_pins.h \
        altitude.h \
        ao_kalman.h \
@@ -21,6 +23,11 @@ INC = \
 #
 # Common AltOS sources
 #
+
+#      ao_cc1120.c \
+#      ao_packet.c \
+#      ao_packet_slave.c \
+
 ALTOS_SRC = \
        ao_interrupt.c \
        ao_product.c \
@@ -35,7 +42,6 @@ ALTOS_SRC = \
        ao_mutex.c \
        ao_serial_stm.c \
        ao_gps_skytraq.c \
-       ao_cc1120.c \
        ao_freq.c \
        ao_dma_stm.c \
        ao_spi_stm.c \
@@ -46,12 +52,17 @@ ALTOS_SRC = \
        ao_m25.c \
        ao_usb_stm.c \
        ao_exti_stm.c \
-       ao_packet.c \
-       ao_packet_slave.c \
+       ao_report.c \
        ao_i2c_stm.c \
        ao_hmc5883.c \
        ao_mpu6000.c \
-       ao_convert_pa.c
+       ao_convert_pa.c \
+       ao_log.c \
+       ao_log_mega.c \
+       ao_sample_mm.c \
+       ao_kalman.c \
+       ao_flight_mm.c
+
 
 PRODUCT=MegaMetrum-v0.1
 PRODUCT_DEF=-DMEGAMETRUM
index 2e1f92983218a84b87ec0a30469b5d8397f1e5b0..19746d378d2d63ccf230d79bd751ad336d4fb871 100644 (file)
@@ -18,6 +18,7 @@
 #include <ao.h>
 #include <ao_hmc5883.h>
 #include <ao_mpu6000.h>
+#include <ao_log.h>
 #include <ao_exti.h>
 
 void
@@ -46,7 +47,6 @@ main(void)
        ao_timer_init();
        ao_cmd_init();
        ao_gps_init();
-       ao_config_init();
        ao_dma_init();
        ao_spi_init();
        ao_ms5607_init();
@@ -55,10 +55,14 @@ main(void)
        ao_storage_init();
        ao_usb_init();
        ao_exti_init();
-       ao_radio_init();
+//     ao_radio_init();
        ao_i2c_init();
        ao_hmc5883_init();
        ao_mpu6000_init();
+       ao_flight_init();
+       ao_log_init();
+       ao_report_init();
+       ao_config_init();
        
        ao_cmd_register(&ao_mm_cmds[0]);
        ao_start_scheduler();
index adc561519cfd979733e5e73539e36d60c64aa6a1..3ab7e15ac883c540a8658b4db859095a1e137c81 100644 (file)
 
 #define LEDS_AVAILABLE         (AO_LED_RED | AO_LED_GREEN)
 
+#define HAS_GPS                        1
+#define HAS_FLIGHT             1
 #define HAS_ADC                        1
+#define HAS_ACCEL              1
 
-#define AO_ADC_RING            32
+#define AO_DATA_RING           32
 #define AO_ADC_NUM_SENSE       6
 
 struct ao_adc {
@@ -179,6 +182,7 @@ struct ao_adc {
 /*
  * Pressure sensor settings
  */
+#define HAS_MS5607             1
 #define AO_MS5607_CS_GPIO      stm_gpioc
 #define AO_MS5607_CS           4
 #define AO_MS5607_CS_MASK      (1 << AO_MS5607_CS)
@@ -221,6 +225,7 @@ struct ao_adc {
  * mpu6000
  */
 
+#define HAS_MPU6000            1       
 #define AO_MPU6000_INT_PORT    stm_gpioc
 #define AO_MPU6000_INT_PIN     13
 #define AO_MPU6000_I2C_INDEX   STM_I2C_INDEX(1)
index a256990851f3bfeb5af3c2e2e79b53f7a64a3f4d..af2968d6ea9df830933c63e92e775859968c2e10 100644 (file)
  */
 
 #include <ao.h>
+#include <ao_data.h>
+#if HAS_MPU6000
+#include <ao_mpu6000.h>
+#endif
+#if HAS_MS5607
+#include <ao_ms5607.h>
+#endif
 
+volatile __xdata struct ao_data        ao_data_ring[AO_DATA_RING];
+volatile __data uint8_t                ao_data_head;
 
-volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING];
-volatile __data uint8_t                ao_adc_head;
 static uint8_t                 ao_adc_ready;
 
 #define AO_ADC_CR2_VAL         ((0 << STM_ADC_CR2_SWSTART) |           \
@@ -43,9 +50,15 @@ static uint8_t                       ao_adc_ready;
  */
 static void ao_adc_done(int index)
 {
-       ao_adc_ring[ao_adc_head].tick = ao_time();
-       ao_adc_head = ao_adc_ring_next(ao_adc_head);
-       ao_wakeup((void *) &ao_adc_head);
+       ao_data_ring[ao_data_head].adc.tick = ao_time();
+#if HAS_MPU6000
+       ao_data_ring[ao_data_head].mpu6000 = ao_mpu6000_current;
+#endif
+#if HAS_MS5607
+       ao_data_ring[ao_data_head].ms5607 = ao_ms5607_current;
+#endif 
+       ao_data_head = ao_data_ring_next(ao_data_head);
+       ao_wakeup((void *) &ao_data_head);
        ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1));
        ao_adc_ready = 1;
 }
@@ -62,7 +75,7 @@ ao_adc_poll(void)
        stm_adc.sr = 0;
        ao_dma_set_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1),
                            &stm_adc.dr,
-                           (void *) (&ao_adc_ring[ao_adc_head].tick + 1),
+                           (void *) (&ao_data_ring[ao_data_head].tick + 1),
                            AO_NUM_ADC,
                            (0 << STM_DMA_CCR_MEM2MEM) |
                            (STM_DMA_CCR_PL_HIGH << STM_DMA_CCR_PL) |
@@ -84,20 +97,27 @@ ao_adc_poll(void)
 void
 ao_adc_get(__xdata struct ao_adc *packet)
 {
-       uint8_t i = ao_adc_ring_prev(ao_adc_head);
-       memcpy(packet, (void *) &ao_adc_ring[i], sizeof (struct ao_adc));
+       uint8_t i = ao_data_ring_prev(ao_data_head);
+       memcpy(packet, (void *) &ao_data_ring[i].adc, sizeof (struct ao_adc));
+}
+
+void
+ao_data_get(__xdata struct ao_data *packet)
+{
+       uint8_t i = ao_data_ring_prev(ao_data_head);
+       memcpy(packet, (void *) &ao_data_ring[i], sizeof (struct ao_data));
 }
 
 static void
 ao_adc_dump(void) __reentrant
 {
-       struct ao_adc   packet;
+       struct ao_data  packet;
        int16_t *d;
        uint8_t i;
 
-       ao_adc_get(&packet);
+       ao_data_get(&packet);
        printf("tick: %5u",  packet.tick);
-       d = (int16_t *) (&packet.tick + 1);
+       d = (int16_t *) (&packet.adc);
        for (i = 0; i < AO_NUM_ADC; i++)
                printf (" %2d: %5d", i, d[i]);
        printf("\n");