计算 Android 的 DeviceMotionEvent 值
我想使用 Android 的 SensorEvent 提供的值计算为 DeviceMotionEvent 指定的相同值。
我的问题是 Android 文档中引用 Gx、Gy、Gz 的部分:
public void onSensorChanged(SensorEvent event)
{
// alpha is calculated as t / (t + dT)
// with t, the low-pass filter's time-constant
// and dT, the event delivery rate
final float alpha = 0.8;
gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
linear_acceleration[0] = event.values[0] - gravity[0];
linear_acceleration[1] = event.values[1] - gravity[1];
linear_acceleration[2] = event.values[2] - gravity[2];
}
该代码中引用的 gravity 数组的值应该是什么?它还提到了 alpha ,但我仍然不明白它是什么/代表什么,方程是如何工作的(什么是低通滤波器?如何确定“时间常数”?什么是“交付率”甚至测量?),或者为什么它甚至被设置(非常任意)为 0.8。
我显然在物理系有所欠缺,但我懂数学。因此,如果有人愿意解释背后的物理推理,我将非常感激。我知道我链接的页面上有对术语的解释,但它们在我的脑海中仍然没有任何意义,除非这些术语与设备沿哪个轴加速或围绕哪个轴旋转的图片相匹配。
I'd like to use the values that Android's SensorEvent provides to calculate the same values that are specified for DeviceMotionEvent.
My problem is the part in the Android documentation that refers to Gx, Gy, Gz:
public void onSensorChanged(SensorEvent event)
{
// alpha is calculated as t / (t + dT)
// with t, the low-pass filter's time-constant
// and dT, the event delivery rate
final float alpha = 0.8;
gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
linear_acceleration[0] = event.values[0] - gravity[0];
linear_acceleration[1] = event.values[1] - gravity[1];
linear_acceleration[2] = event.values[2] - gravity[2];
}
What are supposed to be values of the gravity
array referenced in that code? It also mentions alpha
, but I still don't understand what it is/represents, how the equation works (What's a low-pass filter? How do you determine the "time-constant"? What's the "delivery-rate" even measuring?), or why it was even set (quite arbitrarily) to 0.8.
I'm obviously lacking in the physics department, but I understand the math. So if someone would be so kind to explain the physics reasoning behind, I would be much obliged. I know that there are explanations of the terms on the pages I linked, but they still hold no meaning in my mind except that the terms match pictures of which axes the device is acceleration along or rotating around.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个低通数字滤波器。它用于以简单的方式消除振动(高频信号)。
Alpha 介于 0 和 1 之间。 Alpha 越高,消除的振动就越多(您更相信重力的历史值),另一方面,重力值会高度延迟。
您可以在此处了解更多信息:http://en.wikipedia.org/wiki/Low-pass_filter ,看离散时间实现部分。
This is a low-pass digital filter. It is employed for removing vibrations (high-freq signals) in a simple way.
Alpha is between 0 and 1. The higher alpha the more vibrations are removed (you trust more in the historical values of gravity), on the other hand the gravity value is highly delayed.
You have more information here: http://en.wikipedia.org/wiki/Low-pass_filter , look at Discrete-time realization section.