gyroscope - 无法使用 watchOS 5 获取核心运动更新 : "[Gyro] Manually set gyro-interrupt-calibration to 800"

标签 gyroscope core-motion watchos-5

我正在尝试从 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/

相关文章:

ios - 获取 iPhone 旋转和方向以实时旋转 3D 对象

iphone - CMAttitude 和 CATransform3D 是否与旋转矩阵相关?

swift - 如何在 watch 充电时保持 Apple Watch 应用程序运行

swift - iOS WatchOS5 - 如何以编程方式检测 Apple Watch 是否在特定时间间隔戴在手腕上?

ios - 使用CMDeviceMotion获取绝对旋转?

iphone - iOS - 快门触发时捕获数据

java - 计算纵跳腾空时间

ios - 反转 CMRotationMatrix 的一个单轴的旋转

swift - 尝试启动 HKLiveWorkout 时总是意外地发现 session 为零