gpt4 book ai didi

ios - CMDeviceMotion 为磁场返回 0 值

转载 作者:搜寻专家 更新时间:2023-10-30 22:30:03 32 4
gpt4 key购买 nike

我正在开发具有罗盘功能的 iOS 应用程序。我尝试使用 CMMagnetometerData 更新,它给出了未校准但正常的结果。

之后,我尝试获取 CMDeviceMotion 更新,结果始终提供零磁场,并且具有 CMMagneticFieldCalibrationAccuracyUncalibrated 精度。我唯一的设备是 iPad,因此无法在其他设备上进行测试。

可能是字段为零,因为传感器未校准,但我找不到任何方法来执行校准。

如何解决?

更新:

Here建议使用 startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:,但它对我不起作用。

Here建议将 showsDeviceMovementDisplay 设置为 true。但是它也没有用,只是没有弹出校准窗口。

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

1) 使用 startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:referenceFrame 不等于 allZerosXArbitraryZVertical

2) 将 showsDeviceMovementDisplay 设置为 true

在几次以 CMMagneticFieldCalibrationAccuracyUncalibrated 精度进行零值更新后,它将归一化。

代码:

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

最佳答案

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

1) 使用 startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:referenceFrame 不等于 allZerosXArbitraryZVertical

2) 将 showsDeviceMovementDisplay 设置为 true

在几次以 CMMagneticFieldCalibrationAccuracyUncalibrated 精度进行零值更新后,它将归一化。

关于ios - CMDeviceMotion 为磁场返回 0 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30840844/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com