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

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

问题描述

我正在开发一个需要检测垂直运动的 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?

这是我想要检测的:

请为您认为的‘向上移动’提出一个数学上合理的定义."这是我最初的问题,如何编写函数来定义平板电脑何时向上或向下移动?我考虑向上移动的垂直平移.现在我该如何检测?我简直不知道从哪里开始,谢谢.

"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.

陀螺仪中的 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天全站免登陆