Skip to content

Instantly share code, notes, and snippets.

@glebov21
Created June 19, 2018 11:44
Show Gist options
  • Save glebov21/ca2209774ec95190dc173f78ebd91a35 to your computer and use it in GitHub Desktop.
Save glebov21/ca2209774ec95190dc173f78ebd91a35 to your computer and use it in GitHub Desktop.
/* Kalman Filter */
float Qvalue;
long locationTimeInMillis = (long)(location.getElapsedRealtimeNanos() / 1000000);
long elapsedTimeInMillis = locationTimeInMillis - runStartTimeInMillis;
if(currentSpeed == 0.0f){
Qvalue = 3.0f; //3 meters per second
}else{
Qvalue = currentSpeed; // meters per second
}
kalmanFilter.Process(location.getLatitude(), location.getLongitude(), location.getAccuracy(), elapsedTimeInMillis, Qvalue);
double predictedLat = kalmanFilter.get_lat();
double predictedLng = kalmanFilter.get_lng();
Location predictedLocation = new Location("");//provider name is unecessary
predictedLocation.setLatitude(predictedLat);//your coords of course
predictedLocation.setLongitude(predictedLng);
float predictedDeltaInMeters = predictedLocation.distanceTo(location);
if(predictedDeltaInMeters > 60){
Log.d(TAG, "Kalman Filter detects mal GPS, we should probably remove this from track");
kalmanFilter.consecutiveRejectCount += 1;
if(kalmanFilter.consecutiveRejectCount > 3){
kalmanFilter = new KalmanLatLong(3); //reset Kalman Filter if it rejects more than 3 times in raw.
}
kalmanNGLocationList.add(location);
return false;
}else{
kalmanFilter.consecutiveRejectCount = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment