2

I have to implement Kalman filter for a better accuracy with GPS positions... I use Stochastically solution (Smooth GPS data). In ValidPosition I have some checks like:

public boolean checkPosition(Location location) {

    if (( location != null ) &&
        (distance != 0) &&
        (distance > MINIMUM_DISTANCE) && // 10 metres

        (location.hasSpeed()) && 
        (location.getSpeed() > 0) && 
        (averageTime < HUMANSPEED) &&

        (location.hasAccuracy()) &&
        (location.getAccuracy() < MINIMUM_ACCURACY) &&
        (isBetterLocation(location, lastLocation)) // From Google example in http://developer.android.com/guide/topics/location/strategies.html#BestPerformance
            return true;
    }

    return false;
}

Now, in my main class with Location Fusion Provider I have this:

public static final int ACCURACY_DECAYS_TIME = 3; // Metres per second

private KalmanLatLong kalmanLatLong = new KalmanLatLong(ACCURACY_DECAYS_TIME);

private ValidPosition validPosition = new ValidPosition();

@Override
public void onLocationChanged(Location location) {

    if(validPosition.checkPosition(location)) {
        kalmanLatLong.process(
                location.getLatitude(),
                location.getLongitude(),
                location.getAccuracy(),
                location.getTime());

        mCallback.handleNewLocation(location);
    }
}`

And now? How can I use Kalman predictions? What do I have write here in Stochastically code?

// TODO: USE VELOCITY INFORMATION HERE TO GET A BETTER ESTIMATE OF CURRENT POSITION

Thanks

Community
  • 1
  • 1
Nammen8
  • 619
  • 1
  • 11
  • 31
  • The GPS position which is output by the GPS chip is already heavily Kalman filtered, having much more filter input information than after leaving the chip. I doubt that that data will get better after whatever post prcoessing kalman filter. Just make sure you filter location when the position or car is standing still. – AlexWien Jul 06 '15 at 16:33
  • Hi, in what way? When getSpeed is zero I reject those positions? With no filter for example I get a 1st LatLng coordinate but the 2nd LatLng is located 100 meters away from the 1st coordinate, so I guess that is very unlikely that a user can move 100 meters away in a few seconds... – Nammen8 Jul 06 '15 at 20:37

1 Answers1

0

You forgot to get processed result back from the kalmanLatLong object. You need to do something like this:

if(validPosition.checkPosition(location)) {
    kalmanLatLong.process(
            location.getLatitude(),
            location.getLongitude(),
            location.getAccuracy(),
            location.getTime());

    location.setLatitude(kalmanLatLong.get_lat());
    location.setLongitude(kalmanLatLong.get_lng());
    location.setAccuracy(kalmanLatLong.get_accuracy());

    mCallback.handleNewLocation(location);
}

As for your second question, I don't think it's trivial and should be based more on experimental data. Simple assumption with linear decay works well in most cases.

Ilya Polenov
  • 362
  • 3
  • 10
  • Hi, thanks for your reply... Kalman filter is a prediction, right? If I set data like in your code, is it a prediction? I have to check if my location if is a valid location with Kalman. In this case I set a prediction, not the real location (or no? :P ) Also, what do I have to do in TODO about speed? Kind regards :) – Nammen8 Jul 06 '15 at 15:37
  • Something like this? `if (predictedLocation.distanceTo(location) < 10m) // Hadle new location` – Nammen8 Jul 06 '15 at 18:12
  • Oh, so you want to predict? Sorry I didn't understand your question originally. Kalman filter is originally a noise filter(which is described in original question as jumping). It removes sensor noise and smoothes out the sensor output. To predict you need to feed kalman filter with your predicted location(like prediction is a separate filter) with some arbitrary lower accuracy. You won't increase accuracy with predictions, but you can reduce time between location updates. Do you want to do that? – Ilya Polenov Jul 06 '15 at 22:46
  • Or you can also try predicting location using other sensor data(like accelerometer and compass data) and then feeding this predicion to the kalman filter. If done right, this will improve location accuracy. How you predict new location depends on what is your actual use(car, robot, human, bicycle). For example, human will tend to rotate the device a lot, so compass data is not very useful. – Ilya Polenov Jul 06 '15 at 23:03
  • I understand that if I have a location, kalman filter say me prediction locations... with predictedLocation from Kalman filter with `if (predictedLocation.distanceTo(location) < 10m) // Hadle new location` I get not so bad results, just lucky? – Nammen8 Jul 06 '15 at 23:17
  • Where do you get `predictedLocation` from? Kalman filter by itself won't give you predictions, it can only minimize the error from your own predictions by smoothing out the sudden jumps. – Ilya Polenov Jul 07 '15 at 00:37
  • I wrote this: http://s12.postimg.org/w5pi32771/on_Location_Changed.png In this page (http://stackoverflow.com/questions/9735744/kalman-filter-for-gps-android), and in others, I read: "A Kalman filter formalizes a simple idea: when you know how fast you’re going, you can predict your geolocation from the last reported GPS position, and then update when a new GPS report comes in.". Why do you say that it's not for predictions? – Nammen8 Jul 07 '15 at 07:45
  • It can be used for predictions, but it cannot predict by itself. Basically by knowing how fast you're going you can predict your location with a simple formula(kind of like `newX = Vx * dt + oldX`). Then if you feed this location to the kalman filter, it will smooth out your prediction in case it was not very accurate. The more sources of location info you feed into kalman filter, the better it will estimate your location. – Ilya Polenov Jul 07 '15 at 08:20
  • I suggest you taking this course https://www.udacity.com/course/artificial-intelligence-for-robotics--cs373 online. It covers Kalman filters on the second lesson with very intuitive approach. It also covers its limitations in position estimation in later lessons. – Ilya Polenov Jul 07 '15 at 08:21
  • Thanks you so much... so if I do something in "// TO DO: USE VELOCITY INFORMATION HERE TO GET A BETTER ESTIMATE OF CURRENT POSITION" in Stochastically solution (http://stackoverflow.com/a/15657798/5053585) it's ok. thanks again PD AlexWien say that it's useless use this filter – Nammen8 Jul 07 '15 at 09:00