Skip to content

Kalman filter does not update position between GPS fixes if GPS updates are too infrequent #134

Open
@OlofLindber9

Description

@OlofLindber9

I’m using the library to combine accelerometer data and GPS fixes with a Kalman filter. My intention is to track user movement more frequently than once per minute (the GPS update rate), without draining the battery too much. However, I’m observing that when I only receive a GPS fix once per minute, the calculated Kalman-filtered position never changes from the last GPS fix, even though the user actually moves. If I reduce the GPS interval to every 10 seconds, the Kalman filter does a slightly better job, but its still not great.

Anyone have any ideas what I am missing?

I tested this on a OnePlus Nord 4

This is how I use the library:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_accelerometerandgps);

    // 1) Register this class as a listener
    ServicesHelper.addLocationServiceInterface(this);

    // 2) Init preferences
    mSharedPref = PreferenceManager.getDefaultSharedPreferences(this);

    // 5) Set your desired location provider
    Settings.LocationProvider finalProvider = Settings.LocationProvider.FUSED;

    // 6) Connect to the service
    ServicesHelper.getLocationService(this, value -> {
        if (value.IsRunning()) {
            return;
        }
        value.stop();

        // 7) Build your Kalman filter settings
        Settings settings = new Settings(
                Utils.ACCELEROMETER_DEFAULT_DEVIATION,
                Integer.parseInt(mSharedPref.getString("pref_gps_min_distance", "10")),
                Integer.parseInt(mSharedPref.getString("pref_gps_min_time", "60000")),
                Integer.parseInt(mSharedPref.getString("pref_position_min_time", "500")),
                Integer.parseInt(mSharedPref.getString("pref_geohash_precision", "6")),
                Integer.parseInt(mSharedPref.getString("pref_geohash_min_point", "2")),
                Double.parseDouble(mSharedPref.getString("pref_sensor_frequency", "10")),
                this,           //logger
                true,          //filterMockGpsCoordinates
                false,         //onlyGpsSensor
                true,         //useGpsSpeed
                Utils.DEFAULT_VEL_FACTOR,
                Utils.DEFAULT_POS_FACTOR,
                finalProvider
        );

        value.reset(settings);
        value.start();
    });
}

@Override
public void locationChanged(Location location) {
    lastKalmanLocation = location;

    Log.d("debug message", "Method2: lat=" + location.getLatitude() +
            " lon=" + location.getLongitude());

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions