From 9513be7f9d3d0b0ec29f6487fa9dc8f1ac24d0de Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 25 Aug 2011 20:43:44 -0700 Subject: altos: Restructure altos build to prepare for multi-arch support Split out sources into separate directories: core: architecture and product independent bits cc1111: cc1111-specific code drivers: architecture independent drivers product: product-specific sources and Makefile fragments util: scripts for building stuff This should have no effect on the built products, but testing is encouraged Signed-off-by: Keith Packard --- src/core/ao_kalman.c | 292 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 src/core/ao_kalman.c (limited to 'src/core/ao_kalman.c') diff --git a/src/core/ao_kalman.c b/src/core/ao_kalman.c new file mode 100644 index 00000000..ee01949e --- /dev/null +++ b/src/core/ao_kalman.c @@ -0,0 +1,292 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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. + */ + +#ifndef AO_FLIGHT_TEST +#include "ao.h" +#endif + +#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; + +#define AO_K_STEP_100 to_fix16(0.01) +#define AO_K_STEP_2_2_100 to_fix16(0.00005) + +#define AO_K_STEP_10 to_fix16(0.1) +#define AO_K_STEP_2_2_10 to_fix16(0.005) + +#define AO_K_STEP_1 to_fix16(1) +#define AO_K_STEP_2_2_1 to_fix16(0.5) + +__pdata int16_t ao_height; +__pdata int16_t ao_speed; +__pdata int16_t ao_accel; +__pdata int16_t ao_max_height; +static __pdata int32_t ao_avg_height_scaled; +__pdata int16_t ao_avg_height; + +__pdata int16_t ao_error_h; +__pdata int16_t ao_error_h_sq_avg; + +#if HAS_ACCEL +__pdata int16_t ao_error_a; +#endif + +static void +ao_kalman_predict(void) +{ +#ifdef AO_FLIGHT_TEST + if (ao_sample_tick - ao_sample_prev_tick > 50) { + ao_k_height += ((int32_t) ao_speed * AO_K_STEP_1 + + (int32_t) ao_accel * AO_K_STEP_2_2_1) >> 4; + ao_k_speed += (int32_t) ao_accel * AO_K_STEP_1; + + return; + } + if (ao_sample_tick - ao_sample_prev_tick > 5) { + ao_k_height += ((int32_t) ao_speed * AO_K_STEP_10 + + (int32_t) ao_accel * AO_K_STEP_2_2_10) >> 4; + ao_k_speed += (int32_t) ao_accel * AO_K_STEP_10; + + return; + } + if (ao_flight_debug) { + printf ("predict speed %g + (%g * %g) = %g\n", + ao_k_speed / (65536.0 * 16.0), ao_accel / 16.0, AO_K_STEP_100 / 65536.0, + (ao_k_speed + (int32_t) ao_accel * AO_K_STEP_100) / (65536.0 * 16.0)); + } +#endif + ao_k_height += ((int32_t) ao_speed * AO_K_STEP_100 + + (int32_t) ao_accel * AO_K_STEP_2_2_100) >> 4; + ao_k_speed += (int32_t) ao_accel * AO_K_STEP_100; +} + +static void +ao_kalman_err_height(void) +{ + int16_t e; + int16_t height_distrust; +#if HAS_ACCEL + int16_t speed_distrust; +#endif + + ao_error_h = ao_sample_height - (int16_t) (ao_k_height >> 16); + + e = ao_error_h; + if (e < 0) + e = -e; + if (e > 127) + e = 127; +#if HAS_ACCEL + ao_error_h_sq_avg -= ao_error_h_sq_avg >> 2; + ao_error_h_sq_avg += (e * e) >> 2; +#else + ao_error_h_sq_avg -= ao_error_h_sq_avg >> 4; + ao_error_h_sq_avg += (e * e) >> 4; +#endif + + if (ao_flight_state >= ao_flight_drogue) + return; + height_distrust = ao_sample_alt - AO_MAX_BARO_HEIGHT; +#if HAS_ACCEL + /* speed is stored * 16, but we need to ramp between 200 and 328, so + * we want to multiply by 2. The result is a shift by 3. + */ + speed_distrust = (ao_speed - AO_MS_TO_SPEED(AO_MAX_BARO_SPEED)) >> (4 - 1); + if (speed_distrust <= 0) + speed_distrust = 0; + else if (speed_distrust > height_distrust) + height_distrust = speed_distrust; +#endif + if (height_distrust > 0) { +#ifdef AO_FLIGHT_TEST + int old_ao_error_h = ao_error_h; +#endif + if (height_distrust > 0x100) + height_distrust = 0x100; + ao_error_h = (int16_t) (((int32_t) ao_error_h * (0x100 - height_distrust)) >> 8); +#ifdef AO_FLIGHT_TEST + if (ao_flight_debug) { + printf("over height %g over speed %g distrust: %g height: error %d -> %d\n", + (double) (ao_sample_alt - AO_MAX_BARO_HEIGHT), + (ao_speed - AO_MS_TO_SPEED(AO_MAX_BARO_SPEED)) / 16.0, + height_distrust / 256.0, + old_ao_error_h, ao_error_h); + } +#endif + } +} + +static void +ao_kalman_correct_baro(void) +{ + ao_kalman_err_height(); +#ifdef AO_FLIGHT_TEST + if (ao_sample_tick - ao_sample_prev_tick > 50) { + ao_k_height += (int32_t) AO_BARO_K0_1 * ao_error_h; + ao_k_speed += (int32_t) AO_BARO_K1_1 * ao_error_h; + ao_k_accel += (int32_t) AO_BARO_K2_1 * ao_error_h; + return; + } + if (ao_sample_tick - ao_sample_prev_tick > 5) { + ao_k_height += (int32_t) AO_BARO_K0_10 * ao_error_h; + ao_k_speed += (int32_t) AO_BARO_K1_10 * ao_error_h; + ao_k_accel += (int32_t) AO_BARO_K2_10 * ao_error_h; + return; + } +#endif + ao_k_height += (int32_t) AO_BARO_K0_100 * ao_error_h; + ao_k_speed += (int32_t) AO_BARO_K1_100 * ao_error_h; + ao_k_accel += (int32_t) AO_BARO_K2_100 * ao_error_h; +} + +#if HAS_ACCEL + +static void +ao_kalman_err_accel(void) +{ + int32_t accel; + + accel = (ao_ground_accel - ao_sample_accel) * ao_accel_scale; + + /* Can't use ao_accel here as it is the pre-prediction value still */ + ao_error_a = (accel - ao_k_accel) >> 16; +} + +static void +ao_kalman_correct_both(void) +{ + ao_kalman_err_height(); + ao_kalman_err_accel(); + +#ifdef AO_FLIGHT_TEST + if (ao_sample_tick - ao_sample_prev_tick > 50) { + if (ao_flight_debug) { + printf ("correct speed %g + (%g * %g) + (%g * %g) = %g\n", + ao_k_speed / (65536.0 * 16.0), + (double) ao_error_h, AO_BOTH_K10_1 / 65536.0, + (double) ao_error_a, AO_BOTH_K11_1 / 65536.0, + (ao_k_speed + + (int32_t) AO_BOTH_K10_1 * ao_error_h + + (int32_t) AO_BOTH_K11_1 * ao_error_a) / (65536.0 * 16.0)); + } + ao_k_height += + (int32_t) AO_BOTH_K00_1 * ao_error_h + + (int32_t) AO_BOTH_K01_1 * ao_error_a; + ao_k_speed += + (int32_t) AO_BOTH_K10_1 * ao_error_h + + (int32_t) AO_BOTH_K11_1 * ao_error_a; + ao_k_accel += + (int32_t) AO_BOTH_K20_1 * ao_error_h + + (int32_t) AO_BOTH_K21_1 * ao_error_a; + return; + } + if (ao_sample_tick - ao_sample_prev_tick > 5) { + if (ao_flight_debug) { + printf ("correct speed %g + (%g * %g) + (%g * %g) = %g\n", + ao_k_speed / (65536.0 * 16.0), + (double) ao_error_h, AO_BOTH_K10_10 / 65536.0, + (double) ao_error_a, AO_BOTH_K11_10 / 65536.0, + (ao_k_speed + + (int32_t) AO_BOTH_K10_10 * ao_error_h + + (int32_t) AO_BOTH_K11_10 * ao_error_a) / (65536.0 * 16.0)); + } + ao_k_height += + (int32_t) AO_BOTH_K00_10 * ao_error_h + + (int32_t) AO_BOTH_K01_10 * ao_error_a; + ao_k_speed += + (int32_t) AO_BOTH_K10_10 * ao_error_h + + (int32_t) AO_BOTH_K11_10 * ao_error_a; + ao_k_accel += + (int32_t) AO_BOTH_K20_10 * ao_error_h + + (int32_t) AO_BOTH_K21_10 * ao_error_a; + return; + } + if (ao_flight_debug) { + printf ("correct speed %g + (%g * %g) + (%g * %g) = %g\n", + ao_k_speed / (65536.0 * 16.0), + (double) ao_error_h, AO_BOTH_K10_100 / 65536.0, + (double) ao_error_a, AO_BOTH_K11_100 / 65536.0, + (ao_k_speed + + (int32_t) AO_BOTH_K10_100 * ao_error_h + + (int32_t) AO_BOTH_K11_100 * ao_error_a) / (65536.0 * 16.0)); + } +#endif + ao_k_height += + (int32_t) AO_BOTH_K00_100 * ao_error_h + + (int32_t) AO_BOTH_K01_100 * ao_error_a; + ao_k_speed += + (int32_t) AO_BOTH_K10_100 * ao_error_h + + (int32_t) AO_BOTH_K11_100 * ao_error_a; + ao_k_accel += + (int32_t) AO_BOTH_K20_100 * ao_error_h + + (int32_t) AO_BOTH_K21_100 * ao_error_a; +} + +#ifdef FORCE_ACCEL +static void +ao_kalman_correct_accel(void) +{ + ao_kalman_err_accel(); + + if (ao_sample_tick - ao_sample_prev_tick > 5) { + ao_k_height +=(int32_t) AO_ACCEL_K0_10 * ao_error_a; + ao_k_speed += (int32_t) AO_ACCEL_K1_10 * ao_error_a; + ao_k_accel += (int32_t) AO_ACCEL_K2_10 * ao_error_a; + return; + } + ao_k_height += (int32_t) AO_ACCEL_K0_100 * ao_error_a; + ao_k_speed += (int32_t) AO_ACCEL_K1_100 * ao_error_a; + ao_k_accel += (int32_t) AO_ACCEL_K2_100 * ao_error_a; +} +#endif +#endif /* HAS_ACCEL */ + +void +ao_kalman(void) +{ + ao_kalman_predict(); +#if HAS_ACCEL + if (ao_flight_state <= ao_flight_coast) { +#ifdef FORCE_ACCEL + ao_kalman_correct_accel(); +#else + ao_kalman_correct_both(); +#endif + } else +#endif + ao_kalman_correct_baro(); + ao_height = from_fix(ao_k_height); + ao_speed = from_fix(ao_k_speed); + ao_accel = from_fix(ao_k_accel); + if (ao_height > ao_max_height) + ao_max_height = ao_height; + ao_avg_height_scaled = ao_avg_height_scaled - ao_avg_height + ao_sample_height; +#ifdef AO_FLIGHT_TEST + if (ao_sample_tick - ao_sample_prev_tick > 50) + ao_avg_height = (ao_avg_height_scaled + 1) >> 1; + else if (ao_sample_tick - ao_sample_prev_tick > 5) + ao_avg_height = (ao_avg_height_scaled + 7) >> 4; + else +#endif + ao_avg_height = (ao_avg_height_scaled + 63) >> 7; +#ifdef AO_FLIGHT_TEST + ao_sample_prev_tick = ao_sample_tick; +#endif +} -- cgit v1.2.3 From 78423f3fc5164ea9fd428606419784c1700ad5c5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 25 May 2012 23:18:06 -0600 Subject: Get megametrum ready to at least log flight data Doesn't track flight state changes correctly. Signed-off-by: Keith Packard --- src/core/ao_adc.h | 5 ++- src/core/ao_config.c | 33 ++++++++++++++++---- src/core/ao_kalman.c | 3 ++ src/core/ao_log.c | 3 +- src/core/ao_log.h | 62 ++++++++++++++++++++++++++++++++++++- src/core/ao_sample.h | 19 +++++++----- src/megametrum-v0.1/Makefile | 19 +++++++++--- src/megametrum-v0.1/ao_megametrum.c | 8 +++-- src/megametrum-v0.1/ao_pins.h | 7 ++++- src/stm/ao_adc_stm.c | 42 ++++++++++++++++++------- 10 files changed, 164 insertions(+), 37 deletions(-) (limited to 'src/core/ao_kalman.c') diff --git a/src/core/ao_adc.h b/src/core/ao_adc.h index db5bfab3..8ec740c4 100644 --- a/src/core/ao_adc.h +++ b/src/core/ao_adc.h @@ -18,13 +18,11 @@ #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 diff --git a/src/core/ao_config.c b/src/core/ao_config.c index 55fb8590..55ec9f40 100644 --- a/src/core/ao_config.c +++ b/src/core/ao_config.c @@ -16,6 +16,9 @@ */ #include "ao.h" +#include "ao_log.h" +#include +#include __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 \0Apogee detect lockout (s)", ao_config_apogee_lockout_set, ao_config_apogee_lockout_show, }, #endif /* HAS_FLIGHT */ +#if HAS_RADIO { "F \0Frequency (kHz)", ao_config_frequency_set, ao_config_frequency_show }, { "c \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 \0Radio calib (cal = rf/(xtal/2^16))", ao_config_radio_cal_set, ao_config_radio_cal_show }, +#endif /* HAS_RADIO */ #if HAS_LOG { "l \0Flight log size (kB)", ao_config_log_set, ao_config_log_show }, diff --git a/src/core/ao_kalman.c b/src/core/ao_kalman.c index ee01949e..68725f69 100644 --- a/src/core/ao_kalman.c +++ b/src/core/ao_kalman.c @@ -17,10 +17,13 @@ #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; diff --git a/src/core/ao_log.c b/src/core/ao_log.c index db60707d..d696625e 100644 --- a/src/core/ao_log.c +++ b/src/core/ao_log.c @@ -16,12 +16,13 @@ */ #include "ao.h" +#include __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; diff --git a/src/core/ao_log.h b/src/core/ao_log.h index 611c00d5..e585750f 100644 --- a/src/core/ao_log.h +++ b/src/core/ao_log.h @@ -18,6 +18,8 @@ #ifndef _AO_LOG_H_ #define _AO_LOG_H_ +#include + /* * 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_ */ diff --git a/src/core/ao_sample.h b/src/core/ao_sample.h index fb0e69e8..189b2019 100644 --- a/src/core/ao_sample.h +++ b/src/core/ao_sample.h @@ -18,6 +18,8 @@ #ifndef _AO_SAMPLE_H_ #define _AO_SAMPLE_H_ +#include + /* * ao_sample.c */ @@ -88,21 +90,22 @@ #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 diff --git a/src/megametrum-v0.1/Makefile b/src/megametrum-v0.1/Makefile index 6524d8b8..a07b25ee 100644 --- a/src/megametrum-v0.1/Makefile +++ b/src/megametrum-v0.1/Makefile @@ -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 diff --git a/src/megametrum-v0.1/ao_megametrum.c b/src/megametrum-v0.1/ao_megametrum.c index 2e1f9298..19746d37 100644 --- a/src/megametrum-v0.1/ao_megametrum.c +++ b/src/megametrum-v0.1/ao_megametrum.c @@ -18,6 +18,7 @@ #include #include #include +#include #include 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(); diff --git a/src/megametrum-v0.1/ao_pins.h b/src/megametrum-v0.1/ao_pins.h index adc56151..3ab7e15a 100644 --- a/src/megametrum-v0.1/ao_pins.h +++ b/src/megametrum-v0.1/ao_pins.h @@ -94,9 +94,12 @@ #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) diff --git a/src/stm/ao_adc_stm.c b/src/stm/ao_adc_stm.c index a2569908..af2968d6 100644 --- a/src/stm/ao_adc_stm.c +++ b/src/stm/ao_adc_stm.c @@ -16,10 +16,17 @@ */ #include +#include +#if HAS_MPU6000 +#include +#endif +#if HAS_MS5607 +#include +#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"); -- cgit v1.2.3 From 6694cedd560a7ea9520ef11472c2770b489187c0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 10 Jul 2012 15:13:18 -0700 Subject: altos: Eliminate compiler warnings when building ao_flight_test We turn on a pile of warnings for that. Signed-off-by: Keith Packard --- src/core/ao_flight.c | 4 +++- src/core/ao_kalman.c | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/core/ao_kalman.c') diff --git a/src/core/ao_flight.c b/src/core/ao_flight.c index a0affc48..39084fd0 100644 --- a/src/core/ao_flight.c +++ b/src/core/ao_flight.c @@ -48,7 +48,9 @@ __pdata uint16_t ao_boost_tick; /* time of launch detect */ static __data uint16_t ao_interval_end; static __data int16_t ao_interval_min_height; static __data int16_t ao_interval_max_height; +#if HAS_ACCEL static __data int16_t ao_coast_avg_accel; +#endif __pdata uint8_t ao_flight_force_idle; @@ -350,7 +352,7 @@ ao_flight(void) ao_interval_end = ao_sample_tick + AO_INTERVAL_TICKS; } break; - case ao_flight_landed: + default: break; } } diff --git a/src/core/ao_kalman.c b/src/core/ao_kalman.c index 68725f69..59ffd8b2 100644 --- a/src/core/ao_kalman.c +++ b/src/core/ao_kalman.c @@ -172,6 +172,7 @@ ao_kalman_err_accel(void) ao_error_a = (accel - ao_k_accel) >> 16; } +#ifndef FORCE_ACCEL static void ao_kalman_correct_both(void) { @@ -242,7 +243,8 @@ ao_kalman_correct_both(void) (int32_t) AO_BOTH_K21_100 * ao_error_a; } -#ifdef FORCE_ACCEL +#else + static void ao_kalman_correct_accel(void) { @@ -258,7 +260,8 @@ ao_kalman_correct_accel(void) ao_k_speed += (int32_t) AO_ACCEL_K1_100 * ao_error_a; ao_k_accel += (int32_t) AO_ACCEL_K2_100 * ao_error_a; } -#endif + +#endif /* else FORCE_ACCEL */ #endif /* HAS_ACCEL */ void -- cgit v1.2.3