如何根据手机的加速度来计算距离 [英] How to calculate distance based on phone acceleration

查看:3393
本文介绍了如何根据手机的加速度来计算距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立这样的事情,但使用的是Android手机: http://www.youtube .COM /手表?ν= WOt9mb5QqRs

I want to build something like this but using an android phone: http://www.youtube.com/watch?v=WOt9mb5QqRs

我已经建立了一个应用程序,将通过套接字传感器信息(还在寻找一个很好的的WebSocket实现机器人)。我打算使用这些信息来与Web应用程序进行交互,例如,我将能够将图像基于手机的移动移动。 问题是,我试图计算基于加速度计数据的距离,但结果是非常糟糕的。我不知道是否有人可以帮助我正确的公式,但首先,是有可能做到这一点?

I've already built an app that sends sensor information via socket (still looking for a good websocket implementation for android). I intend to use that information to interact with a web app, so for example i would be able to move an image based on the phone movement. The problem is that I tried to calculate distance based on the accelerometer data but the results are really bad. I wonder if anyone could help me with the correct equation, but first of all, is it possible to do this?

直到现在我用下面的公式:

Till now I'm using the following equations:

速度=加速度*时间;

距离=速度*时间+(加速时间* ^ 2)/ 2;

然后根据监视器屏幕分辨率我翻译每秒米的距离,以像素为单位。

then I translate distance from meters per second to pixels based on monitor screen resolution.

这是每个时间我收到传感器数据计算的JavaScript在浏览器中,这是每一个〜80毫秒。

that's calculated with javascript in the browser every time i receive sensor data, which is every ~80ms.

推荐答案

基础知识很简单。在模拟世界里,你使用连续数学是:

The basics is simple. In the analog world you use continuous math which is:

velocity = integrate(acceleration)
distance = integrate(velocity)

和在数字世界中更容易,你用离散数学,其中集成变得总和:

and in the digital world it is even easier, you use discrete math where integration becomes summation:

velocity = sum(acceleration)
distance = sum(velocity)

只要保持增加了阅读的加速度的所有值,你最终得到的距离。

Just keep adding up all the values of acceleration you read and you eventually get distance.

的最大问题在于,在地球上有一个恒定的加速度向下约10米/秒/秒,由于重力作用。搞清楚其中的载体的一部分比重是困难的部分。

The big problem with this is that on planet Earth there is a constant acceleration downwards of approximately 10m/s/s due to gravity. Figuring out which part of your vector is gravity is the hard part.

BTW,重力是如何加速计可以检测倾斜。所以,不管你这样做,除非你能计算出独立于加速度计的倾斜(例如,使用陀螺仪的帮助下)你的code将主要测量的,而不是距离倾斜。

BTW, gravity is how accelerometers can detect tilt. So however you do it, unless you can calculate the tilt independently of the accelerometers (for example with the help of gyros) your code will mostly be measuring tilt instead of distance.

哈!我只是从我的最后一条语句意识到,很多iPhone应用程序不会在太空:-P工作

HA! I just realized from my last statement that a lot of iPhone apps won't work in space :-P

根据一个评论发表的OP(如低于或高于这个答案的答案),它看起来像我需要提供进一步的解释。执行是真的,真的很简单,人们不熟悉的数学会认为它必须比这更复杂。伪code是如下:

Based on a "comment" posted by the OP (as an answer either below or above this answer) it looks like I need to provide further explanation. The implementation is really-really simple that people not familiar with the maths will think it must be more complicated than that. The pseudocode is as follows:

// Set distance to zero at start-up:
var distance_X = 0
var velocity_X = 0

function update_acceleration_X (acceleration_X) {
    velocity_X = velocity_X + acceleration_X
    distance_X = distance_X + velocity_X
}

// To use the distance value just read the distance_X variable:
function get_distance_X_and_reset () {
    x = distance_X
    distance_X = 0
    return x
}

距离总是从哪里软件第一次启动,除非您重置的距离变到零测量。加速度计必须经常(在速率本身测量力加速度计preferably)和速度与距离相应地更新的值被读取。当你想知道,从起点的距离刚才读的距离变量。

Distance is always measured from where the software first starts unless you reset the distance variable to zero. The accelerometer must constantly be read (preferably at the rate the accelerometer itself measures forces) and the values of velocity and distance updated accordingly. When you want to know the distance from the starting point just read the distance variable.

几件事情:任何的量的倾斜,无论多么轻微,将增加漂移。也就是说,总是会有少量恒定加速度的在一个方向或另一个除非倾斜本身的角度不断跟踪。即使核潜艇,配备了高precision加速度计和陀螺仪,因为GPS不水下工作,必须定期浮出水面,并同步与全球定位系统纠正这种漂移。

Several things: any amount of tilt, no matter how slight, will add drift. Meaning that there will always be a small amount of constant acceleration in one direction or the other unless the angle of tilt itself is constantly tracked. Even nuclear submarines, equipped with high precision accelerometers and gyros because GPS doesn't work under water, need to periodically surface and sync with GPS to correct this drift.

其次,加速度计测量的力,不运动。任何一种力量进行测量。我提到的引力,但它也测量由摩擦引起的颠簸有一张桌子,你的脉搏是你的心跳和呼吸的原因你的手微微抖动,任何东西。好消息是,从长远来看,所有这些因素将会平均和公式将仍然是正确的。但就短期来看,这意味着你的阅读将是嘈杂。有很多的技巧,人们纷纷拿出尽量减少使用像维纳和卡尔曼滤波器这种噪声。

Second, the accelerometer measures force, not movement. Any kind of force is measured. I mentioned gravity but it also measures bumps caused by friction with a table, your pulse as your heartbeat and breathing cause your hand to shake slightly, anything. The good news is that over the long run all these forces will average out and the formula will still be correct. But in the short run it means your reading is going to be noisy. There are a lot of tricks people have come up with to minimize this noise using things like Weiner and Kalman filters.

三,你可能已经注意到,加速度计读数不是恒定的。我并不简单地意味着该值是在每次读取它们的时间不同,这是显而易见的,但它也读数之间在-变化值。我们错过了每个值影响着我们的精确度,因此读取值尽可能经常是很重要的。现在,好消息是,从长期来看所有这些错误所造成的遗漏值应平均掉,因为他们大多引起剧烈地移动或振动,我们的公式又是仍然正确。但它再次意味着,在短期内,这增加了噪音对我们的系统。如果你使用一个很好的perdictive过滤器就像一个卡尔曼滤波器那么它应该能够考虑到这一点,但较弱的过滤器可能需要一些帮助。这样做的一种方法是将平均掉各个加速度读数与previous读数。需要注意的是它必须是previous真实的阅读,而不是previous平均读数。

Third, as you may have noticed, the accelerometer reading is not constant. I don't simply mean that the values are different each time you read them, that is obvious, but it also changes values in-between readings. Every value we miss affects our accuracy so it is important to read the values as often as possible. Now, the good news is that in the long run all these errors caused by missing values should average out as they are mostly caused by jerky movements or vibrations and our formula is again still correct. But it means again that in the short run this adds noise to our system. If you use a good perdictive filter like a Kalman filter then it should be able to account for this but weaker filters may need some help. One way of doing this is to average out each acceleration reading with the previous reading. Note that it must be the previous "real" reading, not the previous averaged reading.

更多的精度比这个进入惯性测量单元(IMU)的境界和惯性制导和大量相当毛茸茸的向量和矩阵数学。这样做有虽然开源项目(不到10年前的这个东西是严格的军事,因为,你知道,潜艇和巡航导弹使用它们)。

More accuracy than this goes into the realm of Inertial Measurement Units (IMU) and inertial guidance and a lot of fairly hairy vector and matrix maths. There are open source projects doing this though (less than 10 years ago this stuff was strictly military since, you know, submarines and cruise missiles use them).

这些Sparkfun文章有在底部和一些不错的链接有一定的参考code:

These Sparkfun articles have some nice links at the bottom and some reference code:

http://www.sparkfun.com/products/9268

http://www.sparkfun.com/products/8454

希望这一切帮助。如果任何人有联系的任何物品,这可以帮助请评论。

Hope all this helps. And if anyone else have links to any article which may help please comment.

当然,如果你愿意,你需要以规模求采样率实际单位。例如在9米/ S / S加速为80毫秒意味着你的速度(9米/秒/秒* 0.08s)=0.72米/ S 。上述伪code简化假设你不关心单位。最后的值仍然会重新present距离为一个数字,它只是这个数字几乎没有关系,测量中的任何真实世界单位。你可以简单应用的缩放功能,在结束校准,以你的像素衣被合计。总之,这里是一个例子与实际单位澄清发生的事情:

Of course if you want real units you need to scale for sample rate. For example accelerating at 9m/s/s for 80ms means your velocity is (9m/s/s * 0.08s) = 0.72m/s. The above pseudocode is simplified assuming you don't care about units. The final values will still represent distance as a number it's just that the number has little relation to any real world unit of measurement. You can simply apply a scaling function at the end calibrated to your pixel valus. Anyway, here's an example with real-world units to clarify what's happening:

given the following acceleration readings:
9m/s/s
3m/s/s
0m/s/s
0m/s/s
0m/s/s
-5m/s/s
-7m/s/s

assuming an 80ms sample rate
we can derive the following velocities:
0.72m/s (what you get from accelerating 9m/s for 80ms)
0.96m/s
0.96m/s
0.96m/s
0.96m/s
0.56m/s
0m/s

from that we can derive the following distances:
57.6mm (what you get from moving at 0.72m/s for 80ms)
134.4mm
211.2mm
288mm
364.8mm
409.6mm

现在,如果你拿得出的距离,做一个反向计算按通常( V =(S2-S1)/吨 A =(V2-V1)/ T )你应该得到的加速读数回来。

Now, if you take the derived distances and do a reverse calculation as per usual (v = (s2-s1)/t and a = (v2-v1)/t) you should get the acceleration readings back.

这篇关于如何根据手机的加速度来计算距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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