diff options
author | Bdale Garbee <bdale@gag.com> | 2014-01-22 20:55:41 -0700 |
---|---|---|
committer | Bdale Garbee <bdale@gag.com> | 2014-01-22 20:55:41 -0700 |
commit | 9884ca1449167a06bd2cebc7d28353eeac592493 (patch) | |
tree | 9fde328b3a5971c67954e669c1ba27042821fd8c /src/core | |
parent | 8e669694a60d34e2ea0f8f6b189e0bc3605d94d7 (diff) | |
parent | 0ef0c50536e5eb6ad3455b5828983307edbab828 (diff) |
Merge branch 'branch-1.3' into debian
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ao.h | 11 | ||||
-rw-r--r-- | src/core/ao_config.c | 26 | ||||
-rw-r--r-- | src/core/ao_convert_volt.c | 33 | ||||
-rw-r--r-- | src/core/ao_data.h | 8 | ||||
-rw-r--r-- | src/core/ao_fec.h | 2 | ||||
-rw-r--r-- | src/core/ao_flight.c | 22 | ||||
-rw-r--r-- | src/core/ao_flight.h | 6 | ||||
-rw-r--r-- | src/core/ao_gps_report_mega.c | 1 | ||||
-rw-r--r-- | src/core/ao_gps_report_metrum.c | 3 | ||||
-rw-r--r-- | src/core/ao_ignite.c | 4 | ||||
-rw-r--r-- | src/core/ao_kalman.c | 2 | ||||
-rw-r--r-- | src/core/ao_log.c | 2 | ||||
-rw-r--r-- | src/core/ao_log_metrum.c | 1 | ||||
-rw-r--r-- | src/core/ao_log_mini.c | 4 | ||||
-rw-r--r-- | src/core/ao_notask.c | 1 | ||||
-rw-r--r-- | src/core/ao_pyro.c | 2 | ||||
-rw-r--r-- | src/core/ao_radio_cmac.c | 1 | ||||
-rw-r--r-- | src/core/ao_sample.c | 19 | ||||
-rw-r--r-- | src/core/ao_telemetry.c | 4 |
19 files changed, 121 insertions, 31 deletions
diff --git a/src/core/ao.h b/src/core/ao.h index 0b634a79..29ad2603 100644 --- a/src/core/ao.h +++ b/src/core/ao.h @@ -307,6 +307,17 @@ ao_altitude_to_pa(alt_t alt); #include <ao_serial.h> #endif +/* + * ao_convert_volt.c + * + * Convert ADC readings to decivolts + */ + +int16_t +ao_battery_decivolt(int16_t adc); + +int16_t +ao_ignite_decivolt(int16_t adc); /* * ao_spi_slave.c diff --git a/src/core/ao_config.c b/src/core/ao_config.c index a30ec64a..4482f673 100644 --- a/src/core/ao_config.c +++ b/src/core/ao_config.c @@ -353,9 +353,9 @@ ao_config_accel_calibrate_set(void) __reentrant { int16_t up, down; #if HAS_GYRO - int16_t accel_along_up, accel_along_down; - int16_t accel_across_up, accel_across_down; - int16_t accel_through_up, accel_through_down; + int16_t accel_along_up = 0, accel_along_down = 0; + int16_t accel_across_up = 0, accel_across_down = 0; + int16_t accel_through_up = 0, accel_through_down = 0; #endif ao_cmd_decimal(); @@ -390,9 +390,11 @@ ao_config_accel_calibrate_set(void) __reentrant ao_config.accel_plus_g = up; ao_config.accel_minus_g = down; #if HAS_GYRO - ao_config.accel_zero_along = (accel_along_up + accel_along_down) / 2; - ao_config.accel_zero_across = (accel_across_up + accel_across_down) / 2; - ao_config.accel_zero_through = (accel_through_up + accel_through_down) / 2; + if (ao_cmd_lex_i == 0) { + ao_config.accel_zero_along = (accel_along_up + accel_along_down) / 2; + ao_config.accel_zero_across = (accel_across_up + accel_across_down) / 2; + ao_config.accel_zero_through = (accel_through_up + accel_through_down) / 2; + } #endif _ao_config_edit_finish(); } @@ -512,6 +514,10 @@ ao_config_pad_orientation_show(void) __reentrant printf("Pad orientation: %d\n", ao_config.pad_orientation); } +#ifndef AO_ACCEL_INVERT +#define AO_ACCEL_INVERT 0x7fff +#endif + void ao_config_pad_orientation_set(void) __reentrant { @@ -521,10 +527,10 @@ ao_config_pad_orientation_set(void) __reentrant _ao_config_edit_start(); ao_cmd_lex_i &= 1; if (ao_config.pad_orientation != ao_cmd_lex_i) { - uint16_t t; + int16_t t; t = ao_config.accel_plus_g; - ao_config.accel_plus_g = 0x7fff - ao_config.accel_minus_g; - ao_config.accel_minus_g = 0x7fff - t; + ao_config.accel_plus_g = AO_ACCEL_INVERT - ao_config.accel_minus_g; + ao_config.accel_minus_g = AO_ACCEL_INVERT - t; } ao_config.pad_orientation = ao_cmd_lex_i; _ao_config_edit_finish(); @@ -656,8 +662,10 @@ ao_config_help(void) __reentrant; static void ao_config_show(void) __reentrant; +#if HAS_EEPROM static void ao_config_save(void) __reentrant; +#endif __code struct ao_config_var ao_config_vars[] = { #if HAS_FLIGHT diff --git a/src/core/ao_convert_volt.c b/src/core/ao_convert_volt.c new file mode 100644 index 00000000..8556d423 --- /dev/null +++ b/src/core/ao_convert_volt.c @@ -0,0 +1,33 @@ +/* + * Copyright © 2014 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" + +#define scale(v,p,m) ((int32_t) (v) * (AO_ADC_REFERENCE_DV * ((p) + (m))) / (AO_ADC_MAX * (m))) + +int16_t +ao_battery_decivolt(int16_t adc) +{ + return scale(adc, AO_BATTERY_DIV_PLUS, AO_BATTERY_DIV_MINUS); +} + +int16_t +ao_ignite_decivolt(int16_t adc) +{ + return scale(adc, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS); +} + diff --git a/src/core/ao_data.h b/src/core/ao_data.h index e1d8a139..c4b062fd 100644 --- a/src/core/ao_data.h +++ b/src/core/ao_data.h @@ -273,14 +273,16 @@ typedef int16_t accel_t; /* MMA655X is hooked up so that positive values represent negative acceleration */ +#define AO_ACCEL_INVERT 4095 + #define ao_data_accel(packet) ((packet)->mma655x) #if AO_MMA655X_INVERT -#define ao_data_accel_cook(packet) (4095 - (packet)->mma655x) +#define ao_data_accel_cook(packet) (AO_ACCEL_INVERT - (packet)->mma655x) #else #define ao_data_accel_cook(packet) ((packet)->mma655x) #endif #define ao_data_set_accel(packet, accel) ((packet)->mma655x = (accel)) -#define ao_data_accel_invert(accel) (4095 - (accel)) +#define ao_data_accel_invert(accel) (AO_ACCEL_INVERT - (accel)) #endif @@ -288,6 +290,8 @@ typedef int16_t accel_t; #define HAS_ACCEL 1 +#define AO_ACCEL_INVERT 0 + typedef int16_t accel_t; /* MPU6000 is hooked up so that positive y is positive acceleration */ diff --git a/src/core/ao_fec.h b/src/core/ao_fec.h index eedea8f4..618756c1 100644 --- a/src/core/ao_fec.h +++ b/src/core/ao_fec.h @@ -31,7 +31,7 @@ void ao_fec_dump_bytes(const uint8_t *bytes, uint16_t len, const char *name); #endif -static uint16_t inline +static inline uint16_t ao_fec_crc_byte(uint8_t byte, uint16_t crc) { uint8_t bit; diff --git a/src/core/ao_flight.c b/src/core/ao_flight.c index 463ff4a2..702c3403 100644 --- a/src/core/ao_flight.c +++ b/src/core/ao_flight.c @@ -46,7 +46,7 @@ __pdata enum ao_flight_state ao_flight_state; /* current flight state */ __pdata uint16_t ao_boost_tick; /* time of launch detect */ __pdata uint16_t ao_motor_number; /* number of motors burned so far */ -#if HAS_IMU +#if HAS_SENSOR_ERRORS /* Any sensor can set this to mark the flight computer as 'broken' */ __xdata uint8_t ao_sensor_errors; #endif @@ -104,9 +104,6 @@ ao_flight(void) ao_config.accel_minus_g == 0 || ao_ground_accel < ao_config.accel_plus_g - ACCEL_NOSE_UP || ao_ground_accel > ao_config.accel_minus_g + ACCEL_NOSE_UP || -#if HAS_IMU - ao_sensor_errors || -#endif ao_ground_height < -1000 || ao_ground_height > 7000) { @@ -152,7 +149,11 @@ ao_flight(void) #endif } else { /* Set idle mode */ - ao_flight_state = ao_flight_idle; + ao_flight_state = ao_flight_idle; +#if HAS_SENSOR_ERRORS + if (ao_sensor_errors) + ao_flight_state = ao_flight_invalid; +#endif #if HAS_ACCEL && HAS_RADIO && PACKET_HAS_SLAVE /* Turn on packet system in idle mode on TeleMetrum */ @@ -400,7 +401,7 @@ ao_flight_dump(void) #if HAS_ACCEL int16_t accel; - accel = ((ao_ground_accel - ao_sample_accel) * ao_accel_scale) >> 16; + accel = ((ao_config.accel_plus_g - ao_sample_accel) * ao_accel_scale) >> 16; #endif printf ("sample:\n"); @@ -442,9 +443,18 @@ ao_gyro_test(void) ao_flight_state = ao_flight_idle; } +uint8_t ao_orient_test; + +static void +ao_orient_test_select(void) +{ + ao_orient_test = !ao_orient_test; +} + __code struct ao_cmds ao_flight_cmds[] = { { ao_flight_dump, "F\0Dump flight status" }, { ao_gyro_test, "G\0Test gyro code" }, + { ao_orient_test_select,"O\0Test orientation code" }, { 0, NULL }, }; #endif diff --git a/src/core/ao_flight.h b/src/core/ao_flight.h index c7c02ccf..01d21c11 100644 --- a/src/core/ao_flight.h +++ b/src/core/ao_flight.h @@ -41,7 +41,11 @@ extern __pdata enum ao_flight_state ao_flight_state; extern __pdata uint16_t ao_boost_tick; extern __pdata uint16_t ao_motor_number; -#if HAS_IMU +#if HAS_IMU || HAS_MMA655X +#define HAS_SENSOR_ERRORS 1 +#endif + +#if HAS_SENSOR_ERRORS extern __xdata uint8_t ao_sensor_errors; #endif diff --git a/src/core/ao_gps_report_mega.c b/src/core/ao_gps_report_mega.c index d13885dd..07a2bc5b 100644 --- a/src/core/ao_gps_report_mega.c +++ b/src/core/ao_gps_report_mega.c @@ -24,7 +24,6 @@ ao_gps_report_mega(void) static __xdata struct ao_log_mega gps_log; static __xdata struct ao_telemetry_location gps_data; static __xdata struct ao_telemetry_satellite gps_tracking_data; - uint8_t date_reported = 0; uint8_t new; uint8_t c, n, i; diff --git a/src/core/ao_gps_report_metrum.c b/src/core/ao_gps_report_metrum.c index fa038976..696a833b 100644 --- a/src/core/ao_gps_report_metrum.c +++ b/src/core/ao_gps_report_metrum.c @@ -24,9 +24,8 @@ ao_gps_report_metrum(void) static __xdata struct ao_log_metrum gps_log; static __xdata struct ao_telemetry_location gps_data; static __xdata struct ao_telemetry_satellite gps_tracking_data; - uint8_t c, n, i, p, valid, packets; + uint8_t c, n, i; uint8_t svid; - uint8_t date_reported = 0; uint8_t new; for (;;) { diff --git a/src/core/ao_ignite.c b/src/core/ao_ignite.c index 9f2ec0a7..823d003c 100644 --- a/src/core/ao_ignite.c +++ b/src/core/ao_ignite.c @@ -114,6 +114,8 @@ ao_igniter_fire(enum ao_igniter igniter) ao_delay(AO_IGNITER_FIRE_TIME); AO_IGNITER_SET_MAIN(0); break; + default: + break; } break; case AO_IGNITE_MODE_MAIN: @@ -127,6 +129,8 @@ ao_igniter_fire(enum ao_igniter igniter) ao_delay(AO_IGNITER_FIRE_TIME); AO_IGNITER_SET_MAIN(0); break; + default: + break; } break; } diff --git a/src/core/ao_kalman.c b/src/core/ao_kalman.c index 7fd4f889..9aea1f14 100644 --- a/src/core/ao_kalman.c +++ b/src/core/ao_kalman.c @@ -166,7 +166,7 @@ ao_kalman_err_accel(void) { int32_t accel; - accel = (ao_ground_accel - ao_sample_accel) * ao_accel_scale; + accel = (ao_config.accel_plus_g - 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; diff --git a/src/core/ao_log.c b/src/core/ao_log.c index 701c81ab..20febefe 100644 --- a/src/core/ao_log.c +++ b/src/core/ao_log.c @@ -196,7 +196,9 @@ ao_log_full(void) return ao_log_current_pos == ao_log_end_pos; } +#if HAS_ADC static __xdata struct ao_task ao_log_task; +#endif void ao_log_list(void) __reentrant diff --git a/src/core/ao_log_metrum.c b/src/core/ao_log_metrum.c index 43441e7a..91624d98 100644 --- a/src/core/ao_log_metrum.c +++ b/src/core/ao_log_metrum.c @@ -81,7 +81,6 @@ void ao_log(void) { __pdata uint16_t next_sensor, next_other; - uint8_t i; ao_storage_setup(); diff --git a/src/core/ao_log_mini.c b/src/core/ao_log_mini.c index 99a85982..29e3bd9f 100644 --- a/src/core/ao_log_mini.c +++ b/src/core/ao_log_mini.c @@ -78,7 +78,7 @@ typedef uint8_t check_log_size[1-(256 % sizeof(struct ao_log_mini))] ; void ao_log(void) { - __pdata uint16_t next_sensor, next_other; + __pdata uint16_t next_sensor; ao_storage_setup(); @@ -99,7 +99,7 @@ ao_log(void) * when starting up. */ ao_log_data_pos = ao_data_ring_next(ao_data_head); - next_other = next_sensor = ao_data_ring[ao_log_data_pos].tick; + next_sensor = ao_data_ring[ao_log_data_pos].tick; ao_log_state = ao_flight_startup; for (;;) { /* Write samples to EEPROM */ diff --git a/src/core/ao_notask.c b/src/core/ao_notask.c index a41712d2..6f967e6d 100644 --- a/src/core/ao_notask.c +++ b/src/core/ao_notask.c @@ -41,5 +41,6 @@ ao_sleep(__xdata void *wchan) void ao_wakeup(__xdata void *wchan) { + (void) wchan; ao_wchan = 0; } diff --git a/src/core/ao_pyro.c b/src/core/ao_pyro.c index a260aa99..e59f5bc4 100644 --- a/src/core/ao_pyro.c +++ b/src/core/ao_pyro.c @@ -436,7 +436,7 @@ ao_pyro_set(void) if (ao_cmd_status != ao_cmd_success) return; p = ao_cmd_lex_i; - if (p < 0 || AO_PYRO_NUM <= p) { + if (AO_PYRO_NUM <= p) { printf ("invalid pyro channel %d\n", p); return; } diff --git a/src/core/ao_radio_cmac.c b/src/core/ao_radio_cmac.c index 3ca3c313..bff848f6 100644 --- a/src/core/ao_radio_cmac.c +++ b/src/core/ao_radio_cmac.c @@ -21,7 +21,6 @@ static __xdata uint8_t ao_radio_cmac_mutex; __pdata int8_t ao_radio_cmac_rssi; static __xdata uint8_t cmac_data[AO_CMAC_MAX_LEN + AO_CMAC_KEY_LEN + 2 + AO_CMAC_KEY_LEN]; -static __pdata uint8_t ao_radio_cmac_len; static uint8_t round_len(uint8_t len) diff --git a/src/core/ao_sample.c b/src/core/ao_sample.c index adf8399d..34658951 100644 --- a/src/core/ao_sample.c +++ b/src/core/ao_sample.c @@ -92,6 +92,10 @@ __pdata int32_t ao_sample_roll_sum; static struct ao_quaternion ao_rotation; #endif +#if HAS_FLIGHT_DEBUG +extern uint8_t ao_orient_test; +#endif + static void ao_sample_preflight_add(void) { @@ -159,7 +163,11 @@ ao_sample_preflight_set(void) * that as the current rotation vector */ ao_quaternion_vectors_to_rotation(&ao_rotation, &up, &orient); +#if HAS_FLIGHT_DEBUG + if (ao_orient_test) + printf("\n\treset\n"); #endif +#endif nsamples = 0; } @@ -210,6 +218,17 @@ ao_sample_rotate(void) rotz = ao_rotation.z * ao_rotation.z - ao_rotation.y * ao_rotation.y - ao_rotation.x * ao_rotation.x + ao_rotation.r * ao_rotation.r; ao_sample_orient = acosf(rotz) * (float) (180.0/M_PI); + +#if HAS_FLIGHT_DEBUG + if (ao_orient_test) { + printf ("rot %d %d %d orient %d \r", + (int) (x * 1000), + (int) (y * 1000), + (int) (z * 1000), + ao_sample_orient); + } +#endif + } #endif diff --git a/src/core/ao_telemetry.c b/src/core/ao_telemetry.c index c118d007..5a00d825 100644 --- a/src/core/ao_telemetry.c +++ b/src/core/ao_telemetry.c @@ -24,9 +24,9 @@ #endif static __pdata uint16_t ao_telemetry_interval; -static __pdata uint8_t ao_rdf = 0; #if HAS_RDF +static __pdata uint8_t ao_rdf = 0; static __pdata uint16_t ao_rdf_time; #endif @@ -211,7 +211,6 @@ ao_send_metrum_data(void) { if (--ao_telemetry_metrum_data_cur <= 0) { __xdata struct ao_data *packet = (__xdata struct ao_data *) &ao_data_ring[ao_data_ring_prev(ao_sample_data)]; - uint8_t i; telemetry.generic.tick = packet->tick; telemetry.generic.type = AO_TELEMETRY_METRUM_DATA; @@ -473,7 +472,6 @@ ao_telemetry(void) } else time = ao_time(); - bottom: ; } } } |