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