0
votes

I am creating test app that receives gyroscope pitch, roll and yaw.

This code does not work as I would think it would:

- (void) enableGyro {
    motionManager.deviceMotionUpdateInterval = 1.0/30.0;
    if (motionManager.gyroAvailable) {
        [motionManager startGyroUpdates];
    }
    NSLog(@"Gyro Available? %@", (motionManager.gyroAvailable ? @"YES" : @"NO"));
    NSLog(@"Gyro Active? %@", (motionManager.gyroActive ? @"YES" : @"NO"));
}

The output of that is

2011-09-29 16:37:08.070 Gyro2[4014:607] Gyro Available? YES
2011-09-29 16:37:08.074 Gyro2[4014:607] Gyro Active? NO

I don't understand why, when I begin the gyro updates, it does not actually start.

2
Sorry guys, i am not sure what the problem was but I just rewrote the test project and it worked. I based it off the code from this website: cs491f10.wordpress.com/2010/10/28/core-motion-gyroscope-exampleSamB

2 Answers

0
votes

If you really want to use raw unbiased sensor data, you have to set the update interval of every sensor independently although they often will be the same value:

motionManager.gyroUpdateInterval = myGyroInterval;
motionManager.accelerometerUpdateInterval = myAccelerometerInterval;

The deviceMotionUpdateInterval is bound to device motions only.

Most people don't want to handle sensor data processing with Kalman filter etc. but just the current orientation of the device. If that's the case, have a look at Simple iPhone motion detect.

The only situation when I saw the values of CMMotionManager's xxxActive methods did not report the correct state was putting the app in background and activating it again when motion handling is done within an own NSThread. I think this related to some actions done by the operating system maybe combined with kind of racing condition. The trick then is to release CMMotionManager instance and allocate a new one.

0
votes

According to documentation (http://developer.apple.com/library/ios/#DOCUMENTATION/CoreMotion/Reference/CMMotionManager_Class/Reference/Reference.html), gyroActive will only be true if you've called startGyroUpdatesToQueue:withHandler: or startGyroUpdates. Even though startDeviceMotionUpdates uses the gyroscope, it doesn't set gyroActive.