Android 获得标准化加速

发布于 2024-12-22 11:16:54 字数 216 浏览 0 评论 0原文

我希望获得 Android 手机的加速度矢量。问题是,加速度计坐标是相对于手机的旋转的。我想要的是“绝对”加速度,即无论手机面向哪个方向,它都应该返回相同的值。 (我想检测滑雪的用户是否在不使用 GPS 的情况下滑下斜坡。我还需要能够区分滑动和上升缆车。)

我可以通过将加速度计与陀螺仪结合起来获得这些值,但我不知道如何用陀螺仪的值抵消加速度计的值。

这可能吗?如果可能的话,如何实现?

I wish to get the acceleration vector of an Android phone. The problem is, the accelerometer coordinates are relative to the phone's rotation. What I want is the "absolute" acceleration, i.e., it should return the same values whichever way the phone is facing. (I want to detect if a user that is skiing is sliding down a slope without using GPS. I also need to be able to differentiate sliding and going up the chairlift.)

I can probably get those values by combining the accelerometer with the gyroscope, but I have no idea how I could offset the accelerometer's values with the gyroscope's.

Is this possible, and if so, how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

任谁 2024-12-29 11:16:54

你所描述的事情是无法完成的,除非你重新定义一下问题。为了帮助您重新定义它,我将概述主要问题:

首先,我猜测您所说的“绝对加速度”是相对于地理参考的加速度。仅使用加速度计无法完成此操作,因为它不知道地理参考。如果你移动得足够远,可以使用 GPS,或者使用指南针,你也许可以解决这个问题,但每个问题都有自己的问题(尽管至少问题是可以解决的)。

第二个问题是,仅使用加速度计完全无法区分重力和加速度(这称为“等效原理”)。因此,任何测量到的加速度始终是重力和加速度的矢量和,但这些方程总是有多个解,并且在加速度小于重力的通常情况下,您实际上无法确定有关加速度的任何信息。由于重力在某种程度上是恒定的,因此也有一些方法可以解决这个问题,例如使用陀螺仪,或者您的用户可以将手机保持在固定方向(例如,通过查看地平线等外部提示),并且这些方法中的任何一个方法可能会让你减去重力的影响,但这通常是一个不小的问题。

最后一点是,您似乎在地球固定的坐标系中思考,而手机的加速度计只是手机固定的。也就是说,加速度计的 z 轴与地球上的上下没有任何关系,而这种关系将取决于手机的方向。确实,许多人更喜欢地球固定系统,但手机却不知道这一点。您可以使用外部提示(GPS、磁场、陀螺仪、重力、地平线等)来尝试对齐它们,但仅给出加速度计的单个任意读数,则信息不存在。

定义:
加速度矢量:这是加速度计的 x、y、z 读数(每个读数取决于手机方向),有时写为 A=(ax, ay, az)。
加速度大小:这是a=sqrt(ax2 + ay2 + az2),这不应该取决于手机方向(如果不同的轴校准为相同)。如果手机是静止的,这基本上只是重力读数。另请注意,使用此方法会丢失加速度矢量中的许多信息。
归一化加速度:加速度方向,大小为1,,A/a
地球坐标中的加速度:我认为这是你真正想要的,只是没有简单的方法来获得它,而且即使你可以,我认为它也不会那么有用乍一看。

滑雪
我认为您可以根据加速度计的测量结果确定某人何时在滑雪。使用加速度计,诸如颠簸和转弯之类的事情都应该非常独特。对于这些,我将使用完整的加速度矢量。例如,反过来,加速度大小将保持大致恒定,而方向将扫过。还要注意自由落体(即,基本上只要滑雪者的天空/脚/屁股/等不在地面上,无论他们是在撞击/跳跃时向上,还是从缆车上掉下来) ,自由落体时加速度大小为零。对于缆车来说,它似乎很可能在一个平面内有独特的节奏摇摆。

所有这些事情都可以弄清楚。如果你真的想解决这个问题,我建议你在滑雪时记录加速度计的数据,看看是否可以根据数据的特征来确定你何时在滑雪。 (我的猜测是,你的主要障碍将是数学,因为想出一种可以区分滑雪特征的算法可能有点棘手,所以似乎回顾一下向量是个好主意数学,以及点积和叉积之类的东西,而且,我怀疑另一个称为 FFT 或傅立叶变换的主题可能有助于整理滑雪与椅子上摇摆的时间和频率特征升力。)

您还可以折叠 GPS 测量值,这不太可靠,或者提供良好的时间分辨率,但至少可以用来仔细检查您的算法。

What you describe can't be done, unless you redefine the problem a bit. To help you redefine it, I'll outline the main issues:

First, I'm guessing that what you mean by "absolute acceleration" is acceleration with respect to geographical reference. The can't be done with the accelerometer alone, since it has no idea about geographical references. If you move far enough for the gps, or use the compass, you might be able to get around this, but each of these has its own issues (though at least the problem is soluble).

The second issue is that gravity and acceleration are completely indistinguishable using an accelerometer alone (this is known as the "equivalence principle"). Therefore, any measured acceleration will always be the vector sum of gravity and the acceleration, but there are always multiple solutions to these equations, and in the usual cases where the acceleration is smaller than gravity, you really can't determine anything about the acceleration. Since gravity is somewhat constant though, there are ways around this too, using, say, a gyroscope, or maybe your user could hold the phone in a fixed orientation (e.g., by looking at external cues like the horizon), and either of these approaches might let you subtract the influence of gravity, but it's generally a non-trivial problem.

The final point to not is that you seem to be thinking in an earth-fixed coordinate system and the phone's accelerometer is only phone-fixed. That is the accelerometer's z-axis many not have anything to do with up and down on the earth -- and the relationship will depend on the orientation of the phone. Really, many people would prefer an earth-fixed system, but the phone just doesn't know that. You can use external cues (GPS, magnetic field, gyroscope, gravity, horizon, etc) to try to align them, but given only a single arbitrary reading form the accelerometer, the information just isn't there.

Definitions:
acceleration vector: this is the x, y, z reading from the accelerometer (and each reading will depend on the phones orientation), sometimes written as A=(ax, ay, az).
acceleration magnitude: this is a=sqrt(ax2 + ay2 + az2), and this should not depend on the phones orientation (if the different axes are calibrated to be the same). If the phone is stationary, this will basically just be a reading of gravity. Note also that a lot of the information in the acceleration vector is lost using this measure.
normalized acceleration: The acceleration direction, that has magniture 1, i.e., A/a
acceleration in earth coordinates: I think this is what you really want, there's just no easy way to get it, and really even if you could, I don't think it would be as useful as it might seem at first.

Skiing:
I think you have a good shot at determining when someone is skiing based on the measurements from the accelerometer. Things like bumps and turns should all be quite distinctive using the accelerometer. For these I'd use the full acceleration vector. For example, in turns, the acceleration magnitude would stay roughly constant and the direction would sweep. Also note that free-fall (i.e., basically whenever the skier doesn't have their skies/feet/butt/etc on the ground, whether they're going upward when launching off a bump/jump, or falling out of the chairlift), the acceleration magnitude will be zero in free-fall. For the chairlift, it seems that it will likely have a distinctive rhythmic sway mostly within a single plane.

All of these things could be figured out. I'd recommend, if you really want to solve this problem, is to record data from your accelerometer while skiing, and see if you can determine when you're skiing based on the characteristics of the data. (My guess is, that your major stumbling block with this will be math, because it might be a bit tricky to come up with an algorithm the can distinguish the signatures of skiing, so it seems that it would be a good idea to review vector math, and things like dot-products and cross-products, and also, I suspect that a little bit on another topic known as FFTs or Fourier transforms might be useful in sorting out the time and frequency signatures of skiing vs swinging in the chair lift.)

You could also fold in GPS measurements, which wouldn't be as reliable, or give good time resolution, but could at least be used to double-check your algorithm.

眼藏柔 2024-12-29 11:16:54

无论手机的方向如何,您都可以使用以下方法计算加速度:

a = sqrt(x*x + y*y + z*z)

其中 a 是绝对加速度,xyz > 是手机 3 个轴中每个轴的加速度计值。

You can calculate acceleration regardless of the phone's orientation using:

a = sqrt(x*x + y*y + z*z)

Where a is the absolute acceleration and x, y and z are accelerometer values for each of the phone's 3 axes.

面如桃花 2024-12-29 11:16:54

有些手机内置了气压计(气压传感器)。应用移动平均值后,我发现它可以编写以确定用户是上升还是下降 - 也许对您的问题有用。在 Galaxy s4 和 5 上,我获得了足够好的分辨率来确定设备是否刚刚从桌子移到地板上。

请注意,天气的逐渐变化会影响您的读数,因此您必须考虑合理时间间隔内的 Delta,并忽略某个阈值附近的变化。

Some phones have a barometer (air pressure sensor) built in. After applying a moving average, I have found it to be write ready to determine if the user is going up or down -perhaps useful for your problem. On the galaxy s4 and 5 I get a resolution good enough to determine whether the device just moved from the table, to the floor.

Note, gradual changes in weather will affect your readings, so you must consider the Delta over a reasonable time interval, and ignore changes around some threshold.

旧梦荧光笔 2024-12-29 11:16:54

考虑使用 GPS。在飞行记录应用程序中,我使用加速度(尽管是绝对值,而不是矢量)来过滤嘈杂的 GPS 数据(我删除了速度变化所需的加速度不合理的位置):

/**
 * Remove noise from the measurement of the location.
 * @param loc a location
 * @return Answer <code>false</code> iff the location should not be used.
 */
private boolean filterNoise(final Location loc) {
    if( ! loc.hasSpeed() )
        return true;
    if( this.recentSpeeds.isEmpty() ) {  // rescentSpeeds is a queue of locations
        this.recentSpeeds.add(loc);
        return true;
    }
    final Location lastFix = this.recentSpeeds.getHead();
    final long delta_t = (loc.getTime() - lastFix.getTime()) / 1000;
    if( delta_t == 0 )
        return false;
    final float delta_v = loc.getSpeed() - lastFix.getSpeed();
    final float a = delta_v / delta_t;
    if( Math.abs(a) <= AccelThreshold ) {
        this.recentSpeeds.add(loc);
        return true;
    }
    return false;
}

如果您使用坐标计算速度从上次修复和当前修复中,您可以得到加速度矢量。

Consider using the GPS. In a flight logging app I use the acceleration (albeit the absolute value, not the vector) to filter noisy GPS data (I remove locations where the acceleration needed for the change in speed is not plausible):

/**
 * Remove noise from the measurement of the location.
 * @param loc a location
 * @return Answer <code>false</code> iff the location should not be used.
 */
private boolean filterNoise(final Location loc) {
    if( ! loc.hasSpeed() )
        return true;
    if( this.recentSpeeds.isEmpty() ) {  // rescentSpeeds is a queue of locations
        this.recentSpeeds.add(loc);
        return true;
    }
    final Location lastFix = this.recentSpeeds.getHead();
    final long delta_t = (loc.getTime() - lastFix.getTime()) / 1000;
    if( delta_t == 0 )
        return false;
    final float delta_v = loc.getSpeed() - lastFix.getSpeed();
    final float a = delta_v / delta_t;
    if( Math.abs(a) <= AccelThreshold ) {
        this.recentSpeeds.add(loc);
        return true;
    }
    return false;
}

If you compute the speed using the coordinates from the last fix and the current fix you get the acceleration as vector.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文