垂直运动传感器 [英] Vertical movement sensor

查看:172
本文介绍了垂直运动传感器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要检测垂直运动的Android应用程序。当将平板电脑向上移动时,陀螺仪,加速度计和线性加速度传感器会给出相应的值,指示向上或向下运动。

I am working on an android app that requires the detection of vertical motion. When moving the tablet upward, the Gyroscope, Accelerometer, and Linear Acceleration sensors give a corresponding value indicating upward or downward motion.

我的问题是,当您将平板电脑向用户或远离用户倾斜时,这些传感器也会读取向上/向下的运动。例如,陀螺仪中的x值表示垂直平面。但是,当您向前倾斜设备时,x值将会改变。
进行此运动时,读取垂直运动的同一传感器将为此读取一个值。

The problem I have is that these sensors will also read an upward/downward motion when you tilt the tablet towards the user or away from the user. For example, the x value in the gyroscope represents the vertical plane. But when you tilt the device forwards, the x value will change. When I make this motion, the same sensor that reads vertical motion reads a value for this.

其余的传感器也是如此。我尝试将方向与陀螺仪结合使用来进行条件声明,如果音高没有变化,但是x变量在上/下变化,则我们有垂直运动。这样的问题是,如果用户向上移动但稍微倾斜,它将不再起作用。我还尝试过这样做,因此,如果倾斜发生变化,则不会发生垂直运动。但是迭代如此之快,以至于倾斜可能会发生1/100秒的变化,但是下一秒钟就没有变化。

The same goes for the rest of the sensors. I have tried to use orientation coupled with the gyro to make the conditional statement, if the pitch is not changing, but the x variable is going up/down, then we have vertical motion. The problem with this is that if the user moves it up but tilted slightly, it will no longer work. I also tried making it so if there is a change in tilt, then there is no vertical motion. But it iterates so quickly that there may be a change in tilt for 1/100 of a second, but for the next there isn't.

我有什么办法吗?只能读取垂直变化而不读取设备间距的变化?

Is there any way I can read only vertical changes and not changes in the devices pitch?

这是我要检测的内容:

Here is what I want to detect:

编辑:

请为您认为向上移动提出数学上正确的定义。
这是我最初的问题,如何编写定义数位板向上或向下移动的功能?我认为垂直平移向上移动。现在我该如何检测?我根本不知道从哪里开始,谢谢。

"Please come up with a mathematically sound definition of what you consider 'moving upwards.'" This was my initial question, how can I write a function to define when the tablet is moving upwards or downwards? I consider a vertical translation moving upwards. Now how do I detect this? I simply do not know where to begin, thank you.

推荐答案

好的,尽管这个问题已经很老了,但我在当前的答案和评论中还是感到困惑。万一有人发现了这个,我打算清理一些东西。

Ok, even though this question is fairly old, I see a lot of confusion in the present answer and comments, so in case anyone finds this, I intend to clear a few things up.

首先,陀螺仪不会按照您的定义测量垂直运动(平移运动)。它测量围绕每个轴围绕的旋转,如下图所示。因此,向前或向后倾斜设备确实会使它绕x轴旋转,因此您将在陀螺仪传感器的x值中看到非零值。

First of all, the gyroscope does not measure vertical motion as per your definition (a translatory motion). It measures rotation around each of the axes, which are defined as in the figure below. Thus having you tilt your device forwards and backwards indeed rotates it around the x axis and therefore you will see non-zero values in the x value of your gyroscope sensor.

< img src = https://developer.android.com/images/axis_device.png alt =设备轴>


the陀螺仪中的x值代表垂直平面。

the x value in the gyroscope represents the vertical plane.

我不确定垂直平面是什么意思,但是x值当然不表示平面本身,也不表示设备在平面内的方向。

I'm not sure what is meant by "the vertical plane", however the x value certainly does not represent the plane itself nor the orientation of the device within the plane.

陀螺仪传感器的x值表示设备当前沿x轴的角速度(例如,旋转变化)。

The x value of the gyroscope sensor represents the current angular velocity of the device around the x axis (eg. the change in rotation).


但是当您向前倾斜设备时,x值将会改变。当我进行此动作时,读取垂直运动的同一传感器将为此读取一个值。

But when you tilt the device forwards, the x value will change. When I make this motion, the same sensor that reads vertical motion reads a value for this.

不太清楚您要指的是什么到这里。我假设陀螺仪是读取垂直运动的同一传感器,但是如前所述,它不读取垂直运动。

Not quite sure what you're referring to here. "The same sensor that reads vertical motion" I assume is the gyroscope, but as previously said, it does not read vertical motion. It does exactly what it says on the tin.

这更多是为了回应用户Ali的答案比原始问题要大,但在两种情况下都仍然有意义。

This is more in response to user Ali's answer than the original question, but it remains relevant in either case.

线性加速度传感器(或与此相关的任何其他传感器)的单个输出以设备的坐标系表示,如下所示:如上图所示。这意味着,如果您稍微旋转设备,则输出将不再平行于它们之前重合的任何世界坐标轴。这样,您将不得不强制设备针对您的应用程序使用特定的方向,或者考虑新的方向。

The individual outputs of the linear acceleration sensor (or any other sensor for that matter) are expressed in the coordinate system of the device, as shown in the image above. This means if you rotate the device slightly, the outputs will no longer be parallel to any world axis they coincided with before. As such, you will either have to enforce that the device is in a particular orientation for your application, or take the new orientation into account.

ROTATION_VECTOR 传感器,结合四元数数学或 getRotationMatrixFromVector()方法,是一种将测量值从设备坐标转换为世界坐标的方法。还有其他方法可以实现相同的目标,但是一旦实现,握持设备的方式就不会影响垂直运动的测量。

The ROTATION_VECTOR sensor, combined with quaternion math or the getRotationMatrixFromVector() method, is one way to translate your measurements from device coordinates to world coordinates. There are other ways to achieve the same goal, but once achieved, the way you hold your device won't matter for measuring vertical motion.

无论哪种情况,轴您正在寻找的是y轴,而不是z轴。

In either case, the axis you're looking for is the y axis, not the z axis.

(如果有可能您将沿设备y轴的意思是垂直,那么忽略所有方向性,只使用线性加速度传感器)

(If by any chance you meant "along device y axis" as "vertical", then just ignore all the orientation stuff and just use the linear acceleration sensor)

您提到了一些有关噪声的问题并更新问题的速率,所以我在这里只提及它。从经常变化的事物中获得良好,一致的数据的最简单,最常见的方法之一就是使用低通滤波器。哪种类型的过滤器最好取决于应用程序,但是我发现指数移动平均值过滤器在大多数情况下是可行的。

You mentioned some problems regarding noise and update rates in the question, so I'll just mention it here. The simplest and one of the more common ways to get nice, consistent data from something that varies very often is to use a low-pass filter. What type of filter is best depends on the application, but I find that a exponential moving average filter is viable in most cases.

请注意,如果您妥善照顾了方向,转换后的线性加速度输出将很好地近似于垂直运动(很好,运动变化),而没有过滤任何噪声。

Note that if you take proper care of the orientation, your transformed linear acceleration output will be a good approximation of vertical motion (well, change in motion) without filtering any noise.

此外,如果您要测量垂直 运动,与速度一样,您需要对加速度计输出进行积分。由于种种原因,虽然在速度情况下比在尝试测量位置时要轻一些,但在大多数情况下并不能很好地解决问题。

Also, if you want to measure vertical "motion", as in velocity, you need to integrate the accelerometer output. For various reasons, this doesn't really turn out too well in most cases, although it is less severe in the case of velocity rather than trying to measure position.

这篇关于垂直运动传感器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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