23

Android provides both the rotation vector sensor and the orientation sensor. I know they returns different data, because for vector sensor we have sin of angles, in orientation sensor we have angles. But what's the conceptual difference? I can't understand from the docs. Which one provides the orientation of the device in the three-dimensional space? I'm confused!

user1781028
  • 1,348
  • 3
  • 19
  • 44

4 Answers4

45

The older ORIENTATION sensors report orientation using three angles. The problem with this coordinate systems is that it suffers from "gimbal lock": when the actual orientation vector is close to vertical, one of the coordinates goes to 90 or -90 degrees, and the remaining two coordinates become either uninterpretable or dangerously denormalized.

The newer ROTATION sensors report orientation using quarternion coordinates, which are more complicated to work with, but don't suffer from the Gimbal lock problem. When orientation is reported using quaternion coordinates, you can determine the precise orientation of the device no matter what the orientation is.

Quaternions are also more computationally efficient. You don't need to call expensive trig functions to apply a quaternion rotation to a vector. If the w coordinate isn't supplied you can still compute w with a single sqrt call, compared to three sin and three cos function calls for orientation coordinates in the three angle Euler form.

Short story: the ORIENTATION-style sensors were done wrong. They were fixed in API 9, by replacing them with ROTATION sensors.

Hossein Sarshar
  • 486
  • 7
  • 15
Robin Davies
  • 6,889
  • 1
  • 29
  • 41
18

ROTATION_VECTOR sensor was introduced in API 9 and represents 'virtual' sensor which combines data from different sensors (usually ACCELEROMETER, GEOMAGNETIC_FIELD and GYROSCOPE) and does some smart calculations to provide more accurate data rather than using raw data from ACCEL and GEOMAGNETIC_FIELD sensors. This is called 'sensor fusion'. More info you can find here

ORIENTATION sensor is deprecated since it is providing not very accurate data. Documentation is suggesting to use raw data from ACCELEROMETER and GEOMAGNETIC_FIELD sensors instead.

Unfortunately, I cannot provide any examples how to use ROTATION_VECTOR sensor data since I'm in process of investigation right now :)

Just in case you need some examples how to use raw data - feel free to ask me - I'll post some examples, but simple googling can help you better ;)

Pavel Dudka
  • 19,968
  • 6
  • 65
  • 81
  • Ok, but I want to understand if they conceptually provide or not the same information, represented by the orientation of the device in the three-dimensional space. – user1781028 Jan 03 '13 at 15:58
  • Well, the output from these 2 sensors is definitely different. ORIENTATION sensor responds with the rotation around axes (so you can take values[0] f.i. to obtain rotation around X axis. ROTATION_VECTOR output is unitless - it represents much more complicated values. However, you can get the same array of values by calling simple set of helper functions to convert ROTATION_VECTOR output to rotation values around axes – Pavel Dudka Jan 04 '13 at 01:31
  • Yes, I know the output is "formally" different, but do you agree it represents the same conceptual information, that is the orientation of the device in the three-dimensional space? After all, they must be conceptually equal if they can be transformed in each other, do you agree? – user1781028 Jan 08 '13 at 11:41
  • It is possible that accuracy was improved in API-9; however on the API 16 and 18 devices I tested, both API's provide the same data (in different coordinate systems, of course). – Robin Davies Jan 13 '14 at 21:34
  • And yes, geomagnetic readings do appear to be merged in. Orientation results are affected by nearby metallic objects, and are therefore remarkably glitchy in indoor environments. Metal screws in a table-top can skew the results by 50 or 60 degrees on a small scale. A speaker 10 or 15 feet away (big magnet) pretty much dominates any reasonable sense of where north is if there are no nearby metal objects. – Robin Davies Jan 13 '14 at 21:41
0

They are conceptually same, just representationally different.

Have a look at the code of orientation sensor here. The parameter of the function for the orientation sensor is the rotation matrix, which inturn is calculated from the rotation vector(the quats representation)

matrixisreal
  • 193
  • 1
  • 7
0

On cheap Android phones (unlike higher end iPhones) compass will work only when the phone orientation is close to horizontal (i.e. parallel to ground surface).

Technically a good compass (i.e. a floating magnetic sphere) should work at any orientation but the cheap ones don't. Hence, to use a compass make sure that your phone is horizontal via looking at ACCELEROMETER before you use MAGNETOMETER. Hopefully Google will use better magnetometers in the future!

Vlad
  • 4,223
  • 1
  • 28
  • 38