2

I am testing Core Motion and using the gyroscope. Right now I am getting values that I am not understanding. My assumption was that with each x, y and z I would get a value between 0-360 which would be a full rotation, but this isn't the case.

[self.motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMGyroData *gyroData, NSError *error) {
     NSString *x = [NSString stringWithFormat:@"%.02f",gyroData.rotationRate.x];
     NSLog(@"X: %@", x);

     NSString *y = [NSString stringWithFormat:@"%.02f",gyroData.rotationRate.y];
     NSLog(@"Y: %@", y);

     NSString *z = [NSString stringWithFormat:@"%.02f",gyroData.rotationRate.z];
     NSLog(@"Z: %@", z);

    frequency = gyroData.rotationRate.y*500;

    float rate = gyroData.rotationRate.z;
    if (fabs(rate) > .2) {
        float direction = rate > 0 ? 1 : -1;
        rotation += (direction * M_PI/90.0)*1000;
        NSLog(@"Rotation: %f", rotation);
    }

 }];

It is possible to get more human readable rotation values? Is my assumption that I should be getting values between 0-360 wrong?

Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412

1 Answers1

4

The values are in radians, not degrees, so they should be between 0 and 2Pi. Also, they are a rate, not an angle. They are radians per second.

user1118321
  • 25,567
  • 4
  • 55
  • 86
  • Ok. So does the device know the number of times I have rotated it? – Nic Hubbard Jan 05 '12 at 05:17
  • I don't think so. It just gives you the angular rate that it's turning at (say Pi / 3 radians per second). Your application would need to track that over time to determine how many times it's been rotated. – user1118321 Jan 05 '12 at 05:20
  • Ok, so how do I know what angle the phone is at? Isn't that what the gyroscope can be used for? Such as apps that have a level or games the roll a ball? – Nic Hubbard Jan 05 '12 at 05:30
  • Check out [this answer](http://stackoverflow.com/questions/5053793/iphone-core-motion-relative-rotation). – user1118321 Jan 05 '12 at 06:25