Created
June 19, 2018 11:44
-
-
Save glebov21/ca2209774ec95190dc173f78ebd91a35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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