CMDeviceMotion返回磁场的0值 [英] CMDeviceMotion returns 0 values for magnetic field

查看:357
本文介绍了CMDeviceMotion返回磁场的0值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发具有罗盘功能的iOS应用程序。我曾尝试使用 CMMagnetometerData 更新,这些更新会产生未校准但正常的结果。

I am developing iOS app with compass functionality. I have tried to use CMMagnetometerData updates which give uncalibrated, but normal results.

之后我试图获得 CMDeviceMotion 更新,结果总是给出零磁场 CMMagneticFieldCalibrationAccuracyUncalibrated 准确性。我唯一的设备是iPad,因此无法测试其他设备。

After that I tried to get CMDeviceMotion updates which turned out to give always zero magnetic field with CMMagneticFieldCalibrationAccuracyUncalibrated accuracy. The only device I have is an iPad, so can't test on others.

由于传感器未校准,但可能是场为零,但我找不到任何方法进行校准。

May be field is zero because sensor is not calibrated, but I could not find any way to perform calibration.

如何解决这个问题?

更新:

这里使用 startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:,但它对我不起作用。

Here is suggested to use startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:, however it didn't work for me.

这里建议将 showsDeviceMovementDisplay 设置为 true 。然而它也没有用,校准窗口就不会弹出。

Here is suggested to set showsDeviceMovementDisplay to true. However it didn't work either, calibration windows is just not popping up.

最后,已解决。根据我的观察:

Finally, SOLVED. According to my observations:

1)使用 startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler: with referenceFrame 不等于 allZeros XArbitraryZVertical

1) Use startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler: with referenceFrame NOT equal to allZeros or XArbitraryZVertical.

2)将 showsDeviceMovementDisplay 设置为 true

经过几次零值更新,精确度 CMMagneticFieldCalibrationAccuracyUncalibrated 它会正常化。

After few zero-value updates with accuracy CMMagneticFieldCalibrationAccuracyUncalibrated it will normalise.

代码:

...
motionManager.deviceMotionUpdateInterval = 0.05
motionManager.showsDeviceMovementDisplay = true 
motionManager.startDeviceMotionUpdatesUsingReferenceFrame(CMAttitudeReferenceFrame.XArbitraryCorrectedZVertical, toQueue: NSOperationQueue.mainQueue(), withHandler:handleUpdate)
...
private func handleUpdate(data: CMDeviceMotion!, error: NSError!) {
    if data != nil {
        let field = data.magneticField.field
        println("\(field.x), \(field.y), \(field.z)")
    }
}


推荐答案

最后,根据我自己的观察:

Finally, according to my own observations:

1)使用 startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler: with referenceFrame 不等于 allZeros XArbitraryZVertical

1) Use startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:with referenceFrame NOT equal to allZeros or XArbitraryZVertical.

2)设置 showsDeviceMovementDisplay true

经过几次零值更新,准确度 CMMagneticFieldCalibrationAccuracyUncalibrated 它会正常化。

After few zero-value updates with accuracy CMMagneticFieldCalibrationAccuracyUncalibrated it will normalise.

这篇关于CMDeviceMotion返回磁场的0值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆