MMS • Sergio De Simone
Article originally posted on InfoQ. Visit InfoQ
The Fused Orientation Provider (FOP) is a new Android API that uses signals from motion sensors embedded in a smartphone to provide consistent and reliable device orientation. FOP is distributed through Google Play Services and is available on all devices running Android 5, independently from their manufacturers.
The main advantage of using FOP is its ability to mix signals from the magnetometer to those coming from the accelerometer and gyroscope, which were already used for the Android Rotation Vector. Similarly to FOP, the rotation vector reports orientation using quaternions, whose main benefit is they work correctly even when the rotation vector gets close to 90 or -90 degrees.
The FOP then outputs a stream of the device’s orientation estimates as quaternions. The orientation is referenced to geographic north. In cases where the local magnetic declination is not known (e.g., location is not available), the orientation will be relative to magnetic north. In addition, the FOP provides the device’s heading and accuracy, which are derived from the orientation estimate.
Although Google says FOP does not replace the rotation vector, they designed the new API to make it easier for developers to adopt it.
To use the new Fused Orientation Provider, you subscribe to the requestOrientationUpdates service by providing a DeviceOrientationRequest where you specify a desired frequency range for the updates.
Updates are sent to a DeviceOrientationListener that updates the state of your app. The choice of the update frequency is especially crucial for power consumption, since too a high frequency might significantly increase battery usage. If you do not know which update period to use, Google suggests starting with DeviceOrientationRequest::OUTPUT_PERIOD_DEFAULT
, which shall fit most use cases.
Additionally, FOP can compensate for lower-quality sensors and other OEM-related variations. As usual in the Android ecosystem, there exists a wide variety of hardware sensors available, differing in accuracy, speed, sensitivity to interference, and so on. To improve sensor performance, FOP performs a number of tasks, such as synchronizing sensors, compensating for magnetometer bias and gyroscope drift, and more.
FOP is only available on devices that include an accelerometer, a gyroscope, and a magnetometer. Furthermore, it does not support sending orientation updates to apps running in the background.