From 24167015705ae831692b95735968b04a876f935e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 4 Apr 2014 23:34:48 -0700 Subject: altos: Rename 'core' to 'kernel' core remains a bad name to use -- dirvish skips files (and directories, it seems) with that name. Signed-off-by: Keith Packard --- src/product/Makefile.teledongle | 4 ++-- src/product/Makefile.telelaunch | 4 ++-- src/product/Makefile.telemetrum | 4 ++-- src/product/Makefile.telemini | 4 ++-- src/product/Makefile.telenano | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/product') diff --git a/src/product/Makefile.teledongle b/src/product/Makefile.teledongle index da9bcba0..81151364 100644 --- a/src/product/Makefile.teledongle +++ b/src/product/Makefile.teledongle @@ -7,8 +7,8 @@ # TD_VER, TD_DEF and include # this file -vpath %.c ..:../core:../cc1111:../drivers:../product -vpath %.h ..:../core:../cc1111:../drivers:../product +vpath %.c ..:../kernel:../cc1111:../drivers:../product +vpath %.h ..:../kernel:../cc1111:../drivers:../product vpath ao-make-product.5c ../util ifndef VERSION diff --git a/src/product/Makefile.telelaunch b/src/product/Makefile.telelaunch index a5e2eb7f..90fe7833 100644 --- a/src/product/Makefile.telelaunch +++ b/src/product/Makefile.telelaunch @@ -4,8 +4,8 @@ # define TELELAUNCH_VER, TELELAUNCH_DEF # this file -vpath %.c ..:../core:../cc1111:../drivers:../product -vpath %.h ..:../core:../cc1111:../drivers:../product +vpath %.c ..:../kernel:../cc1111:../drivers:../product +vpath %.h ..:../kernel:../cc1111:../drivers:../product vpath ao-make-product.5c ../util ifndef VERSION diff --git a/src/product/Makefile.telemetrum b/src/product/Makefile.telemetrum index c740a483..dbbf57d8 100644 --- a/src/product/Makefile.telemetrum +++ b/src/product/Makefile.telemetrum @@ -7,8 +7,8 @@ # TM_VER, TM_DEF, TM_INC and TM_SRC and include # this file -vpath %.c .:..:../core:../cc1111:../drivers:../product -vpath %.h .:..:../core:../cc1111:../drivers:../product +vpath %.c .:..:../kernel:../cc1111:../drivers:../product +vpath %.h .:..:../kernel:../cc1111:../drivers:../product vpath ao-make-product.5c ../util ifndef VERSION diff --git a/src/product/Makefile.telemini b/src/product/Makefile.telemini index 0884079e..ff8b9d56 100644 --- a/src/product/Makefile.telemini +++ b/src/product/Makefile.telemini @@ -4,8 +4,8 @@ # Define TELEMINI_VER and TELEMINI_DEF and then # include this file -vpath %.c ..:../core:../cc1111:../drivers:../product -vpath %.h ..:../core:../cc1111:../drivers:../product +vpath %.c ..:../kernel:../cc1111:../drivers:../product +vpath %.h ..:../kernel:../cc1111:../drivers:../product vpath ao-make-product.5c ../util ifndef VERSION diff --git a/src/product/Makefile.telenano b/src/product/Makefile.telenano index c31989ee..d2fcb6d8 100644 --- a/src/product/Makefile.telenano +++ b/src/product/Makefile.telenano @@ -4,8 +4,8 @@ # Define TELENANO_VER and TELENANO_DEF and then # include this file -vpath %.c ..:../core:../cc1111:../drivers:../product -vpath %.h ..:../core:../cc1111:../drivers:../product +vpath %.c ..:../kernel:../cc1111:../drivers:../product +vpath %.h ..:../kernel:../cc1111:../drivers:../product vpath ao-make-product.5c ../util ifndef VERSION -- cgit v1.2.3 From 7b275ddfe20f54857d7d1abb98607c406b678090 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 11 Apr 2014 16:31:32 -0700 Subject: altos: Add 'microwater' product This is a custom firmware spin for micropeak designed for use with water rockets that sets the boost detect altitude to 10m instead of 30m. Signed-off-by: Keith Packard --- src/microwater/.gitignore | 2 + src/microwater/Makefile | 121 +++++++++++++++++++++++++++++++++++++++++++++ src/microwater/ao_pins.h | 70 ++++++++++++++++++++++++++ src/product/ao_micropeak.h | 2 + 4 files changed, 195 insertions(+) create mode 100644 src/microwater/.gitignore create mode 100644 src/microwater/Makefile create mode 100644 src/microwater/ao_pins.h (limited to 'src/product') diff --git a/src/microwater/.gitignore b/src/microwater/.gitignore new file mode 100644 index 00000000..0573d989 --- /dev/null +++ b/src/microwater/.gitignore @@ -0,0 +1,2 @@ +ao_product.h +microwater-* diff --git a/src/microwater/Makefile b/src/microwater/Makefile new file mode 100644 index 00000000..a49cda4b --- /dev/null +++ b/src/microwater/Makefile @@ -0,0 +1,121 @@ +# +# Tiny AltOS build +# +# +vpath % ../attiny:../drivers:../kernel:../product:.. +vpath ao-make-product.5c ../util +vpath make-altitude-pa ../util + +include ../avr/Makefile.defs + +PUBLISH_DIR=$(HOME)/altusmetrumllc/Binaries +PUBLISH_FILE=$(PUBLISH_DIR)/$(PROG)-$(VERSION).hex + +MCU=attiny85 +DUDECPUTYPE=t85 +#PROGRAMMER=stk500v2 -P usb +LOADSLOW=-i 32 -B 32 +LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w: + +#LDFLAGS=-L$(LDSCRIPTS) -Tavr25.x + +ALTOS_SRC = \ + ao_micropeak.c \ + ao_spi_attiny.c \ + ao_led.c \ + ao_clock.c \ + ao_ms5607.c \ + ao_exti.c \ + ao_convert_pa.c \ + ao_report_micro.c \ + ao_notask.c \ + ao_eeprom_tiny.c \ + ao_panic.c \ + ao_log_micro.c \ + ao_async.c \ + ao_microflight.c \ + ao_microkalman.c + +INC=\ + ao.h \ + ao_pins.h \ + ao_arch.h \ + ao_arch_funcs.h \ + ao_exti.h \ + ao_ms5607.h \ + ao_log_micro.h \ + ao_micropeak.h \ + altitude-pa.h + +IDPRODUCT=0 +PRODUCT=MicroWater-v0.1 +PRODUCT_DEF=-DMICROPEAK +CFLAGS = $(PRODUCT_DEF) -I. -I../attiny -I../kernel -I.. -I../drivers -I../product +CFLAGS += -g -mmcu=$(MCU) -Wall -Wstrict-prototypes -O2 -mcall-prologues -DATTINY + +NICKLE=nickle + +PROG=microwater-v0.1 + +SRC=$(ALTOS_SRC) +OBJ=$(SRC:.c=.o) + +V=0 +# The user has explicitly enabled quiet compilation. +ifeq ($(V),0) +quiet = @printf " $1 $2 $@\n"; $($1) +endif +# Otherwise, print the full command line. +quiet ?= $($1) + +all: $(PROG) $(PROG).hex + +CHECK=sh ../util/check-avr-mem + +$(PROG): Makefile $(OBJ) + $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) + $(call quiet,CHECK) $(PROG) || ($(RM) -f $(PROG); exit 1) + +$(PROG).hex: $(PROG) + avr-size $(PROG) + $(OBJCOPY) -R .eeprom -O ihex $(PROG) $@ + + +load: $(PROG).hex + $(LOADCMD) $(LOADARG)$(PROG).hex + +load-slow: $(PROG).hex + $(LOADCMD) $(LOADSLOW) $(LOADARG)$(PROG).hex + +ao_product.h: ao-make-product.5c ../Version + $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@ + +ao_product.o: ao_product.c ao_product.h + +%.o : %.c $(INC) + $(call quiet,CC) -c $(CFLAGS) $< + +distclean: clean + +clean: + rm -f *.o $(PROG) $(PROG).hex + rm -f ao_product.h + + +publish: $(PROG).hex + cp -a $(PROG).hex $(PUBLISH_FILE) + +load-product: + $(LOADCMD) $(LOADARG)$(PUBLISH_FILE) + +load-product-slow: + $(LOADCMD) $(LOADSLOW) $(LOADARG)$(PUBLISH_FILE) + +../altitude-pa.h: make-altitude-pa + nickle $< > $@ + +install: + +uninstall: + +$(OBJ): ao_product.h $(INC) diff --git a/src/microwater/ao_pins.h b/src/microwater/ao_pins.h new file mode 100644 index 00000000..37885ec2 --- /dev/null +++ b/src/microwater/ao_pins.h @@ -0,0 +1,70 @@ +/* + * 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_PINS_H_ +#define _AO_PINS_H_ +#include + +#define AO_LED_ORANGE (1<<4) +#define AO_LED_SERIAL 4 +#define AO_LED_PANIC AO_LED_ORANGE +#define AO_LED_REPORT AO_LED_ORANGE +#define LEDS_AVAILABLE (AO_LED_ORANGE) +#define USE_SERIAL_1_STDIN 0 +#define HAS_USB 0 +#define PACKET_HAS_SLAVE 0 +#define HAS_SERIAL_1 0 +#define HAS_TASK 0 +#define HAS_MS5607 1 +#define HAS_MS5611 0 +#define HAS_EEPROM 0 +#define HAS_BEEP 0 +#define AVR_CLOCK 250000UL + +/* SPI */ +#define SPI_PORT PORTB +#define SPI_PIN PINB +#define SPI_DIR DDRB +#define AO_MS5607_CS_PORT PORTB +#define AO_MS5607_CS_PIN 3 + +/* MS5607 */ +#define AO_MS5607_SPI_INDEX 0 +#define AO_MS5607_MISO_PORT PORTB +#define AO_MS5607_MISO_PIN 0 +#define AO_MS5607_BARO_OVERSAMPLE 4096 +#define AO_MS5607_TEMP_OVERSAMPLE 1024 + +/* I2C */ +#define I2C_PORT PORTB +#define I2C_PIN PINB +#define I2C_DIR DDRB +#define I2C_PIN_SCL PINB2 +#define I2C_PIN_SDA PINB0 + +#define AO_CONST_ATTRIB PROGMEM +typedef int32_t alt_t; +#define FETCH_ALT(o) ((alt_t) pgm_read_dword(&altitude_table[o])) + +#define AO_ALT_VALUE(x) ((x) * (alt_t) 10) + +/* Pressure change (in Pa) to detect boost */ +#ifndef BOOST_DETECT +#define BOOST_DETECT 120 /* 10m at sea level, 12m at 2000m */ +#endif + +#endif /* _AO_PINS_H_ */ diff --git a/src/product/ao_micropeak.h b/src/product/ao_micropeak.h index 0cefca6f..0ec407d7 100644 --- a/src/product/ao_micropeak.h +++ b/src/product/ao_micropeak.h @@ -25,7 +25,9 @@ #define GROUND_AVG (1 << GROUND_AVG_SHIFT) /* Pressure change (in Pa) to detect boost */ +#ifndef BOOST_DETECT #define BOOST_DETECT 360 /* 30m at sea level, 36m at 2000m */ +#endif /* Wait after power on before doing anything to give the user time to assemble the rocket */ #define BOOST_DELAY AO_SEC_TO_TICKS(60) -- cgit v1.2.3 From 8a114bac1145359f3953ce70f049a6be71df5300 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 12 May 2014 23:18:41 -0700 Subject: altos/flash-loader: Check memory addresses against flash space This validates memory read/write requests to make sure they are within the available flash memory space. This also reports the flash base and bounds addresses in the 'version' command so that the loader can validate the image before attempting to write it. Signed-off-by: Keith Packard --- src/product/ao_flash_task.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src/product') diff --git a/src/product/ao_flash_task.c b/src/product/ao_flash_task.c index 6cb308e1..9a12add6 100644 --- a/src/product/ao_flash_task.c +++ b/src/product/ao_flash_task.c @@ -79,6 +79,14 @@ ao_block_erase(void) ao_flash_erase_page(p); } +static int +ao_block_valid_address(uint32_t addr) +{ + if ((uint32_t) AO_BOOT_APPLICATION_BASE <= addr && addr <= (uint32_t) AO_BOOT_APPLICATION_BOUND - 256) + return 1; + return 0; +} + static void ao_block_write(void) { @@ -87,12 +95,10 @@ ao_block_write(void) uint8_t data[256]; uint16_t i; - if (addr < (uint32_t) AO_BOOT_APPLICATION_BASE) { - ao_put_string("Invalid address\n"); - return; - } for (i = 0; i < 256; i++) data[i] = ao_usb_getchar(); + if (!ao_block_valid_address(addr)) + return; ao_flash_page(p, (void *) data); } @@ -104,18 +110,43 @@ ao_block_read(void) uint16_t i; uint8_t c; + if (!ao_block_valid_address(addr)) { + for (i = 0; i < 256; i++) + ao_usb_putchar(0xff); + return; + } for (i = 0; i < 256; i++) { c = *p++; ao_usb_putchar(c); } } +static inline void +hexchar(uint8_t c) +{ + if (c > 10) + c += 'a' - ('9' + 1); + ao_usb_putchar(c + '0'); +} + +static void +ao_put_hex(uint32_t u) +{ + int8_t i; + for (i = 28; i >= 0; i -= 4) + hexchar((u >> i) & 0xf); +} + static void ao_show_version(void) { ao_put_string("altos-loader"); ao_put_string("\nmanufacturer "); ao_put_string(ao_manufacturer); ao_put_string("\nproduct "); ao_put_string(ao_product); + ao_put_string("\nflash-range "); + ao_put_hex((uint32_t) AO_BOOT_APPLICATION_BASE); + ao_usb_putchar(' '); + ao_put_hex((uint32_t) AO_BOOT_APPLICATION_BOUND); ao_put_string("\nsoftware-version "); ao_put_string(ao_version); ao_put_string("\n"); } -- cgit v1.2.3 From 3e28d8a242955d65d8cd50dbba4cad4609e2e1ae Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Jun 2014 17:12:06 -0700 Subject: altos: Add tracker task for TeleGPS This replaces the flight code to monitor GPS state and switch flight states between startup/pad/drogue Signed-off-by: Keith Packard --- src/product/ao_tracker.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 src/product/ao_tracker.c (limited to 'src/product') diff --git a/src/product/ao_tracker.c b/src/product/ao_tracker.c new file mode 100644 index 00000000..a710d49d --- /dev/null +++ b/src/product/ao_tracker.c @@ -0,0 +1,154 @@ +/* + * Copyright © 2014 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. + */ + +#include +#include +#include +#include + +enum ao_flight_state ao_flight_state; + +/* Speeds for the various modes */ +#define AO_TRACKER_NOT_MOVING 100 + +static uint8_t ao_tracker_force_telem; + +#if HAS_USB_CONNECT +static inline uint8_t +ao_usb_connected(void) +{ + return ao_gpio_get(AO_USB_CONNECT_PORT, AO_USB_CONNECT_PIN, AO_USB_CONNECT) != 0; +} +#else +#define ao_usb_connected() 1 +#endif + +static void +ao_tracker(void) +{ + uint16_t telem_rate = AO_SEC_TO_TICKS(1), new_telem_rate; + uint8_t gps_rate = 1, new_gps_rate; + uint8_t telem_enabled = 1, new_telem_enabled; + int32_t start_latitude = 0, start_longitude = 0; + int16_t start_altitude = 0; + uint32_t ground_distance; + int16_t height; + uint16_t speed; + + ao_timer_set_adc_interval(100); + + ao_flight_state = ao_flight_startup; + for (;;) { + ao_sleep(&ao_gps_new); + + new_gps_rate = gps_rate; + new_telem_rate = telem_rate; + + new_telem_enabled = ao_tracker_force_telem || !ao_usb_connected(); + + ao_mutex_get(&ao_gps_mutex); + + /* Don't change anything if GPS isn't locked */ + if ((ao_gps_data.flags & (AO_GPS_VALID|AO_GPS_COURSE_VALID)) == + (AO_GPS_VALID|AO_GPS_COURSE_VALID)) + { + switch (ao_flight_state) { + case ao_flight_startup: + /* startup to pad when GPS locks */ + ao_flight_state = ao_flight_pad; + start_latitude = ao_gps_data.longitude; + start_longitude = ao_gps_data.latitude; + start_altitude = ao_gps_data.altitude; + break; + case ao_flight_pad: + ground_distance = ao_distance(ao_gps_data.latitude, + start_latitude, + ao_gps_data.longitude, + start_longitude); + height = ao_gps_data.altitude - start_altitude; + if (height < 0) + height = -height; + if (ground_distance >= ao_config.tracker_start_horiz || + height >= ao_config.tracker_start_vert) + { + ao_flight_state = ao_flight_drogue; + ao_log_start(); + } + break; + case ao_flight_drogue: + + /* Modulate data rates based on speed (in cm/s) */ + if (ao_gps_data.climb_rate < 0) + speed = -ao_gps_data.climb_rate; + else + speed = ao_gps_data.climb_rate; + speed += ao_gps_data.ground_speed; + + if (speed < AO_TRACKER_NOT_MOVING) { + new_telem_rate = AO_SEC_TO_TICKS(10); + new_gps_rate = 10; + } else { + new_telem_rate = AO_SEC_TO_TICKS(1); + new_gps_rate = 1; + } + break; + default: + break; + } + } + ao_mutex_put(&ao_gps_mutex); + + if (new_telem_rate != telem_rate || new_telem_enabled != telem_enabled) { + if (new_telem_enabled) + ao_telemetry_set_interval(new_telem_rate); + else + ao_telemetry_set_interval(0); + telem_rate = new_telem_rate; + telem_enabled = new_telem_enabled; + } + + if (new_gps_rate != gps_rate) { + ao_gps_set_rate(new_gps_rate); + gps_rate = new_gps_rate; + } + } +} + +static struct ao_task ao_tracker_task; + +static void +ao_tracker_set_telem(void) +{ + ao_cmd_hex(); + if (ao_cmd_status == ao_cmd_success) + ao_tracker_force_telem = ao_cmd_lex_i; +} + +static const struct ao_cmds ao_tracker_cmds[] = { + { ao_tracker_set_telem, "t \0Set telem on USB" }, + { 0, NULL }, +}; + +void +ao_tracker_init(void) +{ +#if HAS_USB_CONNECT + ao_enable_input(AO_USB_CONNECT_PORT, AO_USB_CONNECT_PIN, 0); +#endif + ao_cmd_register(&ao_tracker_cmds[0]); + ao_add_task(&ao_tracker_task, ao_tracker, "tracker"); +} -- cgit v1.2.3 From e063701310c1ab5b766c27f24088699aad142fbd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Jun 2014 18:33:33 -0700 Subject: altos: Change tracker not-moving speed to 2m/s and document Just adjust to avoid sensing motion from GPS noise Signed-off-by: Keith Packard --- src/product/ao_tracker.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/product') diff --git a/src/product/ao_tracker.c b/src/product/ao_tracker.c index a710d49d..5c2bb73f 100644 --- a/src/product/ao_tracker.c +++ b/src/product/ao_tracker.c @@ -22,8 +22,8 @@ enum ao_flight_state ao_flight_state; -/* Speeds for the various modes */ -#define AO_TRACKER_NOT_MOVING 100 +/* Speeds for the various modes, 2m/s seems reasonable for 'not moving' */ +#define AO_TRACKER_NOT_MOVING 200 static uint8_t ao_tracker_force_telem; -- cgit v1.2.3 From eebcf07950e909e4516b08c32e289a870f772793 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Jun 2014 18:35:45 -0700 Subject: altos: Have tracker average 5 GPS samples before moving to pad mode Avoids early GPS noise right after lock Signed-off-by: Keith Packard --- src/product/ao_tracker.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/product') diff --git a/src/product/ao_tracker.c b/src/product/ao_tracker.c index 5c2bb73f..80eade5c 100644 --- a/src/product/ao_tracker.c +++ b/src/product/ao_tracker.c @@ -36,6 +36,8 @@ ao_usb_connected(void) #else #define ao_usb_connected() 1 #endif + +#define STARTUP_AVERAGE 5 static void ao_tracker(void) @@ -48,6 +50,9 @@ ao_tracker(void) uint32_t ground_distance; int16_t height; uint16_t speed; + int64_t lat_sum = 0, lon_sum = 0; + int32_t alt_sum = 0; + int nsamples = 0; ao_timer_set_adc_interval(100); @@ -69,10 +74,18 @@ ao_tracker(void) switch (ao_flight_state) { case ao_flight_startup: /* startup to pad when GPS locks */ - ao_flight_state = ao_flight_pad; - start_latitude = ao_gps_data.longitude; - start_longitude = ao_gps_data.latitude; - start_altitude = ao_gps_data.altitude; + + lat_sum += ao_gps_data.latitude; + lon_sum += ao_gps_data.longitude; + alt_sum += ao_gps_data.altitude; + + if (++nsamples >= STARTUP_AVERAGE) { + ao_flight_state = ao_flight_pad; + ao_wakeup(&ao_flight_state); + start_latitude = lat_sum / nsamples; + start_longitude = lon_sum / nsamples; + start_altitude = alt_sum / nsamples; + } break; case ao_flight_pad: ground_distance = ao_distance(ao_gps_data.latitude, -- cgit v1.2.3 From b619199345256cdc456f8a0b99c0ad9335e877c7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Jun 2014 18:45:18 -0700 Subject: altos: Fix tracker start state Make sure log can start by scanning existing logs Enable RDF by default Turn off telemetry until we decide whether to turn it on in the loop Allow TeleGPS v0.3 to run without ADC Signed-off-by: Keith Packard --- src/product/ao_tracker.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/product') diff --git a/src/product/ao_tracker.c b/src/product/ao_tracker.c index 80eade5c..d4960d25 100644 --- a/src/product/ao_tracker.c +++ b/src/product/ao_tracker.c @@ -36,7 +36,7 @@ ao_usb_connected(void) #else #define ao_usb_connected() 1 #endif - + #define STARTUP_AVERAGE 5 static void @@ -54,7 +54,15 @@ ao_tracker(void) int32_t alt_sum = 0; int nsamples = 0; +#if HAS_ADC ao_timer_set_adc_interval(100); +#endif + + ao_log_scan(); + + ao_rdf_set(1); + + ao_telemetry_set_interval(0); ao_flight_state = ao_flight_startup; for (;;) { -- cgit v1.2.3 From 4a29df3f9f6c4969eb01598f6917ce78c9ce37a6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Jun 2014 18:47:27 -0700 Subject: altos: tracker distance computation flipped arguments around ao_distance takes (lat, lon, lat, lon) not (lat, lat, lon, lon) Signed-off-by: Keith Packard --- src/product/ao_tracker.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/product') diff --git a/src/product/ao_tracker.c b/src/product/ao_tracker.c index d4960d25..b4e563ee 100644 --- a/src/product/ao_tracker.c +++ b/src/product/ao_tracker.c @@ -97,12 +97,13 @@ ao_tracker(void) break; case ao_flight_pad: ground_distance = ao_distance(ao_gps_data.latitude, - start_latitude, ao_gps_data.longitude, + start_latitude, start_longitude); height = ao_gps_data.altitude - start_altitude; if (height < 0) height = -height; + if (ground_distance >= ao_config.tracker_start_horiz || height >= ao_config.tracker_start_vert) { -- cgit v1.2.3 From 6160ddadeae324b4a68db800c98c339156b63076 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Jun 2014 18:49:01 -0700 Subject: altos: Add debug to tracker to force launch This lets us test the move from pad to drogue state Signed-off-by: Keith Packard --- src/product/ao_tracker.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/product') diff --git a/src/product/ao_tracker.c b/src/product/ao_tracker.c index b4e563ee..c1c3366c 100644 --- a/src/product/ao_tracker.c +++ b/src/product/ao_tracker.c @@ -26,6 +26,7 @@ enum ao_flight_state ao_flight_state; #define AO_TRACKER_NOT_MOVING 200 static uint8_t ao_tracker_force_telem; +static uint8_t ao_tracker_force_launch; #if HAS_USB_CONNECT static inline uint8_t @@ -105,9 +106,11 @@ ao_tracker(void) height = -height; if (ground_distance >= ao_config.tracker_start_horiz || - height >= ao_config.tracker_start_vert) + height >= ao_config.tracker_start_vert || + ao_tracker_force_launch) { ao_flight_state = ao_flight_drogue; + ao_wakeup(&ao_flight_state); ao_log_start(); } break; @@ -156,8 +159,11 @@ static void ao_tracker_set_telem(void) { ao_cmd_hex(); - if (ao_cmd_status == ao_cmd_success) - ao_tracker_force_telem = ao_cmd_lex_i; + if (ao_cmd_status == ao_cmd_success) { + ao_tracker_force_telem = (ao_cmd_lex_i & 1) != 0; + ao_tracker_force_launch = (ao_cmd_lex_i & 2) != 0; + printf ("force telem %d force launch %d\n", ao_tracker_force_telem, ao_tracker_force_launch); + } } static const struct ao_cmds ao_tracker_cmds[] = { -- cgit v1.2.3 From d8f84ba82bab653c041eb85f93b9dcb1083bd849 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Jun 2014 18:55:26 -0700 Subject: altos: Add AO_LOG_FLIGHT packet to TeleGPS logs This encodes the flight number for tracking of data files. Signed-off-by: Keith Packard --- src/product/ao_tracker.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/product') diff --git a/src/product/ao_tracker.c b/src/product/ao_tracker.c index c1c3366c..9666528b 100644 --- a/src/product/ao_tracker.c +++ b/src/product/ao_tracker.c @@ -40,6 +40,31 @@ ao_usb_connected(void) #define STARTUP_AVERAGE 5 +static void +ao_tracker_start_flight(void) +{ + struct ao_log_mega log; + ao_log_start(); + log.type = AO_LOG_FLIGHT; + log.tick = ao_time(); +#if HAS_ACCEL + log.u.flight.ground_accel = ao_ground_accel; +#endif +#if HAS_GYRO + log.u.flight.ground_accel_along = ao_ground_accel_along; + log.u.flight.ground_accel_across = ao_ground_accel_across; + log.u.flight.ground_accel_through = ao_ground_accel_through; + log.u.flight.ground_roll = ao_ground_roll; + log.u.flight.ground_pitch = ao_ground_pitch; + log.u.flight.ground_yaw = ao_ground_yaw; +#endif +#if HAS_FLIGHT + log.u.flight.ground_pres = ao_ground_pres; +#endif + log.u.flight.flight = ao_flight_number; + ao_log_mega(&log); +} + static void ao_tracker(void) { @@ -112,10 +137,10 @@ ao_tracker(void) ao_flight_state = ao_flight_drogue; ao_wakeup(&ao_flight_state); ao_log_start(); + ao_tracker_start_flight(); } break; case ao_flight_drogue: - /* Modulate data rates based on speed (in cm/s) */ if (ao_gps_data.climb_rate < 0) speed = -ao_gps_data.climb_rate; -- cgit v1.2.3 From cab6d80f11e07dd26b865727eb7ce4fd45be5c7c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Jun 2014 21:37:38 -0700 Subject: altos: Force telemetry on by default for v0.3 TeleGPS boards These don't have a USB connect indicator, so just turn on telemetry by default Signed-off-by: Keith Packard --- src/product/ao_tracker.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/product') diff --git a/src/product/ao_tracker.c b/src/product/ao_tracker.c index 9666528b..b207c562 100644 --- a/src/product/ao_tracker.c +++ b/src/product/ao_tracker.c @@ -70,7 +70,7 @@ ao_tracker(void) { uint16_t telem_rate = AO_SEC_TO_TICKS(1), new_telem_rate; uint8_t gps_rate = 1, new_gps_rate; - uint8_t telem_enabled = 1, new_telem_enabled; + uint8_t telem_enabled = 0, new_telem_enabled; int32_t start_latitude = 0, start_longitude = 0; int16_t start_altitude = 0; uint32_t ground_distance; @@ -84,6 +84,10 @@ ao_tracker(void) ao_timer_set_adc_interval(100); #endif +#if !HAS_USB_CONNECT + ao_tracker_force_telem = 1; +#endif + ao_log_scan(); ao_rdf_set(1); @@ -187,8 +191,9 @@ ao_tracker_set_telem(void) if (ao_cmd_status == ao_cmd_success) { ao_tracker_force_telem = (ao_cmd_lex_i & 1) != 0; ao_tracker_force_launch = (ao_cmd_lex_i & 2) != 0; - printf ("force telem %d force launch %d\n", ao_tracker_force_telem, ao_tracker_force_launch); } + printf ("flight %d force telem %d force launch %d\n", + ao_flight_number, ao_tracker_force_telem, ao_tracker_force_launch); } static const struct ao_cmds ao_tracker_cmds[] = { -- cgit v1.2.3 From 1873d539a8f1a0e1e8ad539af5d49a77a129b928 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 7 Jun 2014 07:41:11 -0700 Subject: altos: Move ao_tracker.c to kernel Doesn't make sense to be in product Signed-off-by: Keith Packard --- src/kernel/ao_tracker.c | 212 +++++++++++++++++++++++++++++++++++++++++++++++ src/product/ao_tracker.c | 212 ----------------------------------------------- 2 files changed, 212 insertions(+), 212 deletions(-) create mode 100644 src/kernel/ao_tracker.c delete mode 100644 src/product/ao_tracker.c (limited to 'src/product') diff --git a/src/kernel/ao_tracker.c b/src/kernel/ao_tracker.c new file mode 100644 index 00000000..b207c562 --- /dev/null +++ b/src/kernel/ao_tracker.c @@ -0,0 +1,212 @@ +/* + * Copyright © 2014 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. + */ + +#include +#include +#include +#include + +enum ao_flight_state ao_flight_state; + +/* Speeds for the various modes, 2m/s seems reasonable for 'not moving' */ +#define AO_TRACKER_NOT_MOVING 200 + +static uint8_t ao_tracker_force_telem; +static uint8_t ao_tracker_force_launch; + +#if HAS_USB_CONNECT +static inline uint8_t +ao_usb_connected(void) +{ + return ao_gpio_get(AO_USB_CONNECT_PORT, AO_USB_CONNECT_PIN, AO_USB_CONNECT) != 0; +} +#else +#define ao_usb_connected() 1 +#endif + +#define STARTUP_AVERAGE 5 + +static void +ao_tracker_start_flight(void) +{ + struct ao_log_mega log; + ao_log_start(); + log.type = AO_LOG_FLIGHT; + log.tick = ao_time(); +#if HAS_ACCEL + log.u.flight.ground_accel = ao_ground_accel; +#endif +#if HAS_GYRO + log.u.flight.ground_accel_along = ao_ground_accel_along; + log.u.flight.ground_accel_across = ao_ground_accel_across; + log.u.flight.ground_accel_through = ao_ground_accel_through; + log.u.flight.ground_roll = ao_ground_roll; + log.u.flight.ground_pitch = ao_ground_pitch; + log.u.flight.ground_yaw = ao_ground_yaw; +#endif +#if HAS_FLIGHT + log.u.flight.ground_pres = ao_ground_pres; +#endif + log.u.flight.flight = ao_flight_number; + ao_log_mega(&log); +} + +static void +ao_tracker(void) +{ + uint16_t telem_rate = AO_SEC_TO_TICKS(1), new_telem_rate; + uint8_t gps_rate = 1, new_gps_rate; + uint8_t telem_enabled = 0, new_telem_enabled; + int32_t start_latitude = 0, start_longitude = 0; + int16_t start_altitude = 0; + uint32_t ground_distance; + int16_t height; + uint16_t speed; + int64_t lat_sum = 0, lon_sum = 0; + int32_t alt_sum = 0; + int nsamples = 0; + +#if HAS_ADC + ao_timer_set_adc_interval(100); +#endif + +#if !HAS_USB_CONNECT + ao_tracker_force_telem = 1; +#endif + + ao_log_scan(); + + ao_rdf_set(1); + + ao_telemetry_set_interval(0); + + ao_flight_state = ao_flight_startup; + for (;;) { + ao_sleep(&ao_gps_new); + + new_gps_rate = gps_rate; + new_telem_rate = telem_rate; + + new_telem_enabled = ao_tracker_force_telem || !ao_usb_connected(); + + ao_mutex_get(&ao_gps_mutex); + + /* Don't change anything if GPS isn't locked */ + if ((ao_gps_data.flags & (AO_GPS_VALID|AO_GPS_COURSE_VALID)) == + (AO_GPS_VALID|AO_GPS_COURSE_VALID)) + { + switch (ao_flight_state) { + case ao_flight_startup: + /* startup to pad when GPS locks */ + + lat_sum += ao_gps_data.latitude; + lon_sum += ao_gps_data.longitude; + alt_sum += ao_gps_data.altitude; + + if (++nsamples >= STARTUP_AVERAGE) { + ao_flight_state = ao_flight_pad; + ao_wakeup(&ao_flight_state); + start_latitude = lat_sum / nsamples; + start_longitude = lon_sum / nsamples; + start_altitude = alt_sum / nsamples; + } + break; + case ao_flight_pad: + ground_distance = ao_distance(ao_gps_data.latitude, + ao_gps_data.longitude, + start_latitude, + start_longitude); + height = ao_gps_data.altitude - start_altitude; + if (height < 0) + height = -height; + + if (ground_distance >= ao_config.tracker_start_horiz || + height >= ao_config.tracker_start_vert || + ao_tracker_force_launch) + { + ao_flight_state = ao_flight_drogue; + ao_wakeup(&ao_flight_state); + ao_log_start(); + ao_tracker_start_flight(); + } + break; + case ao_flight_drogue: + /* Modulate data rates based on speed (in cm/s) */ + if (ao_gps_data.climb_rate < 0) + speed = -ao_gps_data.climb_rate; + else + speed = ao_gps_data.climb_rate; + speed += ao_gps_data.ground_speed; + + if (speed < AO_TRACKER_NOT_MOVING) { + new_telem_rate = AO_SEC_TO_TICKS(10); + new_gps_rate = 10; + } else { + new_telem_rate = AO_SEC_TO_TICKS(1); + new_gps_rate = 1; + } + break; + default: + break; + } + } + ao_mutex_put(&ao_gps_mutex); + + if (new_telem_rate != telem_rate || new_telem_enabled != telem_enabled) { + if (new_telem_enabled) + ao_telemetry_set_interval(new_telem_rate); + else + ao_telemetry_set_interval(0); + telem_rate = new_telem_rate; + telem_enabled = new_telem_enabled; + } + + if (new_gps_rate != gps_rate) { + ao_gps_set_rate(new_gps_rate); + gps_rate = new_gps_rate; + } + } +} + +static struct ao_task ao_tracker_task; + +static void +ao_tracker_set_telem(void) +{ + ao_cmd_hex(); + if (ao_cmd_status == ao_cmd_success) { + ao_tracker_force_telem = (ao_cmd_lex_i & 1) != 0; + ao_tracker_force_launch = (ao_cmd_lex_i & 2) != 0; + } + printf ("flight %d force telem %d force launch %d\n", + ao_flight_number, ao_tracker_force_telem, ao_tracker_force_launch); +} + +static const struct ao_cmds ao_tracker_cmds[] = { + { ao_tracker_set_telem, "t \0Set telem on USB" }, + { 0, NULL }, +}; + +void +ao_tracker_init(void) +{ +#if HAS_USB_CONNECT + ao_enable_input(AO_USB_CONNECT_PORT, AO_USB_CONNECT_PIN, 0); +#endif + ao_cmd_register(&ao_tracker_cmds[0]); + ao_add_task(&ao_tracker_task, ao_tracker, "tracker"); +} diff --git a/src/product/ao_tracker.c b/src/product/ao_tracker.c deleted file mode 100644 index b207c562..00000000 --- a/src/product/ao_tracker.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright © 2014 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. - */ - -#include -#include -#include -#include - -enum ao_flight_state ao_flight_state; - -/* Speeds for the various modes, 2m/s seems reasonable for 'not moving' */ -#define AO_TRACKER_NOT_MOVING 200 - -static uint8_t ao_tracker_force_telem; -static uint8_t ao_tracker_force_launch; - -#if HAS_USB_CONNECT -static inline uint8_t -ao_usb_connected(void) -{ - return ao_gpio_get(AO_USB_CONNECT_PORT, AO_USB_CONNECT_PIN, AO_USB_CONNECT) != 0; -} -#else -#define ao_usb_connected() 1 -#endif - -#define STARTUP_AVERAGE 5 - -static void -ao_tracker_start_flight(void) -{ - struct ao_log_mega log; - ao_log_start(); - log.type = AO_LOG_FLIGHT; - log.tick = ao_time(); -#if HAS_ACCEL - log.u.flight.ground_accel = ao_ground_accel; -#endif -#if HAS_GYRO - log.u.flight.ground_accel_along = ao_ground_accel_along; - log.u.flight.ground_accel_across = ao_ground_accel_across; - log.u.flight.ground_accel_through = ao_ground_accel_through; - log.u.flight.ground_roll = ao_ground_roll; - log.u.flight.ground_pitch = ao_ground_pitch; - log.u.flight.ground_yaw = ao_ground_yaw; -#endif -#if HAS_FLIGHT - log.u.flight.ground_pres = ao_ground_pres; -#endif - log.u.flight.flight = ao_flight_number; - ao_log_mega(&log); -} - -static void -ao_tracker(void) -{ - uint16_t telem_rate = AO_SEC_TO_TICKS(1), new_telem_rate; - uint8_t gps_rate = 1, new_gps_rate; - uint8_t telem_enabled = 0, new_telem_enabled; - int32_t start_latitude = 0, start_longitude = 0; - int16_t start_altitude = 0; - uint32_t ground_distance; - int16_t height; - uint16_t speed; - int64_t lat_sum = 0, lon_sum = 0; - int32_t alt_sum = 0; - int nsamples = 0; - -#if HAS_ADC - ao_timer_set_adc_interval(100); -#endif - -#if !HAS_USB_CONNECT - ao_tracker_force_telem = 1; -#endif - - ao_log_scan(); - - ao_rdf_set(1); - - ao_telemetry_set_interval(0); - - ao_flight_state = ao_flight_startup; - for (;;) { - ao_sleep(&ao_gps_new); - - new_gps_rate = gps_rate; - new_telem_rate = telem_rate; - - new_telem_enabled = ao_tracker_force_telem || !ao_usb_connected(); - - ao_mutex_get(&ao_gps_mutex); - - /* Don't change anything if GPS isn't locked */ - if ((ao_gps_data.flags & (AO_GPS_VALID|AO_GPS_COURSE_VALID)) == - (AO_GPS_VALID|AO_GPS_COURSE_VALID)) - { - switch (ao_flight_state) { - case ao_flight_startup: - /* startup to pad when GPS locks */ - - lat_sum += ao_gps_data.latitude; - lon_sum += ao_gps_data.longitude; - alt_sum += ao_gps_data.altitude; - - if (++nsamples >= STARTUP_AVERAGE) { - ao_flight_state = ao_flight_pad; - ao_wakeup(&ao_flight_state); - start_latitude = lat_sum / nsamples; - start_longitude = lon_sum / nsamples; - start_altitude = alt_sum / nsamples; - } - break; - case ao_flight_pad: - ground_distance = ao_distance(ao_gps_data.latitude, - ao_gps_data.longitude, - start_latitude, - start_longitude); - height = ao_gps_data.altitude - start_altitude; - if (height < 0) - height = -height; - - if (ground_distance >= ao_config.tracker_start_horiz || - height >= ao_config.tracker_start_vert || - ao_tracker_force_launch) - { - ao_flight_state = ao_flight_drogue; - ao_wakeup(&ao_flight_state); - ao_log_start(); - ao_tracker_start_flight(); - } - break; - case ao_flight_drogue: - /* Modulate data rates based on speed (in cm/s) */ - if (ao_gps_data.climb_rate < 0) - speed = -ao_gps_data.climb_rate; - else - speed = ao_gps_data.climb_rate; - speed += ao_gps_data.ground_speed; - - if (speed < AO_TRACKER_NOT_MOVING) { - new_telem_rate = AO_SEC_TO_TICKS(10); - new_gps_rate = 10; - } else { - new_telem_rate = AO_SEC_TO_TICKS(1); - new_gps_rate = 1; - } - break; - default: - break; - } - } - ao_mutex_put(&ao_gps_mutex); - - if (new_telem_rate != telem_rate || new_telem_enabled != telem_enabled) { - if (new_telem_enabled) - ao_telemetry_set_interval(new_telem_rate); - else - ao_telemetry_set_interval(0); - telem_rate = new_telem_rate; - telem_enabled = new_telem_enabled; - } - - if (new_gps_rate != gps_rate) { - ao_gps_set_rate(new_gps_rate); - gps_rate = new_gps_rate; - } - } -} - -static struct ao_task ao_tracker_task; - -static void -ao_tracker_set_telem(void) -{ - ao_cmd_hex(); - if (ao_cmd_status == ao_cmd_success) { - ao_tracker_force_telem = (ao_cmd_lex_i & 1) != 0; - ao_tracker_force_launch = (ao_cmd_lex_i & 2) != 0; - } - printf ("flight %d force telem %d force launch %d\n", - ao_flight_number, ao_tracker_force_telem, ao_tracker_force_launch); -} - -static const struct ao_cmds ao_tracker_cmds[] = { - { ao_tracker_set_telem, "t \0Set telem on USB" }, - { 0, NULL }, -}; - -void -ao_tracker_init(void) -{ -#if HAS_USB_CONNECT - ao_enable_input(AO_USB_CONNECT_PORT, AO_USB_CONNECT_PIN, 0); -#endif - ao_cmd_register(&ao_tracker_cmds[0]); - ao_add_task(&ao_tracker_task, ao_tracker, "tracker"); -} -- cgit v1.2.3