Sensor values of TYPE_ROTATION_VECTOR aren't the same of different devices
Asked Answered
D

1

6

I'm using sensor data of type ROTATION_VECTOR in my app.

Using my Nexus 5 I can get azimuth from orientation[0] and can get the phones heading in the range shown in the picture below (it's very accurate).

Since I've tried my app on different devices, I found out that the sensor values differs from my Nexus 5 test device. On my Samsung Galaxy Nexus and on a Samsung Galaxy S3 Mini the azimuth is influenced by tilting the devices as shown in the picture.

Portrait Only - No Tilting to side

TYPE_ROTATION_VECTOR is using sensor fusion, that's why I checked the single sensor values on different devices with sensor test apps. On Nexus 5 the orientation values for z-axis are staying roughly the same when tilting the device, on Samsung Galaxy Nexus the value for z changed while tilting (about 90° from standing upright to lying). I fear that the sensor fusion is using these values and that's why my azimuth is different on different devices.

Does anyone experience a similar scenario and even more important: does anybody has a workaround or a different way to receive the azimuth?

Just to make sure, I looking for the direction, in which the back camera is pointing...

Here is my code:

final float[] mRotationMatrix = new float[9];
final float[] mRotationMatrixFromVector = new float[9];
final float[] orientation = new float[3];

...

SensorManager.getRotationMatrixFromVector(mRotationMatrixFromVector,
                event.values);

// enables usable range like in picture
SensorManager.remapCoordinateSystem(mRotationMatrixFromVector,
                        SensorManager.AXIS_X, SensorManager.AXIS_Z,
                        mRotationMatrix);

SensorManager.getOrientation(mRotationMatrix, orientation);
Dianoia answered 29/10, 2015 at 18:13 Comment(1)
I recommend that you should include Gyroscope sensor to your calculations.Procaine
T
0

You generally have three angles defining orientation, and to use them to project some distance outward, you have to use them all in the proper order, as you will be rotating your axis system. I answered a similar question here which may help you - there is some javascript code there which I left unoptimized to show the steps used in solving that problem.

Usually, azimuth is in the reference system of the earth, and you can just use it by itself. But that may not be so in all cases. If you suspect that your azimuth is being affected by the altitude, its probable (assuming they don't just have the numbers labelled wrong!) that the angles they are supplying you with are meant to be used in a different order, and you'll have to figure out which order they are being applied. Once you have the correct order, apply the three angles in that order (see my other answer), then the projection of the rotated X axis on the XY plane is the actual azimuth.

Thracian answered 17/10, 2018 at 19:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.