• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Accelerometer results translation from phone to word orientation

ofer

Lurker
Mar 6, 2010
1
0
Hi,
I have a problem with the translation of the accelerometer results
from the phone to the world orientation.
The Z results seem OK but the X and Y get wrong values.
It was tested in horizontal phone move.
Attached is the code.
public void onSensorChanged(SensorEvent event) {
synchronized (this) {
// Log.d("MotionTest", "sensor: " + sensor + ", x: " + values[0] +
", y: " + values[1] + ", z: " + values[2]);
int type = event.sensor.getType();
if(type == Sensor.TYPE_ACCELEROMETER) {
acceleValues = event.values.clone();
} else if (type == Sensor.TYPE_MAGNETIC_FIELD) {
magnetValues = event.values.clone();
} else if (type == Sensor.TYPE_ORIENTATION) {
orientValues = event.values.clone();
}
SensorManager.getRotationMatrix(mR, mI,
acceleValues ,magnetValues);
// SensorManager.getOrientation(mR, orientValues);
acceleEarthValues[0]=mR[0]*acceleValues[0]+mR[1]*acceleValues[1]+mR[2]*acce leValues[2];
acceleEarthValues[1]=mR[3]*acceleValues[0]+mR[4]*acceleValues[1]+mR[5]*acce leValues[2];
acceleEarthValues[2]=mR[6]*acceleValues[0]+mR[7]*acceleValues[1]+mR[8]*acce leValues[2];
}
drawData();
}
The mR and mI are defined as:
private float[] mR = new float[9];
private float[] mI = new float[9];
Please advice
Thanks
Ofer
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones