2

我正在尝试从 Apple Watch 3(WatchOS 5.1)获取 Core Motion 数据,但尽管 DeviceMotion 可用(isDeviceMotionAvailable属性为true),但从未触发处理程序。解析后立即在控制台中收到以下消息super.willActivate()

[Gyro] 手动设置 gyro-interrupt-calibration 为 800

我正在使用以下函数来获取 Device Motion 更新:

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.

4

1 回答 1

2

这里的技巧是将startDeviceMotionUpdates(using: CMAttitudeReferenceFrame参数与设备的功能相匹配。如果它没有磁力计,它就不能与磁北相关,即使它有磁力计,它也不能与真北相关,除非它知道你在哪里(即有纬度和经度)。如果它没有符合您选择的参数的能力,则会调用更新,但数据将是nil.

如果您以最小值启动它,.xArbitraryZVertical将从加速度计获得更新,但您不会通过CMDeviceMotion.attitude属性获得有意义的标题,只是一个相对的标题......

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)
        }
    }
}
于 2019-06-18T11:56:25.053 回答