我正在尝试制作一个以给定间隔收集加速度计和陀螺仪更新的应用程序。加速度计和陀螺仪的间隔相同,因此我希望两者的数据对齐。然而,使用 CMMotionManger,加速度计和陀螺仪数据不会在给定的时间间隔内完美更新(我希望每秒更新 20 次,范围为 15-20),并且加速度计点和陀螺仪点的数量不一致,尽管它们具有相同的更新间隔。这是我开始数据收集的代码:
- (void)startDataCollect {
CMMotionManager *motionManager = [MainViewController sharedCMMotionManager];
motionManager.accelerometerUpdateInterval = 1.0/20.0;
motionManager.gyroUpdateInterval = 1.0/20.0;
acc_data = [[NSMutableArray alloc] init];
gyro_data = [[NSMutableArray alloc] init];
time_stamp = [[NSMutableArray alloc] init];
[motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
[self recordAccelerometer:accelerometerData.acceleration];
}];
[motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMGyroData *gyroData, NSError *error) {
[self recordGyroscope:gyroData.rotationRate];
}];
}
处理程序方法只是将数据放入存储数据的数组中,直到将其写入文件。上次测试应用程序时,我得到了 240 个加速度计数据点和 366 个陀螺仪数据点。如果间隔相同,为什么收集点的数量会有很大差异?为什么每秒的数据点数与提供的时间间隔不一致?