HCKalmanFilter 1.2.1

HCKalmanFilter 1.2.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2018年1月
SwiftSwift 版本3.1
SPM支持 SPM

Hypercubesoft 维护。



  • Hypercubesoft

logo

HCKalmanFilter 是一个用 Swift 编写的适用于 iOS 的令人愉悦的库。HCKalmanFilter 库是为了实现 Kalman 过滤器算法以解决基于 GPS 接收器测量的轨迹 GPS 跟踪和校正问题而创建的。当一个接收到来自 GPS 接收器的坐标的幅度很大而且精度非常小或 GPS 信号非常差时,会出现这个问题。如果您遇到这种问题并且需要一个没有大的峰值和偏差的平滑轨迹,这个库是您的最佳选择。

screenshot

screenshot

入门

安装

CocoaPods 是 Objective-C 和 Swift 的依赖项管理器,它使使用第三方库(如 HCKalmanFilter)的过程自动化和简化。

Podfile

要在 CocoaPods 中将 HCKalmanFilter 集成到您的 Xcode 项目中,请在 Podfile 中指定它

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

然后,运行以下命令

$ pod install

包含源代码

下载仓库,然后将 HCKalmanAlgorithm 目录添加到您的项目中。

使用

1. 首先导入 HCKalmanFilter 模块

import HCKalmanFilter

2. 在安装和导入 Kalman Filter 库后,在使用它之前需要初始化 HCKalmanFilter 对象。

let hcKalmanFilter = HCKalmanAlgorithm(initialLocation: myInitialLocation)
  • myInitialLocation 是跟踪开始的地点。

3. 如果有必要,可以修改 rValue 参数的值。 rValue 参数是传感器噪声协方差矩阵的值。默认值是 29.0,这是 GPS 问题的推荐值,此值可获得最佳的滤波精度。这个值可以根据需要进行调整,rValue 变量的值越高,轨迹的平滑度越大,反之亦然。

hcKalmanFilter.rValue = 35.0

4. 在初始化和必要时修改 rValue 参数后,在每个从 GPS 接收器得到的下一个坐标测量后,需要使用当前坐标调用 HCKalmanFilter 对象的 processState 函数。

let kalmanLocation = hcKalmanFilter.processState(currentLocation: myCurrentLocation)
  • currentLocation 是一个 CLLocation 对象,代表了从 GPS 接收器接收到的实际坐标。
  • kalmanLocation 是一个 CLLocation 对象,代表了通过使用 HCKalmanFilter 算法处理 currentLocation 所得到的坐标。您现在可以使用这些修正后的坐标进行其他操作(例如,绘制您正在追踪的对象路径...)。

5. 如果您需要停止跟踪然后重启,在继续处理测量坐标之前,必须使用新的起始位置调用 resetKalman 函数。

hcKalmanFilter.resetKalman(newStartLocation: myNewStartLocation)
  • myNewStartLocation 是一个 CLLocation 对象,代表了在重启算法时从 GPS 接收器接收到的实际坐标。

在调用重启函数后,您可以继续 重复第 4 项下的步骤

使用示例

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)
            }
        }
    }
}

致谢

HCKalmanFilterHypercube 所有并维护。

如果您发现任何错误,请报告它,我们会尽快修复。