Let's Make Robots!

Good algorithm for when to trust GPS speed and course?

In my testing so far, GPS modules that are locked in do a much better job in motion than sitting still. If I ride a bike down the street with a GPS, it will capture my route almost perfectly until I stop and then it gets "fidgety" and will jump around. Some modules do a better job of staying nearly fixed, but  I haven't had any that were perfect. The location data is still reasonably valid, but the implied motion throws off the speed and course reporting drastically. I need to come up with an algorithm to know when to ignore it but I need to start using it as soon as it is valid. I am doing course correction.

I could use 2 GPS modules in my craft and assume I am moving and tracking well if they stay in line with each other, but that seems like overkill and would introduce a delay, having to wait for sentences from 2 GPSes, correlate them and report it (I think I would end up using a dedicated controller for that and have it communicate the result to the main one).

The obvious simple software solution is to only use it when the current reading and the previous 2 are in a line or low angle with the previous one near the midpoint. But that would cause me to ignore it during acceleration and/or tight turns. In all likelihood, the acceleration or turning will have been caused by the controller, so I may be able to work that into the test but it can get som complicated that I could have trouble keeping up.

Thoughts or better yet experiences welcome...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

if it works good while riding the bike, how fast is that? 10mph?   trust it when going 10 or more, ignore it under 10, etc.

I think surveyers use gps in a fixed method over time, taking readings and averaging them constantly.  the longer it remains in 1 spot, the more accuracte the average reading is.    this is nature of how the satellites pass over head, as some come into range, others are leaving, so they all help provide accuracy.

for 5 or 10 mph in a small boat, you may never get good speed data.   once I used my gps on a jet plane and at 30,000 going 400mph, I have to assume it was very accurate.

make sure your using a good gps chip.  I think the good ones can track 20+ satellites whereas the more economical models are good for 10-12 satellites.  external antennas will help track more as well.


Even my walking tests with multiple GPS modules show a marked increase in reliability while moving:

I started at the bottom, which has a bunch of wild data as the units locked in. I lost my logging of the one that goes away, but look at the 3 in the top half when they all have good locks. I am getting accuracy in the 2m range with respect to each other (and in reality; that Goggle picture is correct about where I walked in the parking lot). At first glance, the red and blue lines crossing seems like an awesome example of accuracy but it really isn't. The difference in course being reported at that time is substantial enough that I would likely correct for it. Also look at the "loops" that I get from the "chatter" from a GPS while I am stopped. It would be a lot easier to eliminate points that hopped around in a more random fashion like the green line while it locked in. That little figure 8 the red line does while I am stopped in the middle is probably the best example of bogus data that is hard to eliminate. It doesn't look random at all. It looks like I walked in a good clean oval and circle. Only it never happened.


To build on what Paul said, why not try out a variable windowed average?
At first I considered that you could have the window size inversely proportional to motor speed, for example: average across two readings at full speed, 4 readings at half speed, and 6 readings at rest. Then I realised that if this is for your boat project, motor speed and boat speed are not so conveniently related =)

...but wait, aren't we going to get a speed reading from the distance between GPS readings anyway? Assuming the readings come in at a constant rate (or even vaguely close to it) then the distance between averaged packets of readings should be reasonably proportional to the current speed of the boat.
Starting from rest and averaging a 'large' number of readings you should get a decent first coordinate. From the next average you can determine the distance travelled, and scale the number of readings to use in the next average accordingly. The minimum and maximum number of readings to take for your averages will be a factor of your GPS unit's output rate, and the maximum travel speed of your boat.
Perhaps the minimum number of readings per average will only be 1? Maybe the number of readings to average across should drop to a minimum at something less than the maximum speed? Time for more testing =)

My cheap GPS modules love to go fast. After they have been on for a couple of minutes, they are rock solid in motion. Motion means not stopping. They hold steady through some slow turns. I really don't understand why they seem to hop so much when still.

This turned out to be easy after all. OK, with caveats about extreme conditions and the possibility of introducing minor inefficiency in my route at times, there are a few fairly simple rules...

While in a slow tight turn (a pivot), use the compass.

If the motors have been running at least 2 seconds since the last stop or pivot, use the GPS.

If the motors are running and the compass and GPS are within 30 degrees of each, use the GPS.

That pretty much covers it. If you drop through that logic in a case where the motors have been running a while and the compass and GPS are not within 30 degrees of each other, you may want to cut power to the motors as there exists some chance you have beached the boat (DAMHIKT :) ). I am back and forth about whether or not to go with GPS unconditionally after 2 seconds because of that "possibility". If I don't, ferrying across a strong current will be very difficult; being > 30 degrees "off" is not that uncommon when ferrying.

Other than one minor incident that thankfully caused no damage, testing went very well.