CMMotionManager中的不规则时间戳

过去一周对此进行了大量研究,但未找到类似的问题。 我正在Apple Watch上收集加速度计数据,并查看DeviceMotion类输出的时间戳,这是一个问题。 时间戳并不总是按时间顺序排列。 例如,如果我以100Hz收集几分钟的运动数据,我会从我在同一个应用程序中生成的CSV文件中获取以下时间戳(这些是UTC时间戳):

1531099702.768570 1531099702.778460 1531099702.788380 1531099702.798270 1531099702.738870 1531099702.748780 1531099702.758670 1531099702.768590 

如果你注意到,在第5个时间戳,与第4个时间相比,时间已经大幅回升。

有谁知道这会导致什么? 谢谢!

这是我的代码:

 func startUpdates() { motionManager = CMMotionManager() if motionManager.isDeviceMotionAvailable { self.motionManager.deviceMotionUpdateInterval = updateInterval self.motionManager.showsDeviceMovementDisplay = true self.motionManager.startDeviceMotionUpdates(using: .xArbitraryZVertical, to: .main, withHandler: { (data, error) in // Make sure the data is valid before accessing it. if let validData = data { // find boot time of device to normalize timestamps if (self.accArray.isEmpty) { self.bootTime = Date(timeIntervalSinceNow:-validData.timestamp) } self.accArray.append([validData.timestamp + self.bootTime.timeIntervalSince1970, validData.attitude.pitch, validData.attitude.roll, validData.attitude.yaw, validData.userAcceleration.x, validData.userAcceleration.y, validData.userAcceleration.z, validData.rotationRate.x, validData.rotationRate.y, validData.rotationRate.z, validData.gravity.x, validData.gravity.y, validData.gravity.z]) if (self.accArray.count == 100) { let accChunk = NSKeyedArchiver.archivedData(withRootObject: self.accArray) watchSessionManager.sharedManager.sendMessageData(accChunk: accChunk) self.reset() } } }) } } 

来自accArray的所有数据都插入到CSV文件中,该文件以下列方式生成:

 // Create CSV with collected array func createCSV() -> String { if(self.accArray.count == 0) { return("No data captured") } else { // Create CSV structure var csvText = "Number,Pitch,Roll,Yaw,RotX,RotY,RotZ,GravX,GravY,GravZ,AccX,AccY,AccZ,Time\n" for index in 0...accArray.count-1 { let newLine = [String(index), String(accArray[index][1]), String(accArray[index][2]), String(accArray[index][3]), String(accArray[index][4]), String(accArray[index][5]), String(accArray[index][6]), String(accArray[index][7]), String(accArray[index][8]), String(accArray[index][9]), String(accArray[index][10]), String(accArray[index][11]), String(accArray[index][12]), String(accArray[index][0])].joined(separator: ",") // Insert data into CSV file csvText.append(newLine + "\n") } self.reset() return(csvText) } }