安卓:仅使用加速计确定倾斜角倾斜角

2023-09-07 10:09:38 作者:过去再美°终是空

我试图用计算加速度计读数瞬间就初始位置腿的角度。

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.

理论上它似乎是合理:重力的读数是在腿部的各位置不同,因此,在固定的位置上的读数应收敛到矢量I可用于查找腿的角位移,具有在相对于读取开始。

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.

不过,我已经尝试了几种组合:仅使用Z和Y分量两者向量之间的角度(使用的这个);计算重力和电流之间的差​​矢量,并且做ATAN2(DY,SQRT(DX ^ 2+ DZ ^ 2));计算ATAN2(DY,DZ)...(其中,DY和DZ是对Y和Z分量的电流和重力矢量的减法,分别)

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?

推荐答案

假设该设备被绑定到朝向相同的方向的用户然后就可以计算出角度的表面之间的角度在屏幕的腿屏幕和东 - 北平面。我只是给你的想法在这里你必须做更多的工作要知道如果角度小于或东 - 北平面上方。角度可以计算为

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]);  

因此​​,如果用户站在随后的角度将是90或-90取决于你的约定。当腿向上的绝对的角度将被减少。一个大腿平行于东 - 北面,也就是屏幕平放,以及腿部向上移动,你会得到相同的角度腿向下移动,所以你需要使用一个小的详细信息摸不着头脑。结果如果屏幕正交于用户的面对方向,那么你必须计算出东 - 北平面和平面正交于屏幕之间的角度。我让你摸不着头脑,它可能与上面的方程event.values​​ 0或取决于设备是否在纵向或横向1