Android: Determining the angle of tilt using only accelerometers

ぃ、小莉子 提交于 2019-12-08 11:22:49

问题


I am trying to compute the angle of a leg instantaneously regarding an initial position using accelerometer readings.

As I approached this, I decided I needed to record an averaged gravity vector and compute some angle between my current reading and that.

Theoretically it seems plausible: the reading of gravity is different on each position of the leg, so in stationary positions the readings should converge to a vector I can use to find the angular displacement of the leg, with respect to the reading at the start.

However, I have tried several combinations: the angle between both vectors using only the Z and Y components (using this); compute the difference vector between both gravity and current, and do atan2(dY,SQRT(dX^2+dZ^2)); compute atan2(dY,dz)... (where dY and dZ are the subtraction of the current and gravity vector for the Y and Z components, respectively)

None of these solutions seem to be working, so I am wondering if I can even do this.

Does anyone have a solution for this?


回答1:


Assuming the device is tied to the leg with the screen facing the same direction as of the user then you can calculate the angle as the angle between the surface of the screen and the East-North plane. I just give you the idea here you have to do some more work to know if the angle is below or above the East-North plane. The angle can be calculate as

Math.acos(event.values[3] / norm of event.values[3]);  

Thus if the user is standing then the angle will be 90 or -90 depending your convention. And when the leg move up the absolute of the angle will be decreasing. One the thigh is parallel to the East-North plane, ie the screen is laying flat and the leg moves up, you will get the same angle as the leg moves down, so you need to use a little more info to figure this out.
If the screen is orthogonal to the facing direction of the user then you have to calculate the angle between the East-North plane and the plane orthogonal to the screen. I let you figure this out, it probably the above equation with event.values 0 or 1 depending on whether the device is in Portrait or Landscape.



来源:https://stackoverflow.com/questions/15709918/android-determining-the-angle-of-tilt-using-only-accelerometers

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