如何检测安装有加速度计的Andr​​oid设备的左侧和右侧倾斜? [英] How to detect left and right tilt of an android device mounted with an accelerometer?

查看:216
本文介绍了如何检测安装有加速度计的Andr​​oid设备的左侧和右侧倾斜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说,你在所有的3个维度的加速读数,即X,Y和Z.你怎么推断使用手机进行倾斜向左或向右读?读数获取生成每20ms。

Lets say you have the acceleration readings in all the 3 dimensions i.e X, Y and Z. How do you infer using the readings the phone was tilted left or right? The readings get generated every 20ms.

其实我是想推断从读数倾斜的逻辑。倾斜必须是光滑的。

I actually want the logic of inferring the tilt from the readings. The tilt needs to be smooth.

推荐答案

一个倾斜可以在几分diferent方式检测。你可以考虑1轴,2轴或3轴。取决于您如何准确想要它,多少你觉得学数学的战斗。

A tilt can be detected in a sort of diferent ways. You can take into account 1 axis, 2 axis, or the 3 axis. Depending on how accurate you want it, and how much you feel like fighting with maths.

如果您只使用一个轴,这是很简单的。认为移动是完全水平的,你移动它是这样的:

If you use only one axis, it is quite simple. Think the mobile is completely horizontal, and you move it like this:

只使用一个轴,可以说,x轴,也就足够了,因为你可以准确地检测在该轴位置的改变,因为即使任何微小的动作都会做轴的变化。 但是,如果你的应用程序只读取该轴,并得到了用户的手机几乎是垂直的,在x轴的差异会非常小,即使旋转手机大角度。 反正,对于仅需要粗分辨率的应用程序中,单轴都可以使用。

using just one axis, lets say, axis x, will be enough, since you can detect accurately a change in that axis position, since even any small movement will do a change in the axis. But, if your application is only reading that axis, and the user has the phone almost vertical, the difference in x axis will be really small even rotating the phone a big angle. Anyways,for applications that only need coarse resolution, a single-axis can be used.

参照基本三角学,的在x轴的重力向量的投影产生一个输出加速度等于加速度x轴和地平线之间的角度的正弦值。 这意味着,具有的轴的值(这些是加速度值),则可以计算出在该装置是角度。

Referring to basic trigonometry, the projection of the gravity vector on the x-axis produces an output acceleration equal to the sine of the angle between the accelerometer x-axis and the horizon. This means that having the values of an axis (those are acceleration values) you can calculate the angle in which the device is.

这意味着,由传感器提供给你的价值,是=到9,8 *角的正弦,这样做的数学就可以得到实际的角度。

this means that the value given to you by the sensor, is = to 9,8 * sine of the angle, so doing the maths you can get the actual angle.

不过不要担心,你甚至不必这样做。由于这些值都或多或少的比例,你可以在下表中看到,你可以与传感器的值直接工作,没有采取很在意什么角度重新presents,如果你不需要它很多准确的,因为在那种值的变化意味着比例变化的角度,所以用一些测试,你会发现有多大应该是为了与您的变化。

But don't worry, you don't even have to do this. Since the values are more or less proportional, as you can see in the table below, you can work directly with the value of the sensor, without taking much care of what angle represents, if you don't need it to be much accurate, since a change in that value means a proportional change in the angle, so with a few test, you will find out how big should be the change in order to be relevant to you.

所以,如果你接手时的价值,并进行相互比较,就可以计算出旋转有多大了。对于这一点,

So, if you take the value over the time, and compare to each other, you can figure out how big the rotation was. For this,

  1. 您考虑的只是一个轴。这将是X轴
  2. 在编写一个函数来获得在该轴之间的一个函数调用的传感器值的差额,并在未来
  3. 决定的最大时间和最小的传感器的区别,你会考虑一个有效的运动(例如,一个大的旋转是好的,但只有当它是速度不够快,和一个快速运行良好只有在角度差异较大足够了)
  4. 如果您发现两次测量是实现这些条件,你需要注意,半倾斜做(在布尔为例),并重新开始测量,但现在,新的参考值是被认为是半倾斜值。
  5. 如果上次不同的是积极的,现在你需要一个负差,如果上次不同的是消极的,现在你需要一个积极的变化;这是,回来了。因此开始采取比较新的参考值新值来自传感器的值,看是否达到你的3点决定的东西。
  6. 如果你找到一个有效的值(实现的价值差异和时间等条件),你有一个倾斜。但是,如果你不一个很好的价值得到,时间被消耗,重置一切:让你的参考值是最后一个,复位定时器,重置半倾斜完成布尔为假,并保持测量。

我希望这是对你不够好。为了确保你能找到一些图书馆或code片段来帮你出这一点,但我认为这是很好的,就像你说的,要知道从读数推断倾斜的逻辑

I hope this is good enough for you. For sure you can find some libraries or code snippets to help you out with this, but i think is good, as you say, to know the logic of inferring the tilt from the readings

这些照片是从<一个取href="http://www.digikey.com/us/en/techzone/sensors/resources/articles/using-an-accelerometer-for-inclination-sensing.html"相对=nofollow>这篇文章,至极我建议看,如果你想提高精度,并考虑2 O 3轴倾斜

The pictures was taken from this article, wich i recomend to read if you want to improve the accuracy and consider 2 o 3 axis for the tilt

这篇关于如何检测安装有加速度计的Andr​​oid设备的左侧和右侧倾斜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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