【问题标题】:iOS 5/6 Gyroscope north referenceiOS 5/6 陀螺仪北参考
【发布时间】:2012-11-09 12:27:36
【问题描述】:

我无法正确读取 iphone 的内部陀螺仪。

我开发了一个基于磁力计的增强现实引擎。因为陀螺仪给出的值比磁力计更可靠,所以我想改进引擎。

现在,问题是,如果 iphone 处于横向模式,陀螺仪值,参考北方,工作良好。但是,如果我在横向和纵向之间移动 iPhone,则值是错误的。我试图根据加速度计计算偏移量,但它仍然无法正常工作。第二个问题是,如果iphone处于竖屏模式并且我向后滚动,指南针数据会跳跃180度。

_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);

我现在的问题是,我怎样才能正确读出具有北参考的陀螺仪并计算偏移量,所以当将 iPhone 放在我的眼前时,值仍然是正确的,就像拍照一样。我只想用陀螺仪获得可靠的航向数据,并摆脱滞后的指南针。

【问题讨论】:

  • 您找到解决方案了吗?我有一个类似的问题。
  • @phil 你解决了这个问题吗?
  • 是的,找到了解决方案。但这个解决方案是基于旋转矩阵,而不是偏航、俯仰和滚动的原始值。

标签: iphone ios rotation compass-geolocation gyroscope


【解决方案1】:

也许可以帮到你,这里有一篇文章,陀螺仪和指南针一起使用,可以摆脱落后的指南针,仍然有一些准确的东西: http://www.sundh.com/blog/2011/09/stabalize-compass-of-iphone-with-gyroscope/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-16
    相关资源
    最近更新 更多