Coder Social home page Coder Social logo

hypercubesoft / hckalmanfilter Goto Github PK

View Code? Open in Web Editor NEW
290.0 12.0 75.0 68.28 MB

HCKalmanFilter is Swift implementation of Kalman filter algorithm intended to solve problem with GPS tracking

License: MIT License

Ruby 0.03% Swift 99.97%
kalman-filter kalman-filtering kalman gps-tracking gps-tracker gps-correction swift ios

hckalmanfilter's Introduction

CocoaPods Compatible License Platform Swift

logo

HCKalmanFilter is a delightful library for iOS written in Swift. HCKalmanFilter library was created for the implementation of Kalman filter algorithm for the problem of GPS tracking and correction of trajectories obtained based on the measurement of the GPS receiver. The problem occurs in the case of a large oscillation of the coordinates received from the GPS receiver when the accuracy is very small or the GPS signal is very bad. If you have this kind of problem and you need a fluid trajectory of movement without big peaks and deviations, this library is the right choice for you.

screenshot

screenshot

Change Log

1.2.0

  • In this version, we have upgraded the matrix processing functions within our class HCMatrixObject which now use core functions of the Surge Library. It will greatly accelerate the processing of data and lead to faster results being obtained by the algorithm.
  • We fixed small bug because of which it was not possible to build the example project.

1.1.0

  • In this version, we added another new functionality in addition to small bug fixes.

  • At the request of the HCKalmanFilter library user, we decided that in addition to the correction values for latitude and longitude, we should add the correction of the altitude.

Now you can easily get the corrected value for altitude in the following way:

...
let kalmanLocation = hcKalmanFilter.processState(currentLocation: myLocation)
print(kalmanLocation.altitude)
...

Getting Started

  • Download HCKalmanFilter Sample project, open HCKalmanFilter Sample folder via Terminal and run the following command:

    $ pod install
    

    This will install all necessary dependencies for this sample project. After you have installed all necessary dependencies, open HCKalmanFilter Sample.xcworkspace and try out the included iPhone example app.

  • Read the Installation guide, Usage guide, or other articles on the Wiki about Kalman Filter Algorithm

Installing

CocoaPods is a dependency manager for Objective-C and Swift, which automates and simplifies the process of using 3rd-party libraries like HCKalmanFilter in your projects.

Podfile

To integrate HCKalmanFilter into your Xcode project using CocoaPods, specify it in your Podfile:

target 'TargetName' do
  use_frameworks!
  pod 'HCKalmanFilter'
end

Then, run the following command:

$ pod install

With source code

Download repository, then add HCKalmanAlgorithm directory to your project.

Usage

1. First import HCKalmanFilter module

import HCKalmanFilter

2. After installing and importing Kalman Filter library it is necessary to initialize the HCKalmanFilter object before using it.

let hcKalmanFilter = HCKalmanAlgorithm(initialLocation: myInitialLocation)
  • myInitialLocation is the location where the tracking starts.

3. if necessary, it is possible to correct the value of the rValue parameter. rValue parameter is value for Sensor Noise Covariance Matrix. The default value is 29.0, this is the recommended value for the GPS problem, with this value filter provides optimal accuracy. This value can be adjusted depending on the needs, the higher value of rVaule variable will give greater roundness trajectories, and vice versa.

hcKalmanFilter.rValue = 35.0

4. After initialization and eventual correction of rValue parameter, after each next measurement of the coordinates from the GPS receiver, it is necessary to call processState function of the HCKalmanFilter object with current coordinates.

let kalmanLocation = hcKalmanFilter.processState(currentLocation: myCurrentLocation)
  • currentLocation is CLLocation object which represents the actual coordinates received from the GPS receiver.
  • kalmanLocation is CLLocation object which represents coordinates obtained by processing currentLocation with HCKalmanFilter algorithm. You can now use the corrected coordinates for further purposes (for example, to plot the path of the object you are tracking...)

5. In case you need to stop tracking and then restart it, it is necessary to call resetKalman function with new start location, before continuing with the processing of the measured coordinates.

hcKalmanFilter.resetKalman(newStartLocation: myNewStartLocation)
  • myNewStartLocation is CLLocation object which represents the actual coordinates received from the GPS receiver at the moment of restarting the algorithm.

After calling the restart function, you can continue to repeat the steps under the number 4.

Example of usage

var resetKalmanFilter: Bool = false
var hcKalmanFilter: HCKalmanAlgorithm?

...

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    var myLocation: CLLocation = locations.first!
    
    if hcKalmanFilter == nil {
       self.hcKalmanFilter = HCKalmanAlgorithm(initialLocation: myLocation)
    }
    else {
        if let hcKalmanFilter = self.hcKalmanFilter {
            if resetKalmanFilter == true {
                hcKalmanFilter.resetKalman(newStartLocation: myLocation)
                resetKalmanFilter = false
            }
            else {
                let kalmanLocation = hcKalmanFilter.processState(currentLocation: myLocation)
                print(kalmanLocation.coordinate)
            }
        }
    }
}

Credits

HCKalmanFilter is owned and maintained by the Hypercube.

If you find any bug, please report it, and we will try to fix it ASAP.

hckalmanfilter's People

Contributors

hypercubeoblak avatar hypercubesoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hckalmanfilter's Issues

Distortion of initial GPS points in a trip

Thanks for the good work! In my testing, this filter works well when driving at a consistent speed after the initial acceleration from zero to say 20 mph. However, when the trip starts and the car is still either stationary or moving at <5 mph, and the GPS signals are not extremely accurate/wavering, the filter seems to amplify the effect of the GPS location-points noise.

Use projected coordinates instead of lat/long

I'm not an expert in Kalman, but isn't the use of latitude/longitude going to make the algorithm performance vary depending on where you are on earth? And also the two different scales in x/y axis makes weird to define a R value related to that coordinate system?

Wouldn't it make much more sense to do it with projected coordinates (e.g. MKMapPoints) and supply the R value in meters and convert it to MKMapPoints based on the latitude?

return nan

When I was in the use of the library kalmanCLLocation. Coordinate the latitude is nan

kalmanFilter:244 LocationKalman->35.0-34.232407695251:nan,108.87790451196568:nan,401.8653869628906:nan

Speed Property lost

The speed property of the location gets lost after the filter process.
Is it possible to add it?

Performance when post-processing

Hello,
today I tried out your kalman filter and it looks pretty promising. The only issue I have is that even on my MacBook Pro post-processing like 2000 points takes about 5 seconds...
Do you have any plans on optimizing performance? From what I've seen in Instruments it's mainly the Matrix inverse and multiply functions as well as + and - (but far less)

Cheers,
Georg

`processState` return wrong location

processState is returning NaN values

let kalmanLocation = hcKalmanFilter.processState(currentLocation: location)
return kalmanLocation

having location = <+41.14267000,+1.40481000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 14/09/2017, 10:01:26 Central European Summer Time

returns: <nan,nan> +/- 0.00m (speed -1.00 mps / course -1.00) @ 14/09/2017, 10:01:29 Central European Summer Time

NaN latitude and longitude

Hello,

I have an issue with the filter. Sometimes, the algorithm returns a location with both latitude and longitude NaN:

(lldb) po location
<nan,nan> +/- 65.00m (speed -1.00 mps / course -1.00) @ 01/10/2018 18:07:54 UTC+02:00

Usually, everything works fine and locations are smoothed correctly, but in certain circumstances the output location is NaN.

In case this can help you: the issue occurs indoor, the GPS signal is low, the phone is not moving on a table and the app fetches location in background every second. The problem starts sometimes after 3 minutes, sometimes after 1+ hour. Feel free to ask me if you need further information.

Thank you!

Thomas

Use of kCLLocationAccuracyBestForNavigation

First of all, thanks very much for sharing this with the world. It works great an allows to smooth workout routes. However, I noticed the locations it creates uses kCLLocationAccuracyBestForNavigation for horizontal and vertical accuracy. That actually makes the location invalid since it has a value of -2 and Apple considers anything less than zero to be invalid. I changed it to the following:

let kalmanCLLocation = CLLocation(coordinate: CLLocationCoordinate2D(latitude: lat,longitude: lon), altitude: altitude, horizontalAccuracy: self.previousLocation.horizontalAccuracy, verticalAccuracy: self.previousLocation.verticalAccuracy, timestamp: previousMeasureTime)

I can't build it

I download the zip and pod install.
when i build it,Xcode reports Use of undeclared type 'HCKalmanAlgoorithm' in MapService.swift.
How can i resolve it?

1.2.2 version not pushed to CocoaPods master repo

Hey guys,

I hope you are doing well.

We discovered this awesome library and wanted to try it out. However, we noticed that you did not push 1.2.2 podspec version to the CocoaPods master repo:

https://github.com/CocoaPods/Specs/search?utf8=%E2%9C%93&q=HCKalmanFilter&type=

There is also no tagged release:
https://github.com/Hypercubesoft/HCKalmanFilter/releases (you should do it before pushing podspec), and probably update the readme :P

That is not a big problem, since it is just a patch version, but would be cool to always have the latest :)

thx and have a nice day.

Feature Request: Include elevation

This is a superb library for filtering raw location data, thanks for providing it.
For activity tracking not only latitude and longitude are relevant, but also the current elevation. It would be great if you'd filter and return that aswell.

README.md mistake?

At the request of the HCKalmanFilter library user, we decided that in addition to the correction values for latitude and latitude

longitude?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.