15

I have a very simple application where I am trying to use the gyroscope thru core motion.

At this point, for test purposes, I am just grabbing the values of roll, pitch and yaw and printing on screen. According to the picture below and as far as I know, roll, pitch and yaw correspond to the red, green and blue axis, right?

OK. When I put the iphone on a table resting on its left side (home button on the right), perfectly at 90 degrees in relation to the table plane, these are the values I read for roll, pitch and yaw: -90, 0, 0. Then I start to rotate the iPhone according to the table's vertical axis in an anti-clockwise fashion, that would be on the positive direction according to the table vertical axis. On the iPhone, that would mean a pitch rotation, but as I rotate, pitch remains constant and YAW is the one that changes!!!!!

If the iPhone is resting on its left side on the table, the green axis (pitch) is vertical. If I am rotating the device anti-clockwise (positive) on X, I should see an increase on the pitch angle, not yaw.

The only explanation I have for this is, the gyroscope axis don't rotate when you rotate the device. So, if I am using the default attitude reference, the iPhone considers that the face up resting position is the default and the blue axis (yaw) will always be the vertical one. Is this correct?

This is the code I am using...

on the main code

motionManager = [[CMMotionManager alloc] init];
motionManager.deviceMotionUpdateInterval = 1.0/60.0; //60 Hz
[motionManager startDeviceMotionUpdates];


timer = [[NSTimer scheduledTimerWithTimeInterval:(1.0/60.0) 
          target:self
    selector:@selector( readIt )
userInfo:nil
 repeats:YES]
 retain];

the remaining code

#define degrees(x) (180.0 * x / M_PI)

- (void) readIt {

//  CMAttitude *referenceAttitude;
    CMAttitude *attitude;

    CMDeviceMotion *motion = motionManager.deviceMotion;        
    if (!motion) {
        return;
    }

    attitude = motion.attitude;

    NSLog(@"roll = %f... pitch = %f ... yaw = %f", degrees(attitude.roll), degrees(attitude.pitch), degrees(attitude.yaw));


}

enter image description here

Roger
  • 243
  • 2
  • 4
  • 14
  • It would also depend on where the gyroscope is physically located within the phone's body. If it's not exactly at the center of rotation, it's going to get a mix of all the values.e.g. if it's located where the green app icon is on your sample picture, but you're rotating the phone at the grey ball where the axis arrows meet... – Marc B Mar 05 '11 at 20:33
  • OK thanks, but the pitch has zero variation. Even if it creates a mix of variations it should vary something but it is not changing at all. The one changing is yaw. In other words, I rotate it along the green axis I see changes on the blue axis, not on the green as expected...´ – Roger Mar 05 '11 at 20:45
  • So you're asking why the axes are relative to the ground instead of relative to the phone? – Gabe Mar 05 '11 at 20:46
  • No, I am asking why is yaw varying (instead of pitch) when I change pitch and do axis change when I rotate the device or the axis are always fixed to the ground reference? – Roger Mar 05 '11 at 21:08
  • +1 for the nice picture :-) What happens if you lay the iPhone flat on the table, instead of on its edge (if that is what yo mean by 'size')? What happens if you turn it upside down? And so on... – TonyK Mar 05 '11 at 21:44
  • ooooops, I mean side instead of size. If it is flat on the table, it reads 0,0,0 (row, pitch, yaw). I can rotate it upside down (glass facing table) by two ways. I can roll 180 degrees or I can pitch 180 degrees. If I row 180 degrees, it reads -180,0,0. If I pitch 180 degrees, it will read -180,0,-180 (note the last -180 value is on yaw, but remember that I changed pitch and it had no variation in pitch). Apparently it is using an axis permanently fixed. So, I have no idea how these rotations can be projected to the local reference... – Roger Mar 05 '11 at 22:02
  • The fixed frame of reference is gravity. Z is always vertically fixed. CoreMotion picks arbitrary orthogonal x,y axis in the plane orthogonal to gravity to generate the frame of reference for measurement. 34:15 in WWDC 2010 Session 423 – Steve McFarlin Mar 07 '11 at 04:28
  • Just to verify your definitions as compared to your illustration: red axis = yaw, green axis = pitch, blue axis = roll. That's how you're using them, right? – Suncat2000 Mar 08 '11 at 19:24

2 Answers2

2

Check out my question and the selected answer for some more information on this. I think the answer, in particular, tells you why the two are connected.

Community
  • 1
  • 1
donkim
  • 13,119
  • 3
  • 42
  • 47
0

Sounds like a problem related to Gimbal Lock, expecially when dealing with pitch rotations. You may have a look at iPhone - understanding iPhone rotation

Gimbal Lock or similar articles describe phenomenon. The solution depends on what you need in your app. In most cases you should avoid using Euler angles and take rotation matrix or quaternion representation instead. OK I know, it is sometimes impossible. A good point to start might be the WWDC 2010 teapot core motion example.

Community
  • 1
  • 1
Kay
  • 12,918
  • 4
  • 55
  • 77