iPhone加速度计的最大采样率

3

有没有人知道iPhone加速度计的最大采样率是多少。 我想要高更新率。我将其设置为updateInterval为1.0 / 300.0 但似乎我没有得到那么高的更新率。

所以有人能告诉我我们可以获得的最大更新率是多少,或者如何获得高更新率吗。


我非常确定,如果你使用 DeviceMotionUpdateInterval(1.0/200.0); 并使用 motionManager.startDeviceMotionUpdates() 进行轮询,并使用 motionManager.deviceMotion.gravity 获取加速度,则速率将增加到 200 次/秒(在我的 iPhone SE 上测试有效)。 - micsthepick
3个回答

3

iPhone 6的加速度计和陀螺仪的最大采样率为100Hz。您可以通过实验来测试这一点。以下是代码。

/******************************************************************************/
// First create and initialize two NSMutableArrays. One for accel data and one
// for gyro data. Then create and initialize CMMotionManager.  Finally,
// call this function

- (void) TestRawSensors
{
   speedTest = 0.0001; // Lets try 10,000Hz
   motionManager.accelerometerUpdateInterval = speedTest;
   motionManager.gyroUpdateInterval = speedTest;


    [motionManager startAccelerometerUpdatesToQueue: [NSOperationQueue currentQueue]
    withHandler: ^(CMAccelerometerData  *accelerometerData, NSError *error)
    {
       [rawAccelSpeedTest addObject: [NSNumber numberWithDouble: accelerometerData.timestamp]];
       [rawAccelSpeedTest addObject: [NSNumber numberWithDouble: accelerometerData.acceleration.x]];

       if (error)
       {
          NSLog(@"%@", error);
       }

       if (rawAccelSpeedTest.count > 100)
       {
          [motionManager stopAccelerometerUpdates];

          for (uint16_t i = 0; i < rawAccelSpeedTest.count; i+=2)
          {
             NSLog(@"Time: %f   Accel: %f", [rawAccelSpeedTest[i] doubleValue],
                                            [rawAccelSpeedTest[i+1] doubleValue]);
          }
       }
    }];


   [motionManager startGyroUpdatesToQueue: [NSOperationQueue currentQueue]
                              withHandler: ^(CMGyroData *gyroData, NSError *error)
    {
       [rawGryoSpeedTest addObject: [NSNumber numberWithDouble: gyroData.timestamp]];
       [rawGryoSpeedTest addObject: [NSNumber numberWithDouble: gyroData.rotationRate.x]];

       if (error)
       {
          NSLog(@"%@", error);
       }

       if (rawGryoSpeedTest.count > 100)
       {
          [motionManager stopGyroUpdates];

          for (uint16_t i = 0; i < rawGryoSpeedTest.count; i+=2)
          {
             NSLog(@"Time: %f   Rate: %f", [rawGryoSpeedTest[i] doubleValue],
                                           [rawGryoSpeedTest[i+1] doubleValue]);
          }

       }
    }];
}

请您能否详细说明一下?我已经得到了原始数据,但是应该如何解释它呢?另外,标准差怎么处理?谢谢! - Can

3
尽管文档中说“您可以请求更新的最大频率取决于硬件,但通常至少为100 Hz。”,但在我看来,最大采样率仍然为100Hz。
我的解决方法是使用现有的CoreMotion示例代码MotionGraphs,并将startUpdates函数调整为以下内容:
func startUpdates() {
    guard let motionManager = motionManager, motionManager.isGyroAvailable else { return }

    sampleCount = 0
    let methodStart = Date()

    motionManager.gyroUpdateInterval = TimeInterval(1.0/100000.0) // Hardcoded to something verfy fast
    motionManager.startGyroUpdates(to: .main) { gyroData, error in
        self.sampleCount += 1
        //...view update code removed
        if (self.sampleCount >= 100) {
            let methodFinish = Date()
            let executionTime = methodFinish.timeIntervalSince(methodStart)
            print("Duration of 100 Gyro samples: \(executionTime)")
            self.stopUpdates()
        }
    }
}

我还设置了motionManager.deviceMotionUpdateInterval = TimeInterval(1.0/100000.0)(以防万一它是全局速率)。

当加速度计和陀螺仪都使用该代码后,我确认在iOS 11.4上,iPhone 8的最大频率仍然约为100Hz。

Duration of 100 Accelerometer samples: 0.993090987205505
Duration of 100 Accelerometer samples: 0.995925068855286
Duration of 100 Accelerometer samples: 0.993505954742432
Duration of 100 Accelerometer samples: 0.996459007263184
Duration of 100 Accelerometer samples: 0.996203064918518

Duration of 100 Gyro samples: 0.989820957183838
Duration of 100 Gyro samples: 0.985687971115112
Duration of 100 Gyro samples: 0.989449977874756
Duration of 100 Gyro samples: 0.988754034042358

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接