[HTML payload içeriği buraya]
34.3 C
Jakarta
Monday, May 11, 2026

Constant gadget orientation for all



Posted by Geoffrey Boullanger – Senior Software program Engineer, Shandor Dektor – Sensors Algorithms Engineer, Martin Frassl and Benjamin Joseph – Technical Leads and Managers

Machine orientation, or perspective, is used as an enter sign for a lot of use instances: digital or augmented actuality, gesture detection, or compass and navigation – any time the app wants the orientation of a tool in relation to its environment. We’ve heard from builders that orientation is difficult to get proper, with frequent person complaints when orientation is wrong. A maps app ought to present the proper route to stroll in direction of when a person is navigating to an thrilling restaurant in a international metropolis!

The Fused Orientation Supplier (FOP) is a brand new API in Google Play companies that gives high quality and constant gadget orientation by fusing indicators from accelerometer, gyroscope and magnetometer.

Though at the moment the Android Rotation Vector already gives gadget orientation (and can proceed to take action), the brand new FOP gives extra constant conduct and excessive efficiency throughout units. We designed the FOP API to be just like the Rotation Vector to make the transition as straightforward as doable for builders.

Specifically, the Fused Orientation Supplier

    • Supplies a unified implementation throughout units: an API in Google Play companies signifies that there isn’t any implementation variance throughout totally different producers. Algorithm updates could be rolled out shortly and unbiased of Android platform updates;
    • Straight incorporates native magnetic declination, if obtainable;
    • Compensates for decrease high quality sensors and OEM implementations (e.g., gyro bias, sensor timing).

In sure instances, the FOP returns values piped by way of from the AOSP Rotation Vector, tailored to include magnetic declination.

How one can use the FOP API

Machine orientation updates could be requested by creating and sending a DeviceOrientationRequest object, which defines some specifics of the request just like the replace interval.

The FOP then outputs a stream of the gadget’s orientation estimates as quaternions. The orientation is referenced to geographic north. In instances the place the native magnetic declination shouldn’t be identified (e.g., location shouldn’t be obtainable), the orientation will probably be relative to magnetic north.

As well as, the FOP gives the gadget’s heading and accuracy, that are derived from the orientation estimate. This is identical heading that’s proven in Google Maps, which makes use of the FOP as properly. We lately added modifications to higher deal with magnetic disturbances, to enhance the reliability of the cone for Google Maps and FOP purchasers.

The replace price could be set by requesting a selected replace interval. The FOP doesn’t assure a minimal or most replace price. For instance, the replace price could be quicker than requested if one other app has a quicker parallel request, or it may be slower as requested if the gadget doesn’t help the excessive price.

For full specification of the API, please seek the advice of the API documentation:

Instance utilization (Kotlin)

bundle ...

import android.content material.Context
import com.google.android.gms.location.DeviceOrientation
import com.google.android.gms.location.DeviceOrientationListener
import com.google.android.gms.location.DeviceOrientationRequest
import com.google.android.gms.location.FusedOrientationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.widespread.flogger.FluentLogger
import java.util.concurrent.Executors

class Instance(context: Context) {
  personal val logger: FluentLogger = FluentLogger.forEnclosingClass()

  // Get the FOP API consumer
  personal val fusedOrientationProviderClient: FusedOrientationProviderClient =
    LocationServices.getFusedOrientationProviderClient(context)

  // Create an FOP listener
  personal val listener: DeviceOrientationListener =
    DeviceOrientationListener { orientation: DeviceOrientation ->
      // Use the orientation object returned by the FOP, e.g.
      logger.atFinest().log("Machine Orientation: %s deg", orientation.headingDegrees)
    }

  enjoyable begin() {
    // Create an FOP request
    val request =
      DeviceOrientationRequest.Builder(DeviceOrientationRequest.OUTPUT_PERIOD_DEFAULT).construct()

    // Create (or re-use) an Executor or Looper, e.g.
    val executor = Executors.newSingleThreadExecutor()

    // Register the request and listener
    fusedOrientationProviderClient
      .requestOrientationUpdates(request, executor, listener)
      .addOnSuccessListener { logger.atInfo().log("FOP: Registration Success") }
      .addOnFailureListener { e: Exception? ->
        logger.atSevere().withCause(e).log("FOP: Registration Failure")
      }
  }

  enjoyable cease() {
    // Unregister the listener
    fusedOrientationProviderClient.removeOrientationUpdates(listener)
  }
}

Technical background

The Android ecosystem has all kinds of system implementations for sensors. Gadgets ought to meet the standards within the Android compatibility definition doc (CDD) and should have an accelerometer, gyroscope, and magnetometer obtainable to make use of the fused orientation supplier. It’s preferable that the gadget vendor implements the excessive constancy sensor portion of the CDD.

Although Android units adhere to the Android CDD, really helpful sensor specs usually are not tight sufficient to totally forestall orientation inaccuracies. Examples of this embody magnetometer interference from inner sources, and delayed, inaccurate or nonuniform sensor sampling. Moreover, the surroundings across the gadget often contains supplies that distort the geomagnetic area, and person conduct can fluctuate broadly. To take care of this, the FOP performs a variety of duties with a purpose to present a sturdy and correct orientation:

    • Synchronize sensors working on totally different clocks and delays;
    • Compensate for the laborious iron offset (magnetometer bias);
    • Fuse accelerometer, gyroscope, and magnetometer measurements to find out the orientation of the gadget on the planet;
    • Compensate for gyro drift (gyro bias) whereas shifting;
    • Produce a sensible estimate of the compass heading accuracy.

    We’ve got validated our algorithms on complete check information to offer a top quality end result on all kinds of units.

    Availability and limitations

    The Fused Orientation Supplier is obtainable on all units working Google Play companies on Android 5 (Lollipop) and above. Builders want so as to add the dependency play-services-location:21.2.0 (or above) to entry the brand new API.

    Permissions

    No permissions are required to make use of the FOP API. The output price is proscribed to 200Hz on units working API degree 31 (Android S) or greater, until the android.permissions.HIGH_SAMPLING_RATE_SENSORS permission was added to your Manifest.xml.

    Energy consideration

    All the time request the longest replace interval (lowest frequency) that’s enough to your use case. Whereas extra frequent FOP updates could be required for prime precision duties (for instance Augmented Actuality), it comes with an influence price. When you have no idea which replace interval to make use of, we advocate beginning with DeviceOrientationRequest::OUTPUT_PERIOD_DEFAULT because it suits most consumer wants.

    Foreground conduct

    FOP updates are solely obtainable to apps working within the foreground.

    Copyright 2023 Google LLC.
    SPDX-License-Identifier: Apache-2.0
    

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles