Distance moved by Accelerometer

十年热恋 提交于 2019-11-26 07:28:54

问题


I want to move objects on iPhone screen (rectangle, circle and so on) by moving iPhone. For example, I move iPhone along X-axis and the object moves along X-axis. The same for Y,Z-axis.

How can I do this? Can I get algorithm for it?

Thank you.

P.S: I looked for a while and seems like it is possible using accelerometer.


回答1:


You get position by integrating the linear acceleration twice but the error is horrible. It is useless in practice.

Here is an explanation why (Google Tech Talk) at 23:20. I highly recommend this video.

However the gyro mouse might work for your application, see between 37:00-38:25 in the video.

Similar questions:

track small movements of iphone with no GPS
What is the real world accuracy of phone accelerometers when used for positioning?
how to calculate phone's movement in the vertical direction from rest?
iOS: Movement Precision in 3D Space
How to use Accelerometer to measure distance for Android Application Development
How can I find distance traveled with a gyroscope and accelerometer?




回答2:


Not easy to do accurately. An accelerometer only reports acceleration, not movement. You can try (numerically) integrating the acceleration over time, but you're likely to end up with cumulative errors adding up and leading to unintended motion.

Pseudocode, obviously untested:

init:
    loc = {0, 0, 0}    ; location of object on screen
    vel = {0, 0, 0}    ; velocity of object on screen
    t = 0              ; last time measured

step:
    t0 = time          ; get amount of time since last measurement
    dt = t0 - t
    accel = readAccelerometer()
    vel += accel * dt  ; update velocity
    loc += vel * dt    ; update position
    displayObjectAt(loc)



回答3:


Why don't you use the acceleration itself instead distance moved? For example; If your acceleration is 1.4G east, your object should move to east 14pixels per second until your acceleration changes.

So that object's movement is will be like it is under a relative force and I think it's more realistic. Faster moving device, bigger force to effect object.

Also look:

http://www.freescale.com/files/sensors/doc/app_note/AN3397.pdf

and

Using accelerometer, gyroscope and compass to calculate device's movement in 3D world



来源:https://stackoverflow.com/questions/6645126/distance-moved-by-accelerometer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!