我正在尝试从 Apple Watch 3 (WatchOS 5.1) 获取 Core Motion 数据,但尽管 DeviceMotion 可用(isDeviceMotionAvailable
属性为 true
),但处理程序为从未触发。解析 super.willActivate()
后,我立即在控制台中收到以下消息:
[Gyro] Manually set gyro-interrupt-calibration to 800
我正在使用以下函数来获取设备运动更新:
func startQueuedUpdates() {
if motion.isDeviceMotionAvailable {
self.motion.deviceMotionUpdateInterval = 1.0 / 100.0
self.motion.showsDeviceMovementDisplay = true
self.motion.startDeviceMotionUpdates(using: .xMagneticNorthZVertical, to: self.queue, withHandler:{
(data, error) in
// Make sure the data is valid before accessing it.
if let validData = data {
print(String(validData.userAcceleration.x))
}
})
}
}
在 InterfaceController 中我声明了
let motion = CMMotionManager()
let queue : OperationQueue = OperationQueue.main
有人以前遇到过此消息并设法解决它吗?
注意:我检查了 isGyroAvailable
属性,它是 false
。
最佳答案
这里的技巧是匹配 startDeviceMotionUpdates(using: CMAttitudeReferenceFrame
您的设备功能的参数。如果它没有磁力计,则无法与磁北相关,即使它有磁力计,也无法与真北相关,除非它知道您所在的位置(即具有纬度和经度)。如果它没有能力符合您选择的参数,则会调用更新,但数据将为 nil
.
如果您以最小值 .xArbitraryZVertical
启动它您将会从加速度计获得更新,但是您不会通过 CMDeviceMotion.attitude
获得有意义的标题,而只是一个相对的标题。属性(property)...
if motion.isDeviceMotionAvailable {
print("Motion available")
print(motion.isGyroAvailable ? "Gyro available" : "Gyro NOT available")
print(motion.isAccelerometerAvailable ? "Accel available" : "Accel NOT available")
print(motion.isMagnetometerAvailable ? "Mag available" : "Mag NOT available")
motion.deviceMotionUpdateInterval = 1.0 / 60.0
motion.showsDeviceMovementDisplay = true
motion.startDeviceMotionUpdates(using: .xArbitraryZVertical) // *******
// Configure a timer to fetch the motion data.
self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
if let data = self.motion.deviceMotion {
print(data.attitude.yaw)
}
}
}
关于gyroscope - 无法使用 watchOS 5 获取核心运动更新 : "[Gyro] Manually set gyro-interrupt-calibration to 800",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54748841/