iPhone 中加速度计的最大采样率

发布于 2024-11-27 20:39:53 字数 138 浏览 9 评论 0原文

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

那么任何人都可以告诉我我们可以获得的最大更新率是多少或者我如何获得高更新率。

Does anybody know that what is the maximum sampling rate of the iphone accelerometer.
I want to have have high update rate. i set it to updateInterval to 1.0/ 300.0
But it seems that i am not getting that much update rate.

So can any body tell me that what is the maximum update rate that we can get or how i can get the high update rate.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮年 2024-12-04 20:39:53

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]);
          }

       }
    }];
}

The max accelerometer and gyroscope sampling rate on the iPhone 6 is 100Hz. You can empirically test this yourself. Here is the code.

/******************************************************************************/
// 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]);
          }

       }
    }];
}
作业与我同在 2024-12-04 20:39:53

尽管文档说您可以请求更新的最大频率取决于硬件,但通常至少为 100 Hz。在我看来,最大采样率仍然是 100Hz

我的解决方法是采用名为 MotionGraphs 的 CoreMotion 现有示例代码,并将 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) code> 为良好措施(如果它是全球汇率)。

有了加速计和陀螺仪的代码,我确认运行 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

Despite the documentation saying The maximum frequency at which you can request updates is hardware-dependent but is usually at least 100 Hz. it looks to me like the maximum sample rate is still 100Hz.

My approach to figure out was taking the existing sample code for CoreMotion called MotionGraphs and adapting the startUpdates function to look like this:

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()
        }
    }
}

I also set motionManager.deviceMotionUpdateInterval = TimeInterval(1.0/100000.0) for good measure (in case it is a global rate).

With that code in place for both Accelerometer and Gyroscope I confirm that an iPhone 8 on iOS 11.4 still maxes out right around 100Hz for both.

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
岁月染过的梦 2024-12-04 20:39:53

也许重复。查看

为 deviceMotionUpdateInterval 设置的更新频率,它是实际频率吗?

<一个href="https://stackoverflow.com/questions/5034411/actual-Frequency-of-device-motion-updates-lower-than-expected-but-scales-up-with">设备运动更新的实际频率低于预期的,但会随着设置而扩大

如果使用旧的 UIAccerometerDelegate 接口,同样应该有效。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文