Rolling average for pad location. Say 'GPS ready'.
authorKeith Packard <keithp@keithp.com>
Sat, 18 Jul 2009 00:06:18 +0000 (17:06 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 18 Jul 2009 00:06:18 +0000 (17:06 -0700)
Use a rolling average for the pad location, instead of just averaging all
positions. This filters out old (presumably less accurate) values eventually.

When enough GPS samples have been acquired, say 'GPS ready'.

Signed-off-by: Keith Packard <keithp@keithp.com>
aoview/aoview.h
aoview/aoview_state.c

index 803bd4a538f186a37ac60ce71c3d356bc72d4d21..b4d1315968ba248284f57678501dd639c223bed8 100644 (file)
@@ -122,6 +122,7 @@ struct aostate {
        double  pad_lon_total;
        double  pad_alt_total;
        int     npad;
+       int     prev_npad;
 
        double  distance;
        double  bearing;
index 8b43ec2993c87559c95f786e057b8f702229755f..cf1594cd8c143297fe8ab587d8f8d8313fc880e2 100644 (file)
@@ -110,6 +110,7 @@ aoview_state_derive(struct aodata *data, struct aostate *state)
        state->report_time = aoview_time();
 
        state->prev_data = state->data;
+       state->prev_npad = state->npad;
        state->data = *data;
        tick_count = data->tick;
        if (tick_count < state->prev_data.tick)
@@ -129,14 +130,20 @@ aoview_state_derive(struct aodata *data, struct aostate *state)
        state->main_sense = data->main / 32767.0 * 15.0;
        state->battery = data->batt / 32767.0 * 5.0;
        if (!strcmp(data->state, "pad")) {
-               if (data->locked && data->nsat > 4) {
+               if (data->locked && data->nsat >= 4) {
                        state->npad++;
                        state->pad_lat_total += data->lat;
                        state->pad_lon_total += data->lon;
                        state->pad_alt_total += data->alt;
-                       state->pad_lat = state->pad_lat_total / state->npad;
-                       state->pad_lon = state->pad_lon_total / state->npad;
-                       state->pad_alt = state->pad_alt_total / state->npad;
+                       if (state->npad > 1) {
+                               state->pad_lat = (state->pad_lat * 31 + data->lat) / 32.0;
+                               state->pad_lon = (state->pad_lon * 31 + data->lon) / 32.0;
+                               state->pad_alt = (state->pad_alt * 31 + data->alt) / 32.0;
+                       } else {
+                               state->pad_lat = data->lat;
+                               state->pad_lon = data->lon;
+                               state->pad_alt = data->alt;
+                       }
                }
        }
        state->ascent = FALSE;
@@ -178,6 +185,8 @@ aoview_speak_state(struct aostate *state)
                        aoview_voice_speak("max speed %d meters per second\n",
                                           (int) state->max_speed);
        }
+       if (state->prev_npad < MIN_PAD_SAMPLES && state->npad >= MIN_PAD_SAMPLES)
+               aoview_voice_speak("g p s ready\n");
 }
 
 void