本文介绍了振动加速度,使给错误的价值观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的应用程序,acceleremoter值读取(对X,Y和Z轴)。但是,对于某些值i编程震动我的手机。所以每当发生振动加速度值闪烁高度上下范围。我想避免这种情况。请给我的想法如何prevent加速时给人以振动模式不同的结果。

I have simple app that reads acceleremoter values (for x,y and z axis). But for certain value i vibrate my phone programatically. So whenever vibration occurs accelerometer value flickers highly up and down in range. I want to avoid this. Please give me idea how to prevent accelerometer giving varying result when in vibration mode.

public void onSensorChanged(SensorEvent event) {

if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
return;
         switch (mDisplay.getRotation()) {
                case Surface.ROTATION_0:
                    x = event.values[0];
                    y = event.values[1];
                    break;
                case Surface.ROTATION_90:
                    x = -event.values[1];
                    y = event.values[0];
                    Log.i("ROT: ", "90");
                    break;
                case Surface.ROTATION_180:
                    x = -event.values[0];
                    y = -event.values[1];
                    break;
                case Surface.ROTATION_270:
                    x = event.values[1];
                    y = -event.values[0];
                    break;
            }
}

感谢。

推荐答案

您可以使用一个低通滤波器,这样就可以filtate高的震撼。
事情是这样的:

You could use a low pass filter, so that you can filtate the high shakings.Something like this:

float lastAccel[] = new float[3];
float accelFilter[] = new float[3];
     accelFilter[0] = (float) (alpha * (accelFilter[0] + accelX - lastAccel[0]));
        accelFilter[1] = (float) (alpha * (accelFilter[1] + accelY - lastAccel[1]));
        accelFilter[2] = (float) (alpha * (accelFilter[2] + accelZ - lastAccel[2]));

这篇关于振动加速度,使给错误的价值观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 13:13