过滤指南针读数 [英] Filtering compass readings

查看:192
本文介绍了过滤指南针读数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用指南针标题来旋转MKMapView。旋转是有点干,所以我想过滤它像iPhone上的谷歌地图(或似乎做一些欺骗)。

我试图使用移动平均公式过滤掉iphone指南针的读数,但是它在359和359之间的交叉点上失败,因为它开始平均从35x向后平移到0,导致地图从西向北接近地向后旋转。



任何想法最好的办法是过滤这些数据,使其从359回到零,并保持滚动平均。

代码如下:

pre $ - (void)locationManager:(CLLocationManager *)manager didUpdateHeading :( CLHeading *)newHeading {
static float xd = 0;
static float k = 0.22;

//移动平均公式
xd = k * xd +(1.0 - k)* newHeading.magneticHeading;

NSLog(@%0.2f:%0.2f,newHeading.magneticHeading,xd);
[map setTransform:CGAffineTransformMakeRotation(( - 1 * xd * M_PI)/ 180)];}

感谢您的帮助

解决方案

如果以前的移动平均值和新的标题差异大于180度, 360以较小者为准。然后在存储新的移动平均数时按360。所以(没有精确的数学):

  HDG 
350 350
355 353
0 356(因为353-0> 180所以调整的HDG是360)
5 359(同样地)
10 2(同样,那么362是新的MA,mod 360要归一化)
350 356 (因为2 - 350< -180所以调整MA是362)

我的希望是并且比平均角度中所描述的三角法更有效率(归功于Mark Ransom的指称)。 b $ b

I'm using compass heading to rotate an MKMapView. The rotation was a bit jerky so I'm trying to filter it like Google Maps on the iphone does (or appears to do some trickery).

I'm trying to filter the reading from the iphone compass using a moving average formula but it fails on the crossover between 359 adn 0 becuase it starts to average backwards from 35x to 0 and causes the map to rotate backwards as it approaches north from the west.

Any ideas what the best way is to filter this data so that it crosses from 359 back to zero and maintain the rolling average.

Code is here:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
static float xd=0;
static float k = 0.22;

// Moving average formula
xd = k * xd + (1.0 - k) * newHeading.magneticHeading;

NSLog(@"%0.2f : %0.2f", newHeading.magneticHeading, xd);    
[map setTransform:CGAffineTransformMakeRotation((-1 * xd * M_PI) /180)];}

Thanks for any help

解决方案

If the previous moving average and the new heading are different by more than 180 degrees, add 360 to whichever is smaller. Then mod by 360 when storing the new moving average. So (without precise math):

HDG   MA
350   350
355   353
  0   356  (because 353 - 0 > 180 so adjusted HDG is 360)
  5   359  (likewise)
 10     2  (likewise, then 362 is new MA, mod 360 to normalize)
350   356  (because 2 - 350 < -180 so adjusted MA is 362)

My hope is that this works and is more efficient than the trigonometric method described in Averaging angles (credit to Mark Ransom for referring to that).

这篇关于过滤指南针读数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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