I’m developing for Honeycomb Gingerbread and I was wondering, which physical sensors are used when I use the Sensor.TYPE_ROTATION_VECTOR?
Does it use a combination of compass and accelerometers? Or gyro + accel? Or all three? Or something else?
The reason I’m asking is that my app behaves differently on two different pieces of hardware, and they should actually have the same type of sensors.
I realize it’s been a while since the question was asked, but I don’t see a clear answer, so…
It uses all three sensors if they’re available. The use of magnetic field sensor is crucial to have some absolute point of reference. The “rotation sensor” needs to initially orient itself and then eliminate the drift that gyro introduces over time. Gyro is still used because of it’s precision and good response time. The accelerometer helps determine the gravity vector.
For you phone to know the orientation, including azimuth, you need to reference a plane in the real world.
That plane is calculated from two non co-linear vectors: Gravity (Accelerometer) and Magnetic fields forces. This vectors DO GET co-linear at two “places” on earth, but fortunately that is near the earth poles.
With the Magnetic and Accelerometer you are able to get the orientation.
Unfortunately if you submit your phone to any linear acceleration, or if there is magnetic disturbances the measures get noisy.
The use of a Gyroscope dramatically improves response time/accuracy (since it is a tradeoff), but it is not essential for all applications.
It looks like it uses any sensors that you define to be used with your SensorManager. In turn the sensor manager will broadcast the sensor event that your code will be listening for.
Look at the demo code below to see an example.
From https://source.android.com/devices/sensors/sensor-types.html, which are the specs device OEMs use to implement the various Android sensor types:
Rotation vector (SENSOR_TYPE_ROTATION_VECTOR) – Underlying physical sensors: Accelerometer, Magnetometer, and Gyroscope…It is usually obtained by integration of accelerometer, gyroscope, and magnetometer readings…Underlying physical sensors –
Accelerometer, Magnetometer, AND (when present) Gyroscope.
Game rotation vector (SENSOR_TYPE_GAME_ROTATION_VECTOR) – Underlying physical sensors: Accelerometer and Gyroscope (no Magnetometer). A game rotation vector sensor is similar to a rotation vector sensor but not using the geomagnetic field. Therefore the Y axis doesn’t point north but instead to some other reference. That reference is allowed to drift by the same order of magnitude as the gyroscope drifts around the Z axis…Underlying physical sensors –
Accelerometer, Gyroscope MUST NOT USE Magnetometer.
Geomagnetic rotation vector (SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR) – Underlying physical sensors: Accelerometer and Magnetometer (no Gyroscope). A geomagnetic rotation vector is similar to a rotation vector sensor but using a magnetometer and no gyroscope. This sensor must be based on a magnetometer. It cannot be implemented using a gyroscope, and gyroscope input cannot be used by this sensor…Underlying physical sensors – Accelerometer, Magnetometer, MUST NOT USE Gyroscope.
When there is no gyroscope on the device, and only when there is no gyroscope, you may implement the rotation vector, linear acceleration and gravity sensors without using the gyroscope.
So the exact implementation can vary by device – some devices may not have Gyroscopes.