X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fmicropeak%2Fao_micropeak.c;h=10e1d0f9f3246d7a5e8aba35a60605d44a8b8ef3;hb=c233ef67f42c14cb1d0e0542a9523b279f826af5;hp=6ceec3b5164aa97e559a83fe0bfac31675435007;hpb=5a55501660ebab3b858a48483c5df1cfb4e858e4;p=fw%2Faltos diff --git a/src/micropeak/ao_micropeak.c b/src/micropeak/ao_micropeak.c index 6ceec3b5..10e1d0f9 100644 --- a/src/micropeak/ao_micropeak.c +++ b/src/micropeak/ao_micropeak.c @@ -47,6 +47,15 @@ ao_pa_get(void) #define GROUND_AVG_SHIFT 4 #define GROUND_AVG (1 << GROUND_AVG_SHIFT) +/* Pressure change (in Pa) to detect boost */ +#define BOOST_DETECT 120 /* 10m at sea level, 12m at 2000m */ + +/* Wait after power on before doing anything to give the user time to assemble the rocket */ +#define BOOST_DELAY AO_SEC_TO_TICKS(30) + +/* Pressure change (in Pa) to detect landing */ +#define LAND_DETECT 12 /* 1m at sea level, 1.2m at 2000m */ + static void ao_compute_height(void) { @@ -115,6 +124,7 @@ main(void) ao_log_micro_dump(); #endif + ao_delay(BOOST_DELAY); /* Wait for motion, averaging values to get ground pressure */ time = ao_time(); ao_pa_get(); @@ -122,23 +132,20 @@ main(void) sample_count = 0; for (;;) { time += SAMPLE_SLEEP; - ao_delay_until(time); if (sample_count == 0) - ao_led_on(AO_LED_BLUE); + ao_led_on(AO_LED_REPORT); + ao_delay_until(time); ao_pa_get(); if (sample_count == 0) - ao_led_off(AO_LED_BLUE); + ao_led_off(AO_LED_REPORT); pa_avg = pa_avg - (pa_avg >> FILTER_SHIFT) + pa; pa_diff = pa_ground - pa_avg; - if (pa_diff < 0) - pa_diff = -pa_diff; - /* about 2 meters at sea level, more if you're higher */ - if (pa_diff > (24 << FILTER_SHIFT)) + /* Check for a significant pressure change */ + if (pa_diff > (BOOST_DETECT << FILTER_SHIFT)) break; if (sample_count < GROUND_AVG * 2) { - ao_led_off(AO_LED_BLUE); if (sample_count < GROUND_AVG) pa_sum += pa; ++sample_count; @@ -165,10 +172,10 @@ main(void) time += SAMPLE_SLEEP; ao_delay_until(time); if ((sample_count & 3) == 0) - ao_led_on(AO_LED_BLUE); + ao_led_on(AO_LED_REPORT); ao_pa_get(); if ((sample_count & 3) == 0) - ao_led_off(AO_LED_BLUE); + ao_led_off(AO_LED_REPORT); #if HAS_EEPROM ao_log_micro_data(AO_LOG_MICRO_DATA | pa); #endif @@ -178,8 +185,9 @@ main(void) if (sample_count == (GROUND_AVG - 1)) { pa_diff = pa_interval_max - pa_interval_min; - /* About 1m at sea level */ - if (pa_diff < (12 << FILTER_SHIFT)) + + /* Check to see if the pressure is now stable */ + if (pa_diff < (LAND_DETECT << FILTER_SHIFT)) break; sample_count = 0; pa_interval_min = pa_avg;