如何校准Android Accelerometer&减少噪音,消除重力 [英] How to Calibrate Android Accelerometer & Reduce Noise, Eliminate Gravity

查看:284
本文介绍了如何校准Android Accelerometer&减少噪音,消除重力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我一直在为这个问题苦苦挣扎,而且还没有任何运气能够挖掘互联网的智慧和相关的SO帖子。



我正在写一个使用无处不在的加速度计的Android应用程序,但即使在休息的时候,我似乎也得到了令人难以置信的噪音,似乎无法弄清楚如何处理它,因为我的阅读需要比较准确。我认为也许我的手机(宏达不可思议)功能失常,但传感器似乎与其他游戏和我玩过的应用程序运行良好。



我试过使用各种过滤器,但我似乎无法绕过他们的思想。我明白,引力必须以某种方式处理,也许这就是我出错的地方。目前我已经尝试过,从一个 SO答案,这是从iPhone的例子SDK:

  accel [0] = event.values [0] * kFilteringFactor + accel [0] *(1.0f  -  kFilteringFactor ); 
accel [1] = event.values [1] * kFilteringFactor + accel [1] *(1.0f - kFilteringFactor);


double x = event.values [0] - accel [0];
double y = event.values [1] - accel [1];

海报说玩kFilteringFactor值(例如kFilteringFactor = 0.1f)满意。不幸的是,我似乎还是听到了很多噪音,而这一切似乎只是让读数成为小数字,这对我来说帮不了多少,而且似乎只是让传感器不那么敏感。我的大脑的数学中心也因多年的忽视而萎缩,所以我不完全理解这个过滤器是如何工作的。

有人可以向我详细解释如何从加速度计读取有用的读数吗?一个简洁的教程将是一个难以置信的帮助,因为我没有找到一个很好的(至少针对我的知识水平)。我感到沮丧,因为我觉得所有这些对我来说应该更加明显。任何帮助或方向将不胜感激,当然,如果需要,我可以从我的代码提供更多的样本。



我希望我不要求汤匙太多了;我不会问,除非我一直在想我们的一段时间。它也看起来像其他SO成员的一些兴趣。

解决方案

为了从加速度计得到正确的读数,你需要使用等式速度= SQRT(x * x + y * y + z * z)。使用这个,当电话静止时,速度将是重力 - 9.8m / s。所以,如果你减去(SensorManager.GRAVITY_EARTH),那么当手机静止时,你将有一个0米/秒的读数。至于噪音,Blrfl可能是正确的廉价加速度计,即使当我的手机静止时,它不断地闪烁几分之一米每秒。你可以设置一个小的阈值,例如0.4米/秒,如果速度没有超过那个,那么它是静止的。

So, I've been struggling with this problem for some time, and haven't had any luck tapping the wisdom of the internets and related SO posts on the subject.

I am writing an Android app that uses the ubiquitous Accelerometer, but I seem to be getting an incredible amount of "noise" even while at rest, and can't seem to figure out how to deal with it as my readings need to be relatively accurate. I thought that maybe my phone (HTC Incredible) was dysfunctional, but the sensor seems to work well with other games and apps I've played.

I've tried to use various "filters" but I can't seem to wrap my mind around them. I understand that gravity must be dealt within some way, and maybe that's where I am going wrong. Currently I have tried this, adapted from a SO answer, which refers to an example from the iPhone SDK:

                accel[0] = event.values[0] * kFilteringFactor + accel[0] * (1.0f - kFilteringFactor);
                accel[1] = event.values[1] * kFilteringFactor + accel[1] * (1.0f - kFilteringFactor);


                double x = event.values[0] - accel[0];
                double y = event.values[1] - accel[1];

The poster says to "play with" the kFilteringFactor value (kFilteringFactor = 0.1f in the example) until satisfied. Unfortunately I still seem to get a lot of noise, and all this seems to do is make the readings come in as tiny decimals, which doesn't help me all that much, and it appears to just make the sensor less sensitive. The math centers of my brain are also atrophied from years of neglect, so I don't completely understand how this filter is working.

Can someone explain to me in some detail how to go about getting a useful reading from the accelerometer? A succinct tutorial would be an incredible help, as I haven't found a really good one (at least aimed at my level of knowledge). I get frustrated because I feel like all of this should be more apparent to me. Any help or direction would be greatly appreciated, and of course I can provide more samples from my code if needed.

I hope I'm not asking to be spoon-fed too much; I wouldn't be asking unless I've been trying to figure it our for a while. It also looks like there is some interest from other SO members.

解决方案

To get a correct reading from the accelerometer you need to use the equation speed = SQRT(x*x + y*y + z*z). Using this, when the phone is at rest the speed will be that of gravity - 9.8m/s. So if you subtract that (SensorManager.GRAVITY_EARTH) then when the phone is at rest, you will have a reading of 0 m/s. As for noise, Blrfl might be right about cheap accelerometers, even when my phone is at rest, it continuously flickers a few fractions of a metre per second. You could just set a small threshold e.g 0.4m/s and if the speed doesn't go over that, then it is at rest.

这篇关于如何校准Android Accelerometer&减少噪音,消除重力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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