test: Accept micropeak CSV files for micropeak testing
authorKeith Packard <keithp@keithp.com>
Mon, 4 Feb 2013 17:56:18 +0000 (09:56 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 4 Feb 2013 17:56:18 +0000 (09:56 -0800)
This interpolates the missing values to provide a reasonable testing
environment for the Micropeak flight firmware.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/test/Makefile
src/test/ao_micropeak_test.c
src/test/plotmicro

index 87bd70fe602c276532536b868706d3d99a6079f0..1c2d771ed6511e818106c30885fd480721f7c167 100644 (file)
@@ -62,5 +62,5 @@ ao_aprs_data.wav: ao_aprs_test
 check: ao_fec_test ao_flight_test ao_flight_test_baro run-tests
        ./ao_fec_test && ./run-tests
 
-ao_micropeak_test: ao_micropeak_test.c ao_microflight.c
-       cc $(CFLAGS) -o $@ ao_micropeak_test.c -lm
\ No newline at end of file
+ao_micropeak_test: ao_micropeak_test.c ao_microflight.c ao_kalman.h
+       cc $(CFLAGS) -o $@ ao_micropeak_test.c -lm
index 0468640238aae33c6ffccc5d5e1763704533d1b3..5961bd9309ff700782dd639505d5d78acc32b7a6 100644 (file)
@@ -67,10 +67,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 +93,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 +130,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;
        }
 }
index cdfcc5817e0dab950ad218da433fcb644dfc4832..bb8f4d1d1ffeac876e1ef2b255ee47686246bd26 100755 (executable)
@@ -3,12 +3,14 @@ for i in "$@"; do
 gnuplot -p << EOF &
 set title "$i"
 set ylabel "height (m)"
+set y2label "accel (m/s²)"
 set xlabel "time (s)"
 set xtics border out nomirror
 set ytics border out nomirror
 set y2tics border out nomirror
 plot "$i" using 1:2 with lines lt 2 axes x1y1 title "raw height",\
      "$i" using 1:3 with lines lt 4 axes x1y1 title "kalman height",\
-     "$i" using 1:4 with lines lt 1 axes x1y1 title "max height"
+     "$i" using 1:4 with lines lt 1 axes x1y1 title "max height",\
+     "$i" using 1:6 with lines lt 3 axes x1y2 title "pa accel"
 EOF
 done