X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Ftest%2Fao_micropeak_test.c;h=952460d0c2831c2daf12808037ffa947ee019171;hb=8d53868e67b51d8908e55c6a2e7a3b687529957d;hp=0468640238aae33c6ffccc5d5e1763704533d1b3;hpb=540309240a8515116120dbd4403902282ed8c27b;p=fw%2Faltos diff --git a/src/test/ao_micropeak_test.c b/src/test/ao_micropeak_test.c index 04686402..952460d0 100644 --- a/src/test/ao_micropeak_test.c +++ b/src/test/ao_micropeak_test.c @@ -3,7 +3,8 @@ * * 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. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -33,6 +34,7 @@ uint8_t ao_flight_debug; #define AO_FLIGHT_TEST typedef int32_t alt_t; +typedef int32_t pres_t; #define AO_MS_TO_TICKS(ms) ((ms) / 10) @@ -44,10 +46,10 @@ static void ao_led_on(uint8_t led) { static void ao_led_off(uint8_t led) { } -static void ao_delay_until(uint16_t target) { +static void ao_delay_until(AO_TICK_TYPE target) { } -static uint16_t ao_time(void) { +static AO_TICK_TYPE ao_time(void) { return 0; } @@ -55,7 +57,7 @@ static uint16_t ao_time(void) { #include "ao_microkalman.c" #include "ao_convert_pa.c" -uint16_t now; +AO_TICK_TYPE now; uint8_t running; void ao_log_micro_data() { @@ -67,10 +69,11 @@ ao_micro_report(void) { if (running) { alt_t ground = ao_pa_to_altitude(pa_ground); - printf ("%6.2f %10d %10d %10d\n", now / 100.0, + printf ("%6.3f %10d %10d %10d %10d %10d\n", now / 100.0, ao_pa_to_altitude(pa) - ground, ao_pa_to_altitude(ao_pa) - ground, - ao_pa_to_altitude(pa_min) - ground); + ao_pa_to_altitude(pa_min) - ground, + ao_pa_speed, ao_pa_accel); } } @@ -92,14 +95,24 @@ ao_pa_get(void) double time; double pressure; static double last_time; + static double last_pressure; static int been_here; static int start_samples; + static int is_mp; + static int use_saved; if (been_here && start_samples < 100) { start_samples++; return; } ao_micro_report(); + if (use_saved) { + pa = last_pressure; + now = last_time; + use_saved = 0; +// printf ("use saved %d %d\n", now, pa); + return; + } for (;;) { if (!fgets(line, sizeof (line), emulator_in)) exit(0); @@ -119,15 +132,32 @@ ao_pa_get(void) } } continue; + } else if (!strcmp(toks[0], "Time")) { + time_id = 0; + pa_id = 1; + is_mp = 1; + continue; } time = strtod(toks[time_id],NULL); pressure = strtod(toks[pa_id],NULL); - if (been_here && time - last_time < 0.1) + time *= 100; + if (been_here && time - last_time < 0.096 * 100) continue; - been_here = 1; + if (is_mp && been_here) { + double avg_pressure = (pressure + last_pressure) / 2.0; + double avg_time = (time + last_time) / 2.0; + + now = avg_time; + pa = avg_pressure; +// printf ("new %d %d\n", now, pa); + use_saved = 1; + } else { + now = floor (time + 0.5); + pa = pressure; + } + last_pressure = pressure; last_time = time; - now = floor (time * 100 + 0.5); - pa = pressure; + been_here = 1; break; } }