1. Check out our app, Forums for Android! Download and leave feedback here!

Accelerometer results translation from phone to word orientation

Discussion in 'Application Development' started by ofer, Mar 6, 2010.

  1. ofer

    ofer New Member
    Thread Starter
    5

    Mar 6, 2010
    1
    0
    5
    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
     

    Advertisement

Share This Page

Loading...