开发者

how can i get velocity with UIAcceleration?

Do you know the app "motion ruler"? It can开发者_如何学运维 be used to get the length of an object by moving an iPhone.

How can I get the velocity from UIAcceleration when moving an iPhone?


Velocity is just acceleration * time. I.e. you can use the formula

v = u + acceleration * time.

As a starter you could look at assuming the initial speed is 0, 'u' can be ignored to get accelration * time.

if you want distance just use distance = initial velocity * time + 0.5 * acceleration * time * time.

or better still use dead reckoning and keep adding your velocity vectors as frequently as you get updates from the accelerometers.

To get acceleration as a scalar you can do a = sqrt(x*x+y*y+z*z). You will want to remove gravity from this before though! Also this will only give you distance in straight line, you may prefer to measure velocity in x,y,z independently and use vector analysis to measure the path for a more accurate reading. Be warned though, you may also need to take into account any rotations to be super accurate and this feature is only on iPhone4s. This can get tricky and you'll probably want to use some matrix maths to orientate the 'space' the phone is in.

You will also need to do a low pass filter on the accelerometer to get rid of the 'shakes' and this is where a significant error margin will creep in and why I'd expect all rulers in appstore have spent a long time refining this.

to do a filter, a very simple one is filteredValue = ((lastValue * n) + accelerationValue )/(n+1) where a larger n value gives a smoother result but less responsive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜