在iPhone 4上使用陀螺仪补偿罗盘延迟 [英] Compensating compass lag with the gyroscope on iPhone 4

查看:166
本文介绍了在iPhone 4上使用陀螺仪补偿罗盘延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试验iPhone 4上的指南针和陀螺仪,并希望得到一些我正在解决的问题的帮助。我想通过使用陀螺仪的数据来弥补指南针的缓慢。

I've been experimenting with the compass and gyroscope on iPhone 4 and would like some help with an issue I'm having. I want to compensate for the slowness of the compass by using data from the gyroscope.

使用 CMMotionManager 及其 CMDeviceMotion 对象( motionManager.deviceMotion ),我得到 CMAttitude 目的。如果我错了(请),请纠正我,但这是我从 CMAttitude 对象的 yaw 中推断出的内容物业(我不需要音高也不需要用于我的目的):

Using CMMotionManager and its CMDeviceMotion object (motionManager.deviceMotion), I get the CMAttitude object. Correct me if I'm wrong (please), but here is what I've deduced from the CMAttitude object's yaw property (I don't need pitch nor roll for my purposes):


  • yaw 范围从 0 PI 当手机指向下方时(如 deviceMotion.gravity.z 所示)并逆时针摆动且 0 -PI 顺时针摆动时

  • 当设备指向上方时,偏航范围从 -PI 0 PI 0 ,分别

  • 和指南针数据(我正在使用 locationManager.heading .magneticHeading ),我看到罗盘的值从 0 360 ,顺时针摆动时值增加

  • yaw ranges from 0 to PI when the phone is pointing downwards (as indicated by deviceMotion.gravity.z) and swinging counterclockwise and 0 to -PI when swung clockwise
  • when the device is pointing upwards, yaw ranges from -PI to 0 and PI to 0, respectively
  • and from the compass data (I'm using locationManager.heading.magneticHeading), I see that the compass gives values from 0 to 360, with the value increasing when swinging clockwise

好吧,所以一起使用所有这些信息,我就能得到一个值调用水平,无论设备是向上还是向下,都会将值从 0 提供给 360 并且当设备顺时针摆动时增加(但是当 deviceManager.gravity.z 大约<$ c时我仍然遇到问题$ c> 0 - 这个 gravity.z 值的 yaw 值吓坏了)。

All right, so using all of this information together, I'm able to get a value I call horizontal that, regardless of whether the device is pointing up or down, will give values from 0 to 360 and increase when the device is swung clockwise (though I am still having trouble when deviceManager.gravity.z is around 0 -- the yaw value freaks out at this gravity.z value).

在我看来,我可以同步水平 magneticHeading 值,使用计算出的水平值映射到 magneticHeading ,并同步 水平值到 magneticHeading 当我觉得指南针已赶上时。

It seems to me that I could "synchronize" the horizontal and magneticHeading values, using a calculated horizontal value that maps to magneticHeading, and "synchronize" the horizontal value to magneticHeading when I feel the compass has "caught up."

所以我的问题:


  • 我是否在正确的轨道上?

  • 我是否正确使用 CMDeviceMotion 的陀螺仪数据,我上面列出的假设是否正确?

  • gravity.z 大约<$时,为什么偏航吓坏了c $ c> 0 ?

  • Am I on the right track with this?
  • Am I using the gyro data from CMDeviceMotion properly and the assumptions I listed above correct?
  • Why might yaw freak out when gravity.z is around 0?

非常感谢。我期待着听到你的答案!

Thank you very much. I look forward to hearing your answers!

推荐答案

试着回答......如果我错了,请纠正我..

Just trying to answer... correct me if i'm wrong..

1.你是否走在正确的轨道上

1.Yes you are on the right track

2. CM中的引力已经与用户隔离重力(由用户加速引起的重力值)这就是为什么有两个引力,引力和userAcceleration它在苹果CM文档上
//注意:不完全孤立//

2.gravity in CM is already "isolated" from user gravity (gravity value caused by user acceleration) thats why there is two gravity, the "gravity" and "userAcceleration" its on apple CM documentation // Note : not entirely isolated //

3。
如果你的重力为0则意味着相应的轴与重力垂直。
gravity.z是iPhone屏幕,这就是为什么-9.82m / s2,如果你把桌子放在屏幕上直立,实际上很难得到0或由于传感器噪音引起的最大重力值(这是正常的,所有传感器都有一个噪音特别便宜的传感器)。

3. if you have a gravity 0 it mean that the coresponding axis is perpendicular with gravity. gravity.z is the iPhone screen thats why it -9.82m/s2 if you put on the desk with screen upright, actualy it hard to get 0 or maximum value of the gravity due to the sensor noise (it's normal, all sensor has a noise expecially cheap sensor).

我在我的应用程序上做的是我将我的参考轴切换到另一个轴(在你的情况下可能是x或y) )对于某些限制,策略如何取决于目的或哪一方是您的参考。

what i do on my apps is I will switch my reference axis to other axis (in your case may be x or y) for certain limits, how the strategy is depend on the purpose or which side is your reference.

另一件事是,陀螺仪速度快但不稳定,需要重新校准几个间隔的值。在我的情况下每5秒。我用陀螺试验计算两个平面之间的角度,我尝试用90度标尺,每秒钟会产生0.5度左右的误差并保持增加,但那是我的,也许其他人有更好的方法来避免错误。

the other thing is, gyro is fast but its not stable, you need to re-calibrate the value for several interval. In my case every 5 second. I've experiment with gyro for calculating angle between two plane, i try with exacly 90 degree ruler and it will give an error about 0.5 degree every second try and keep increasing, but thats is mine, maybe others have a better method for avoid the error.

以下是我的步骤


  1. Init

  2. 读取重力XYZ - > Xg Yg Zg

  3. 检查Xg是否<0.25如果为TRUE尝试Yg然后Zg //注1 = 1g = 9.82 m / s ^ 2

  4. 阅读指南针和陀螺仪

  5. 使用指南针配置和校准陀螺仪,并根据我在第3点使用的轴进行计算。

  6. 如果通过5秒然后重新校准,请阅读指南针

  7. 如果与陀螺读数的差异大于5度,则跳过重新校准陀螺仪。

  8. 如果与陀螺仪读数的差异<5度使用罗盘值校准陀螺仪

  1. Init
  2. Read gravity XYZ -> Xg Yg Zg
  3. Check if Xg < 0.25 If TRUE try Yg then Zg // Note 1 = 1g = 9.82 m/s^2
  4. Read the compass and gyro
  5. Configure and calibrate the gyro using the compass and calulate based on which axis i use in point 3.
  6. If 5 second is pass then recalibrate, read the compass
  7. If the the difference with gyro reading is > 5 degree skip recalibartion the gyro.
  8. If the the difference with gyro reading is < 5 degree calibrate the gyro using compass value

注意:对于数字7:检查手机是否受到磁场影响,或接近巨大的钢铁或高压电线,还是工厂内的嘈杂重型设备。

Note: for number 7 : is to check if the phone affected with magnetic field or near huge steel such or high voltage electrical line or in noisy and heavy equipment in factory plant.

这就是全部。希望这可以帮到你......
对不起我的英语..

Thats all... Hope this could help you... And sorry for my english..

这篇关于在iPhone 4上使用陀螺仪补偿罗盘延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆