CoreMotionActivityManager返回汽车或汽车+固定真

时间:2017-08-09 15:22:33

标签: ios core-location core-motion

我正在尝试检测Automotive ActivtyType,但问题是如果“我继续驾驶然后停车并停留在车内”并简单检查coreMotion日志:我会继续获得众多

的混合回调
high Confidence: Automotive: True, Stationary: True 

high confidence: Automotive: True, Stationary: False

low confidence: Automotive: True, Stationary: True
  

我没有得到唯一的固定式:真的,它总是带有汽车   同样是真的

他们的表现方式并不多,或者至少我找不到模式。

问:有没有人找到一种可靠的方法来检测汽车何时是真正的汽车?

我已经尝试计算我得到的回调数,然后进行一些计算,但这似乎不可靠。

FWIW当用户离开汽车的那一刻然后我得到一个步行或静止(没有汽车......这是好的)回调并使用那些回调将标志设置为真...所以在那之后如果我得到任何automotive回调......然后我知道这是一个真正的汽车......

我的代码:

func beginMotionTracking(){

    let motionLog = OSLog(subsystem: "Spike", category: "Motion")

    shouldUseTimer = false
    motionActivityManager = CMMotionActivityManager()
    var totalWalking = 0
    var totalAutomotive = 0
    var totalStationary = 0
    var totalFalseAutomotive = 0

    motionActivityManager?.startActivityUpdates(to: OperationQueue.main){
        [weak self] activity in

        os_log("Motion is Tracking | desiredAccuracy is %{public}f | RemainingTime : %{public}f ",log: motionLog, type: .default, (self?.locationManager.desiredAccuracy)! , UIApplication.shared.remainingTime())

        if activity?.walking == true && (activity?.confidence == .medium || activity?.confidence == .high) && activity?.automotive == false && activity?.stationary == false && activity?.unknown == false {
            totalWalking += 1

            os_log("medium and high conf: walking %{public}d time", log: motionLog, type: .error, totalWalking)

        }else if activity?.stationary == true && (activity?.confidence == .medium || activity?.confidence == .high) && activity?.automotive == false && activity?.walking == false && activity?.unknown == false {
            totalStationary += 1

            os_log("medium and high conf: stationary %{public}d time", log: motionLog, type: .error, totalStationary)

            // false automotive
        }else if activity?.automotive == true && activity?.stationary == true && (activity?.confidence == .high) && activity?.walking == false  && activity?.unknown == false {
            totalFalseAutomotive += 1
            os_log("high conf: FALSE Automotive %{public}d time", log: motionLog, type: .error, totalFalseAutomotive)


            if totalFalseAutomotive > 2{
                totalFalseAutomotive = 0
                totalAutomotive = 0
                totalStationary = 0
                totalWalking = 0

                os_log("Too many FALSE automotives, REST all counts back to 0", log: motionLog, type: .fault)
            }
        }
        else if activity?.automotive == true && (activity?.confidence == .high) && activity?.walking == false && activity?.stationary == false && activity?.unknown == false {
            totalAutomotive += 1
            os_log("high conf: Automotive %{public}d time", log: motionLog, type: .error, totalAutomotive)

            if ((totalWalking > 3 && totalAutomotive > 2) || (totalStationary > 3 && totalAutomotive > 2) || (totalAutomotive > 7)){
                self?.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters

                os_log("Motion is Automotive and is about to be stopped: desired AccuracyChanged to HundredMeters | RemainingTime : %{public}f ", log: motionLog, type: .fault, UIApplication.shared.remainingTime())

                self?.shouldUseTimer = true
                self?.motionActivityManager?.stopActivityUpdates()
            }
        }
    }
}

我正在经历所有这些麻烦,因为我试图降低我的核心位置准确度,只要用户没有开车超过3分钟,然后再使用核心动作来检测automotive运动并使用它将位置精度放回到百米。

0 个答案:

没有答案