summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-07-06 12:35:13 -0700
committerKeith Packard <keithp@keithp.com>2014-07-06 12:36:27 -0700
commitd1527a5457210eb914312cf8857bfb88982a8462 (patch)
treed11aefba40692dfb08e48bceffca8d74f0b412fb
parentf02cc3eec53e9d703837dad55ec2e6625b192588 (diff)
Add support for the "kite" micropeak variant
This uses a 100m 'launch detect' altitude and logs data every 19.2s instead of every .192s. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--micropeak/MicroData.java26
-rw-r--r--micropeak/MicroPeak.java4
-rw-r--r--src/Makefile2
-rw-r--r--src/kernel/ao_log_micro.c11
-rw-r--r--src/kernel/ao_microflight.c15
-rw-r--r--src/microkite/.gitignore2
-rw-r--r--src/microkite/Makefile134
-rw-r--r--src/microkite/ao_pins.h70
-rw-r--r--src/microkite/microkite-load.tmpl20
-rw-r--r--src/product/ao_micropeak.h11
10 files changed, 284 insertions, 11 deletions
diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java
index 6c9447aa..c38ada91 100644
--- a/micropeak/MicroData.java
+++ b/micropeak/MicroData.java
@@ -97,9 +97,15 @@ public class MicroData implements AltosUIDataSet {
private double time_step;
private double ground_altitude;
private ArrayList<Integer> bytes;
+ public int log_id;
String name;
MicroStats stats;
-
+
+ public static final int LOG_ID_MICROPEAK = 0;
+ public static final int LOG_ID_MICROKITE = 1;
+
+ public static final double CLOCK = 0.096;
+
public class FileEndedException extends Exception {
}
@@ -172,7 +178,7 @@ public class MicroData implements AltosUIDataSet {
if (get_nonwhite(f) == 'M' && get_nonwhite(f) == 'P')
return true;
}
- }
+ }
private int get_32(InputStream f) throws IOException, FileEndedException, NonHexcharException {
int v = 0;
@@ -345,6 +351,9 @@ public class MicroData implements AltosUIDataSet {
ground_pressure = get_32(f);
min_pressure = get_32(f);
int nsamples = get_16(f);
+
+ log_id = nsamples >> 12;
+ nsamples &= 0xfff;
pressures = new int[nsamples + 1];
ground_altitude = AltosConvert.pressure_to_altitude(ground_pressure);
@@ -367,7 +376,7 @@ public class MicroData implements AltosUIDataSet {
else
cur = down;
}
-
+
pressures[i+1] = cur;
}
@@ -376,7 +385,14 @@ public class MicroData implements AltosUIDataSet {
crc_valid = crc == current_crc;
- time_step = 0.192;
+ switch (log_id) {
+ case LOG_ID_MICROPEAK:
+ time_step = 2 * CLOCK;
+ break;
+ case LOG_ID_MICROKITE:
+ time_step = 200 * CLOCK;
+ break;
+ }
stats = new MicroStats(this);
} catch (FileEndedException fe) {
throw new IOException("File Ended Unexpectedly");
@@ -389,5 +405,5 @@ public class MicroData implements AltosUIDataSet {
pressures = new int[1];
pressures[0] = 101000;
}
-
+
}
diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java
index 8bdf4b77..1744e803 100644
--- a/micropeak/MicroPeak.java
+++ b/micropeak/MicroPeak.java
@@ -107,7 +107,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
private void DownloadData() {
AltosDevice device = MicroDeviceDialog.show(this);
-
+
if (device != null)
new MicroDownload(this, device);
}
@@ -128,7 +128,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
if (save.runDialog())
SetName(data.name);
}
-
+
private void Export() {
if (data == null) {
no_data();
diff --git a/src/Makefile b/src/Makefile
index 4e8b3c20..df7a31ee 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -39,7 +39,7 @@ ARMM0DIRS=\
easymini-v1.0 easymini-v1.0/flash-loader
AVRDIRS=\
- telescience-v0.1 telescience-pwm micropeak nanopeak-v0.1
+ telescience-v0.1 telescience-pwm micropeak nanopeak-v0.1 microkite
SUBDIRS=
diff --git a/src/kernel/ao_log_micro.c b/src/kernel/ao_log_micro.c
index d665efb5..aef78def 100644
--- a/src/kernel/ao_log_micro.c
+++ b/src/kernel/ao_log_micro.c
@@ -22,10 +22,17 @@
static uint16_t ao_log_offset = STARTING_LOG_OFFSET;
+#define AO_LOG_ID_SHIFT 12
+#define AO_LOG_ID_MASK ((1 << AO_LOG_ID_SHIFT) - 1)
+
void
ao_log_micro_save(void)
{
uint16_t n_samples = (ao_log_offset - STARTING_LOG_OFFSET) / sizeof (uint16_t);
+
+#if AO_LOG_ID
+ n_samples |= AO_LOG_ID << AO_LOG_ID_SHIFT;
+#endif
ao_eeprom_write(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground));
ao_eeprom_write(PA_MIN_OFFSET, &pa_min, sizeof (pa_min));
ao_eeprom_write(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
@@ -99,8 +106,12 @@ ao_log_micro_dump(void)
uint16_t crc = 0xffff;
ao_eeprom_read(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
+
if (n_samples == 0xffff)
n_samples = 0;
+#if AO_LOG_ID
+ n_samples &= AO_LOG_ID_MASK;
+#endif
nbytes = STARTING_LOG_OFFSET + sizeof (uint16_t) * n_samples;
ao_async_start();
ao_async_byte('M');
diff --git a/src/kernel/ao_microflight.c b/src/kernel/ao_microflight.c
index f680e400..df624e79 100644
--- a/src/kernel/ao_microflight.c
+++ b/src/kernel/ao_microflight.c
@@ -43,10 +43,12 @@ void
ao_microflight(void)
{
int16_t sample_count;
+ int16_t log_count;
uint16_t time;
uint32_t pa_interval_min, pa_interval_max;
int32_t pa_diff;
- uint8_t h, i;
+ uint8_t h;
+ uint8_t i;
uint8_t accel_lock = 0;
uint32_t pa_sum = 0;
@@ -93,7 +95,10 @@ ao_microflight(void)
}
/* Log the remaining samples so we get a complete history since leaving the ground */
- for (; i != h; i = SKIP_PA_HIST(i,2)) {
+#if LOG_INTERVAL < NUM_PA_HIST
+ for (; i != h; i = SKIP_PA_HIST(i,2))
+#endif
+ {
pa = pa_hist[i];
ao_log_micro_data();
}
@@ -101,6 +106,7 @@ ao_microflight(void)
/* Now sit around until the pressure is stable again and record the max */
sample_count = 0;
+ log_count = 0;
pa_min = ao_pa;
pa_interval_min = ao_pa;
pa_interval_max = ao_pa;
@@ -112,8 +118,11 @@ ao_microflight(void)
ao_microsample();
if ((sample_count & 3) == 0)
ao_led_off(AO_LED_REPORT);
- if (sample_count & 1)
+ if (log_count == LOG_INTERVAL - 1) {
ao_log_micro_data();
+ log_count = 0;
+ } else
+ log_count++;
/* If accelerating upwards, don't look for min pressure */
if (ao_pa_accel < ACCEL_LOCK_PA)
diff --git a/src/microkite/.gitignore b/src/microkite/.gitignore
new file mode 100644
index 00000000..7a5d0a1f
--- /dev/null
+++ b/src/microkite/.gitignore
@@ -0,0 +1,2 @@
+ao_product.h
+microkite-*
diff --git a/src/microkite/Makefile b/src/microkite/Makefile
new file mode 100644
index 00000000..b7523758
--- /dev/null
+++ b/src/microkite/Makefile
@@ -0,0 +1,134 @@
+#
+# Tiny AltOS build
+#
+#
+vpath % ../attiny:../drivers:../kernel:../product:..
+vpath ao-make-product.5c ../util
+vpath make-altitude-pa ../util
+
+include ../avr/Makefile.defs
+
+PROGNAME=microkite-v0.1
+PROG=$(PROGNAME)-$(VERSION).elf
+HEX=$(PROGNAME)-$(VERSION).ihx
+
+SCRIPT=microkite-load
+
+PUBLISH_DIR=$(HOME)/altusmetrumllc/Binaries
+PUBLISH_HEX=$(PUBLISH_DIR)/$(HEX)
+PUBLISH_SCRIPT=$(PUBLISH_DIR)/$(SCRIPT)
+
+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=MicroKite-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
+
+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) $(HEX) microkite-load
+
+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)
+
+$(HEX): $(PROG)
+ avr-size $(PROG)
+ $(OBJCOPY) -R .eeprom -O ihex $(PROG) $@
+
+
+load: $(HEX)
+ $(LOADCMD) $(LOADARG)$(HEX)
+
+load-slow: $(HEX)
+ $(LOADCMD) $(LOADSLOW) $(LOADARG)$(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) $(HEX) $(SCRIPT)
+ rm -f ao_product.h
+
+publish: $(PUBLISH_HEX) $(PUBLISH_SCRIPT)
+
+$(PUBLISH_HEX): $(HEX)
+ cp -a $(HEX) $@
+
+$(PUBLISH_SCRIPT): $(SCRIPT)
+ cp -a $(SCRIPT) $@
+
+load-product:
+ ./$(SCRIPT) fast
+
+load-product-slow:
+ ./$(SCRIPT) slow
+
+../altitude-pa.h: make-altitude-pa
+ nickle $< > $@
+
+$(SCRIPT): $(SCRIPT).tmpl Makefile ../Version
+ sed -e 's/%HEX%/$(HEX)/' -e 's/%LOADCMD%/$(LOADCMD)/' -e 's/%LOADARG%/$(LOADARG)/' -e 's/%LOADSLOW%/$(LOADSLOW)/' $(SCRIPT).tmpl > $@ || (rm $@ && exit 1)
+ chmod +x $@
+
+install:
+
+uninstall:
+
+$(OBJ): ao_product.h $(INC)
diff --git a/src/microkite/ao_pins.h b/src/microkite/ao_pins.h
new file mode 100644
index 00000000..3c56dfb8
--- /dev/null
+++ b/src/microkite/ao_pins.h
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+
+#ifndef _AO_PINS_H_
+#define _AO_PINS_H_
+#include <avr/pgmspace.h>
+
+#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)
+
+#define BOOST_DETECT 1200 /* 100m (ish) */
+#define LOG_INTERVAL 200 /* 19.2 seconds */
+
+#define AO_LOG_ID AO_LOG_ID_MICROKITE
+
+#endif /* _AO_PINS_H_ */
diff --git a/src/microkite/microkite-load.tmpl b/src/microkite/microkite-load.tmpl
new file mode 100644
index 00000000..08236a15
--- /dev/null
+++ b/src/microkite/microkite-load.tmpl
@@ -0,0 +1,20 @@
+#!/bin/sh
+dir=`dirname $0`
+
+HEX="$dir"/"%HEX%"
+LOADCMD="%LOADCMD%"
+LOADARG="%LOADARG%"
+LOADSLOW="%LOADSLOW%"
+LOADFAST=""
+
+case "$1" in
+fast)
+ LOADSPEED="$LOADFAST"
+ ;;
+*)
+ LOADSPEED="$LOADSLOW"
+ ;;
+esac
+
+echo ${LOADCMD} ${LOADSPEED} ${LOADARG}${HEX}
+${LOADCMD} ${LOADSPEED} ${LOADARG}${HEX}
diff --git a/src/product/ao_micropeak.h b/src/product/ao_micropeak.h
index 0ec407d7..396b9a23 100644
--- a/src/product/ao_micropeak.h
+++ b/src/product/ao_micropeak.h
@@ -29,6 +29,17 @@
#define BOOST_DETECT 360 /* 30m at sea level, 36m at 2000m */
#endif
+#ifndef LOG_INTERVAL
+#define LOG_INTERVAL 2 /* 192 ms */
+#endif
+
+#define AO_LOG_ID_MICROPEAK 0
+#define AO_LOG_ID_MICROKITE 1
+
+#ifndef AO_LOG_ID
+#define AO_LOG_ID AO_LOG_ID_MICROPEAK
+#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)