Skip to content

Commit

Permalink
- Upgraded the matrix processing functions in HCMatrixObject class wh…
Browse files Browse the repository at this point in the history
…ich now use core functions of the Surge Library

- small Compile Sources bug fix
- small Location Accuracy bug in main kalmanFilter function fixed
- Podspec and README.md file updated
  • Loading branch information
hypercubeOblak committed Jan 24, 2018
1 parent bd77222 commit b9b032e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
4589712C201883FB00030DEE /* HCMatrixObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5B6E33F1F714DD600992EC9 /* HCMatrixObject.swift */; };
4589712D201883FE00030DEE /* HCKalmanAlgorithm.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5B6E33E1F714DD600992EC9 /* HCKalmanAlgorithm.swift */; };
A5D3597C1F713FD200B436D5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5B6E3311F713EE700992EC9 /* AppDelegate.swift */; };
A5D3597D1F713FD400B436D5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A5B6E3321F713EE700992EC9 /* Assets.xcassets */; };
A5D3597E1F713FDA00B436D5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A5B6E3331F713EE700992EC9 /* LaunchScreen.storyboard */; };
Expand Down Expand Up @@ -268,8 +270,10 @@
files = (
A5D359861F71409C00B436D5 /* ViewController.swift in Sources */,
A5D359821F713FE500B436D5 /* MapService.swift in Sources */,
4589712D201883FE00030DEE /* HCKalmanAlgorithm.swift in Sources */,
A5D3597C1F713FD200B436D5 /* AppDelegate.swift in Sources */,
A5D359831F713FE900B436D5 /* AppNotify.swift in Sources */,
4589712C201883FB00030DEE /* HCMatrixObject.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 3 additions & 1 deletion HCKalmanFilter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pod::Spec.new do |s|

s.platform = :ios
s.name = "HCKalmanFilter"
s.version = "1.1.0"
s.version = "1.2.0"
s.summary = "HCKalmanFilter is Swift implementation of Kalman filter algorithm intended to solve problem with GPS tracking"

s.description = <<-DESC
Expand All @@ -17,4 +17,6 @@ s.source = { :git => "https://github.com/Hypercubesoft/HCKalmanFilter.
s.ios.deployment_target = "9.0"
s.source_files = "HCKalmanFilter/*"

s.dependency 'Surge', '~> 2.0.0'

end
34 changes: 18 additions & 16 deletions HCKalmanFilter/HCKalmanAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import MapKit
import Surge

open class HCKalmanAlgorithm
{
Expand All @@ -22,7 +23,7 @@ open class HCKalmanAlgorithm
/// Acceleration variance magnitude for GPS
/// =======================================
/// **Sigma** value is value for Acceleration Noise Magnitude Matrix (Qt).
/// Recommended value for **sigma** is 0.0625, this value is optimal for GPS problem,
/// Recommended value for **sigma** is 0.0625, this value is optimal for GPS problem,
/// it was concluded by researches.
private let sigma = 0.0625

Expand Down Expand Up @@ -69,7 +70,7 @@ open class HCKalmanAlgorithm
/// Acceleration Noise Magnitude Matrix
/// ===================================
/// **Acceleration Noise Magnitude Matrix (Qt)** is mathematical representation of external uncertainty of Kalman Algorithm.
/// The uncertainty associated can be represented with the “world” (i.e. things we aren’t keeping track of)
/// The uncertainty associated can be represented with the “world” (i.e. things we aren’t keeping track of)
/// by adding some new uncertainty after every prediction step.
private var Qt:HCMatrixObject

Expand All @@ -79,7 +80,7 @@ open class HCKalmanAlgorithm
/// **Sensor Noise Covariance Matrix (R)** is mathematical representation of sensor noise of Kalman Algorithm.
/// Sensors are unreliable, and every state in our original estimate might result in a range of sensor readings.
private var R:HCMatrixObject

/// Measured State Vector
/// =====================
/// **Measured State Vector (zt)** is mathematical representation of measuerd state vector of Kalman Algorithm.
Expand All @@ -93,26 +94,26 @@ open class HCKalmanAlgorithm

/// Previous State Location
private var previousLocation = CLLocation()


//MARK: - HCKalmanAlgorithm initialization

/// Initialization of Kalman Algorithm Constructor
/// ==============================================
/// - parameters:
/// - initialLocation: this is CLLocation object which represent initial location
/// - initialLocation: this is CLLocation object which represent initial location
/// at the moment when algorithm start
public init(initialLocation: CLLocation)
{
self.previousMeasureTime = Date()
self.previousLocation = CLLocation()

self.xk1 = HCMatrixObject(n: stateMDimension, m: stateNDimension)
self.Pk1 = HCMatrixObject(n: stateMDimension, m: stateMDimension)
self.A = HCMatrixObject(n: stateMDimension, m: stateMDimension)
self.Qt = HCMatrixObject(n: stateMDimension, m: stateMDimension)
self.R = HCMatrixObject(n: stateMDimension, m: stateMDimension)
self.zt = HCMatrixObject(n: stateMDimension, m: stateNDimension)
self.xk1 = HCMatrixObject(rows: stateMDimension, columns: stateNDimension)
self.Pk1 = HCMatrixObject(rows: stateMDimension, columns: stateMDimension)
self.A = HCMatrixObject(rows: stateMDimension, columns: stateMDimension)
self.Qt = HCMatrixObject(rows: stateMDimension, columns: stateMDimension)
self.R = HCMatrixObject(rows: stateMDimension, columns: stateMDimension)
self.zt = HCMatrixObject(rows: stateMDimension, columns: stateNDimension)

initKalman(initialLocation: initialLocation)
}
Expand Down Expand Up @@ -163,7 +164,7 @@ open class HCKalmanAlgorithm
/// This function is a main. **processState** will be processed current location of user by Kalman Filter
/// based on previous state and other parameters, and it returns corrected location
/// - parameters:
/// - currentLocation: this is CLLocation object which represent current location returned by GPS.
/// - currentLocation: this is CLLocation object which represent current location returned by GPS.
/// **currentLocation** is real position of user, and it will be processed by Kalman Filter.
/// - returns: CLLocation object with corrected latitude, longitude and altitude values

Expand Down Expand Up @@ -226,6 +227,7 @@ open class HCKalmanAlgorithm
let Pk = ((A*Pk1)!*A.transpose()!)! + Qt

let tmp = Pk!+R

// Kalman gain (Kt)
let Kt = Pk!*(tmp?.inverseMatrix())!

Expand All @@ -235,11 +237,11 @@ open class HCKalmanAlgorithm
self.xk1 = xt!
self.Pk1 = Pt!

let lat = xk1.matrix[0][0]
let lon = xk1.matrix[2][0]
let altitude = xk1.matrix[4][0]
let lat = xk1.matrix[0,0]
let lon = xk1.matrix[2,0]
let altitude = xk1.matrix[4,0]

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

return kalmanCLLocation
}
Expand Down
Loading

0 comments on commit b9b032e

Please sign in to comment.