Reputation: 1477
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.
Upvotes: 3
Views: 748
Reputation: 928
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]));
Upvotes: 2
Reputation: 9209
I think that you'll be forced to ignore acceleration values whilst vibrating the phone.
Upvotes: 0