Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vibration makes accelerometer give wrong values

Tags:

android

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;
            }
}

Thanks.

like image 645
padam thapa Avatar asked Aug 28 '26 02:08

padam thapa


1 Answers

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]));
like image 165
Dany's Avatar answered Aug 29 '26 15:08

Dany's



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!