Comments (6)
We've had the same problem. It seems that the problem is the value of timeInterval
. It's 0 when calculating velocityXComponent
, velocityYComponent
and velocityZComponent
.
See lines 197, 198 and 199:
https://github.com/Hypercubesoft/HCKalmanFilter/blob/master/HCKalmanFilter/HCKalmanAlgorithm.swift#L197
After calculating the velocity, the outcome is:
velocityXComponent = (Double) -Inf
velocityYComponent = (Double) NaN
velocityZComponent = (Double) NaN
What's the best approach? Should we skip the location? Or should the KalmanFilter be altered to devide by 1 instead of zero?
from hckalmanfilter.
Hey Thomas thanks for bringing up this issue,
Can you suggest any best way to overcome this issue,? I mean instead using bunch of if let's
or guard
statements.
from hckalmanfilter.
Hey Yash,
I am not using the library anymore, but in the past, I temporary "solved" the issue by resetting the Kalman filter when it was dirty. Here is some parts of the code:
class LocationDataProvider: CLLocationManagerDelegate {
// ...
private var locationManager: CLLocationManager?
private var kalmanAlgorithm: HCKalmanAlgorithm?
// ...
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last!
var correctedLocation: CLLocation!
// Use the kalman algorithm to smooth location data
if self.kalmanAlgorithm == nil {
self.kalmanAlgorithm = HCKalmanAlgorithm(initialLocation: location)
correctedLocation = location
} else {
correctedLocation = self.kalmanAlgorithm!.processState(currentLocation: location)
}
correctedLocation = self.tempFixForNaNLocations(location: location, correctedLocation: correctedLocation)
// ... <Use correctedLocation>
}
// FIX: Temporary fix to avoid NaN locations: https://github.com/Hypercubesoft/HCKalmanFilter/issues/19
private func tempFixForNaNLocations(location: CLLocation, correctedLocation: CLLocation) -> CLLocation {
if correctedLocation.coordinate.latitude.isNaN || correctedLocation.coordinate.longitude.isNaN || correctedLocation.altitude.isNaN {
self.kalmanAlgorithm = HCKalmanAlgorithm(initialLocation: location)
return location
} else {
return correctedLocation
}
}
}
Hope this can help you.
Cheers.
from hckalmanfilter.
Hey, Thomas
Yeah, I too figured out a way something like that.
Though Really appreciate you taking out time to write the snippet. Thank you.
from hckalmanfilter.
Hey guys, I found this library right now and didn't test it yet but looked into this issue.
For me it sounds as if you are using cached locations which you receive in your didUpdateLocations method because the timestamp of the new and previous location must be the same if these three values are 0.
In my own app, I skip cached locations in my didUpdateLocations method when they are older than 10 seconds (however, you should test how many seconds fit to your case). I also skip locations which are invalid (horizontalAccuracy < 0) and those with an horizontalAccuracy over 30 meters.
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let mostRecentLocation = locations.last else {
return
}
let age = -mostRecentLocation.timestamp.timeIntervalSinceNow
// Filter cached locations, invalid ones and ones with accuracy over 30 meters
if age > 10 || mostRecentLocation.horizontalAccuracy < 0 || mostRecentLocation.horizontalAccuracy > 30 {
return
}
// ... Use your location
}
This will not fix the library code which doesn't test for division by zero, but maybe this will help anyway.
from hckalmanfilter.
Hello,
Just if some one else got this error.
I have done some investigation and i find that i have a NaN error when my location (previous and current one) have the same timestamp.
If they have the same timestamps some we do a division by 0 and we got a NaN.
To prevent it you can just check your locations timestamps before use Kalman or update KalmanAlgo to set value to 0 if the interval between locations is 0
from hckalmanfilter.
Related Issues (20)
- Feature Request: Include elevation HOT 1
- Performance when post-processing HOT 4
- I can't build it HOT 3
- Use of kCLLocationAccuracyBestForNavigation HOT 1
- watchos support in CocoaPods HOT 4
- Speed Property lost HOT 3
- 1.2.2 version not pushed to CocoaPods master repo HOT 1
- Expression was too complex HOT 1
- Distortion of initial GPS points in a trip HOT 1
- Use projected coordinates instead of lat/long
- Package.swift file - Swift Package Manager
- Pods folder should be removed from the project HOT 1
- return nan
- Whether location speed can be added?
- can add speed KalmanFilter?
- XCode 9 Error: Expression too complex to be solved in reasonable time HOT 2
- `processState` return wrong location HOT 7
- README.md mistake? HOT 1
- Build Error Xcode 9 (9A235) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hckalmanfilter.