0

i have a problem to read out the internal gyroscope of the iphone correctly.

I had developed a augmented reality engine based on the magnetometer. Because the gyroscope gives more reliable values than the magnetometer, i wanted to improve the engine.

now, the problem is, that the gyroscope values, in reference to north, work well if the iphone is in landscape mode. But if i move the iphone between landscape and portrait, the values are wrong. i tryed to calculate a offset based on the accelerometer, but it still dont work correctly. the second problem ist, if the iphone is in portrait mode and i roll it backwards, the compass data makes a jump of 180 degrees.

_mmanager.deviceMotionUpdateInterval = 1/60.0;
_mmanager.accelerometerUpdateInterval = 1.0/90.0;
[_mmanager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical];

// queue to get accelation data
NSOperationQueue *motionQueue = [[NSOperationQueue alloc] init];
[_mmanager startAccelerometerUpdatesToQueue: motionQueue withHandler:^(CMAccelerometerData *data, NSError *error) {
    _xacc = (data.acceleration.x * 0.1) + (_xacc * (1.0 - 0.1));
    _yacc = (data.acceleration.y * 0.1) + (_yacc * (1.0 - 0.1));
    _zacc = (data.acceleration.z * 0.1) + (_zacc * (1.0 - 0.1));
}];


// in my update method
double gyx = _mmanager.deviceMotion.attitude.yaw;
double gyy = _mmanager.deviceMotion.attitude.roll;
double gyz = _mmanager.deviceMotion.attitude.pitch;

// sidewise rotation of the iphone to calculate a offset
double rotation = fmod(((atan2(-_yacc, _xacc)+M_PI/2)*180/M_PI)+180, 360);
// heading with compass data and offset just work perfectly
double compassheding = fmod(_lmanager.heading.trueHeading+rotaion, 360);


double gyroheading = -gyx*180/M_PI-90;

if(gyroheading < 0){
    gyroheading = gyroheading+360;
}

// same offset as obove. but wont work correctly.
double ro2 = fmod(((atan2(-_yacc, _xacc)+M_PI/2)*180/M_PI)+180, 360);
head = fmod(head+ro2, 360);

My question is now, how can i read out the gyroscope with north reference correctly and calculate the offset, so the vaues are still correct, when having the iphone in front of my eyes, like making a photo. I just want reliable heading data with the gyroscope and get rid of the lagging compass.

Philip
  • 112
  • 14

1 Answers1

0

It can maybe help you, here is an article where gyroscope and compass are used together to get rid of the lagging compass and still have something accurate: http://www.sundh.com/blog/2011/09/stabalize-compass-of-iphone-with-gyroscope/

alan_langlois
  • 476
  • 1
  • 4
  • 10