A
A
alleks_ya2016-04-07 18:42:38
Java
alleks_ya, 2016-04-07 18:42:38

How to get the rotation angle in degrees?

How to learn the angle of rotation in degrees? Connected accelerometer and magnetic field sensor. Each sensor gives 3 values.

float[] valuesAccel = new float[3];
float[] valuesMagnet = new float[3];
float[] valuesAccelGravity = new float[3];
public void onSensorChanged(SensorEvent event) {
            switch (event.sensor.getType()) {
                case Sensor.TYPE_ACCELEROMETER:
                    for (int i = 0; i < 3; i++) {
                        valuesAccel[i] = event.values[i];
                        valuesAccelGravity[i] = (float) (0.1 * event.values[i] + 0.9 * valuesAccelGravity[i]);
                        valuesAccelMotion[i] = event.values[i]
                                - valuesAccelGravity[i];
                    }
                    break;
                case Sensor.TYPE_MAGNETIC_FIELD:
                    for (int i=0; i < 3; i++){
                        valuesMagnet[i] = event.values[i];
                    }
                    break;
            }

        }
 void getDeviceOrientation() {
        SensorManager.getRotationMatrix(r, null, valuesAccel, valuesMagnet);
        SensorManager.getOrientation(r, valuesResult);

        valuesResult[0] = (float) Math.toDegrees(valuesResult[0]);
        valuesResult[1] = (float) Math.toDegrees(valuesResult[1]);
        valuesResult[2] = (float) Math.toDegrees(valuesResult[2]);
        return;
    }

I need to get the angle of rotation from a given point, that is, we get up, look in one direction, then turn around and look in the other direction, this is the angle I need. What data to use for this? just started working with sensors.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question