erratic world origin/alignment for ARSessionConfiguration.WorldAlignment = .gravityAndHeading

Viewed 1845

[Note: this question was written against the beta version of ARKit during the iOS11/High Sierra prerelease period. Preserved for historical interest only]

I'm seeing erratic placement and orientation for the world origin when I set the ARWorldTrackingSessionConfiguration.worldAlignment to .gravityAndHeading.

The position of the origin is steady after the scene opens. But the axes are often rotated 180 degrees or 90 degrees around the Y axis.

Is there an additional setting I'm missing? I'm running a 2017 iPad (vanilla, not Pro) and Xcode 9 beta 2. I've tested a few compass apps on this iPad and they give me correct results, so I believe the hardware is working correctly.

override func viewDidLoad() {
    super.viewDidLoad()
    
    // Set the view's delegate
    sceneView.delegate = self
    
    // Show statistics such as fps and timing information
    sceneView.showsStatistics = true
    
    // Create a new scene
    let scene = SCNScene()

    // debug options
    let debugOptions: SCNDebugOptions = [ARSCNDebugOptions.showFeaturePoints,ARSCNDebugOptions.showWorldOrigin]
    sceneView.debugOptions = debugOptions

    // Set the scene to the view
    sceneView.scene = scene
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    
    // Create a session configuration
    let configuration = ARWorldTrackingSessionConfiguration()
    configuration.worldAlignment = .gravityAndHeading
    configuration.planeDetection = .horizontal

    // Run the view's session
    sceneView.session.run(configuration)
}

Here are some samples (in all of them I'm facing south).

Positive X and Z point west and north (incorrect, 180 degrees out of phase):

enter image description here

Positive X and Z point east southeast and south southwest (close to correct):

enter image description here

Positive X and Z point east and south (correct), but origin is displaced a couple of meters:

enter image description here

Positive X and Z point south and west (90 degrees out of phase):

enter image description here

From the .gravityAndHeading documentation:

The y-axis matches the direction of gravity as detected by the device's motion sensing hardware; that is, the vector (0,-1,0) points downward.

The x- and z-axes match the longitude and latitude directions as measured by Location Services. The vector (0,0,-1) points to true north and the vector (-1,0,0) points west. (That is, the positive x-, y-, and z-axes point east, up, and south, respectively.)

4 Answers

I realize this is an old thread, however even with ARKit 2 release and I am using iOS 12, Xcode 10.1 with iPhone 8, I am still getting inconsistent world origin. In some cases where the blue line should be pointing to South, it is actually pointing to East or West.

I did try Sander's suggestion by using the location manager heading, but it is still not 100% guarantee I am getting the right direction to begin with.

Anyone has any other suggestion?

I am getting occasional random world origin, where Y axis is NOT aligned with gravity, but is at maybe a 45 degree tilt. This is on Xcode 9.1 (beta) and iOS 11.0.3. If I reset the session, it redetects the Y axis correctly. (I am using gravityAndHeading).

As for heading, I am in a new downtown multi-story metal/brick/stucco building. Indoor Magnetic North detection is almost impossible. I have tested this extensively with many different devices. (I was doing drone navigation). The symptom was a floating north due to extremely low magnetic field. So sometimes it worked, but could change even +-90degrees in a few seconds.

It looks like you are testing indoors, with some brick walls...

I faced up with the same issue. My suggestion as a workaround to use CLLocationManager's delegate method to get true north

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading)

In my experiments is shows more stable and correct results, although sometimes they are as wrong as .gravityAndHeading 's north.

No additional settings for this app are required. Your code is OK.

As you quoted from .gravityAndHeading documentation – longitude and latitude directions measured by Location Services. There is definitely a bug touching Location Services in Xcode 9 beta. I stumbled upon the same issue one year ago.

But now, when I'm using official release of Xcode 10, everything works fine. I tested it more than hundred times in different places (indoor and outdoor). A deviation from the true compass values is +2/-2 degrees.

Tested on iPhone X (MQA82LL) in iOS 12 (16A366).

macOS Mojave 10.14 (18A391), Xcode 10.0 (10A255).

Also, read this useful and informative article: Requesting Always Authorization. There are many tips.

enter image description here

Related