Kalman GPS filtering #7775
Replies: 1 comment 2 replies
-
Kalman Filter..it is a few years ago since i last played with one, but I'll add my 2 cents anyway.
It also should contain a prediction step of the next position which is hard to guess without an external direction and speed source.
Thats what the covariance sensor (co-)variance is for. Unfortunately we do not seem to have any. Best case would be a separate variance for lat and lon. I see you somehow used hdop. For both reasons I believe a kalman is not optimal here. Since it is raining all the time and I'm lazy I put my watch for a quick test stationary on the balcony and did some measurements. First fix is on the right, my actual position is more to the left. This is the result of above script which looks pretty much the same: I belive there is room for improvement, so I searched for "node kalman filter" and https://www.npmjs.com/package/kalman-filter
Since the watch its stationary the prediction step I used is prev pos = next pos. For the variance I see you did hdop*5 so I did the same. I skipped degree to metric conversion because the movement is minimal. After all it is pretty dirty (units do not match) and should not be used as it is, but this is the result: It is a bit cleaner, so yes there is some room for improvement. Also my version above obviously does not run on espruino. It is just a quick test. The position does converge faster if the initial state would be the real position. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There was a post recently which mentioned the distance measurements in the run app from GPS differing from that in the Recorder app.
It's come up a few times in the past, and basically it's because the GPS location includes some inaccuracy and can 'wobble around' over time, and that wobble adds to the distance.
It's been suggested that the way to get rid of this wobble and smooth things out is to use a Kalman filter, which builds its own internal idea about where on earth you are and only updates it based on how accurate your GPS signal is. As far as I can tell in its simplest form it is basically a weighted average where the weight depends how how much you trust the GPS signal.
I thought I'd have a play based on some previously contributed Kalman code which kind of worked at some point for the BangleRun app: https://github.com/espruino/BangleApps/blob/2e8b9ac2cbd0ea70248bbd2ece53ae37203eab7e/apps/banglerun/src/gps.ts#L94
Here are the results based on me turning the GPS on in the office and then leaving home. Red = original, Blue = Kalman:
You can see that initially the red value is pretty useless as satellites are found and the fix changes, and the filter tries to smooth this out. I'm obviously not walking through the middle of all those houses, but to the north side (but there's nothing we can do with the raw data!).
The main thing is it's correcting less when it has less accurate data, but IMO it's not really enough, and I don't know enough to really be sure how to change things. My gut feeling says ideally if GPS says we're 10m away from the current position but it's only accurate to ~25m we shouldn't be updating the location at all - but that's not what is happening right now. I'm not sure I can get it much better or if it's worth including (a weighted average of lat/lon would be way faster and probably just as good).
I've pasted my code below if anyone fancies having a look. I've disabled the velocity element (which I believe just kept track of velocity in the same way, and used it to add higher uncertainty to the Kalman filter when going faster) as I didn't have any trust it was doing anything useful.
Once you have data (see the comment) you can just run it in Node.js in the desktop and view the GPX traces in a viewer to see how it's working.
Beta Was this translation helpful? Give feedback.
All reactions