Android的去除加速度计读数重力 [英] android remove gravity from accelerometer readings

查看:763
本文介绍了Android的去除加速度计读数重力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Android开发的应用程序,我需要从加速度计读数删除引力。我已阅读关于这个问题的讨论多,我还发现了一个算法<一href="http://developer.android.com/reference/android/hardware/Sensor.html#TYPE_ACCELEROMETER">here,但我并没有真正了解它。

I am developing an application for Android where I need to remove gravity from accelerometer readings. I have read multiple discussions on this problem, I have also found an algorithm here, but I didn't really understand it.

欲从各轴过滤重力,而不是从总加速度

I want to filter gravity from each axis, not from the total acceleration.

能否请你帮我吗?我的code应该是这样的:

Could you please help me out? My code should be something like:

public void onSensorChanged(SensorEvent sensorEvent) {
    float vals[] = sensorEvent.values;
    float accelerationX = filterGravity(vals[0]);
    float accelerationY = filterGravity(vals[1]);
    float accelerationZ = filterGravity(vals[2]);
}

我应该在filterGravity()方法有何code?

What code should I place in the filterGravity() method?

推荐答案

有关你需要一个低通滤波器其他方法,如卡尔曼滤波器是关于背后的数学pretty的艰难。一个简单的例子为Android是点击远离你的链接<一个href="http://developer.android.com/reference/android/hardware/SensorEvent.html#values">http://developer.android.com/reference/android/hardware/SensorEvent.html#values.

For a basic solution you would need a low pass filter other approaches like a Kalman filter are pretty tough regarding the maths behind. A simple example for Android is one click away from your link at http://developer.android.com/reference/android/hardware/SensorEvent.html#values.

简单的讲一个低通滤波器,建立从您的所有历史价值的加权平均值。如果你有例如0.1滤波系数就意味着你的当前值的10%将被添加到previous平均值:中oldMeanValue的到currentValue + 90%newMeanValue = 10%。这意味着,即使有一个突然的峰只会慢慢推因为10%的的平均值。

Simply spoken a low pass filter builds a weighted average from all your history values. If you have for example a filtering factor of 0.1 it means that 10% of your current value is added to the previous mean value: newMeanValue = 10% of currentValue + 90% of oldMeanValue. That means even if there is an abrupt peak it will only push your mean value slowly because of the 10%.

这篇关于Android的去除加速度计读数重力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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