google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.97k stars 1.22k forks source link

Feature Request: Provide a geo-oriented world coordinate space #119

Open mrrichardli opened 6 years ago

mrrichardli commented 6 years ago

hi,guys, I'm developing an demo about ar navigation based on arcore, in which , i need to transform a set of (latitude,longtitude) s to anchors in arcore. as we know, if we get latlng1 and latlng2, we can calculate the real distance between them and the angle between vector( latlng1,latlng2) and the north direction. so if the worldcoordinate in arcore can be configed to that the origin of the coordinate is the the device position now, and the y axis is parallel to gravity , z axis is parallel to true north direction, x axis is parallel to east direction, our function will be very easy to implement. I haven't found where to config for the scene mentioned above in javadoc. is there any solutions for the current version of arcore? @jguomoto @inio @gordonbrander @eitanme @richlowenberg Meanwhile , i found that arkit support the config now .

https://developer.apple.com/documentation/arkit/arconfiguration.worldalignment/2873776-gravityandheading

edit by @inio: replaced inline screenshot of ARKit documentation with link.

inio commented 6 years ago

the ARCore world coordinate space always has +Y pointing up relative to gravity. Currently we do not provide any global orientation of the X/Z axes, though you may be able to work something out using the magnetometer sensor (on devices that have one) on your own.

Note: to get a device pose (coordinate system of the magnetometer), you'd need to rotate frame.getDisplayOrientedPose() by the opposite of the current display rotation. Something like this seems to work on my Pixel:

static final float sqrtHalf = (float) Math.sqrt(0.5f);
....
Pose deviceOrientedPose = frame.getCamera().getDisplayOrientedPose().compose(
    Pose.makeInterpolated(
        Pose.IDENTITY, 
        Pose.makeRotation(0, 0, sqrtHalf, sqrtHalf),
        mDisplayRotationHelper.getRotation()));

The makeRotation call produces a 90° rotation about the Z axis, and makeInterpolated is effectively doing transform exponentiation to turn that into a 0°, 90°, 180°, or 270° rotation based on the current display rotation.

mrrichardli commented 6 years ago

i still have some confusions

1、about the rotation

public Pose (float[] translation, float[] rotation) Rotation is a quaternion following the Hamilton convention. Assume the destination and local coordinate spaces are initially aligned, and the local coordinate space is then rotated counter-clockwise about a unit-length axis, k, by an angle, theta. The quaternion parameters are hence: x = k.x sin(theta/2) y = k.y sin(theta/2) z = k.z * sin(theta/2) w = cos(theta/2)

is k a vector or a number, what's the meaning of it? the param (x,y,z) mean the axis rotate by and w mean the angle rotate?

2、about the deviceOrientedPose

2.1 dose the deviceOrientedPose mean the device heading from the true north direction

2.2 sqrtHalf. why do we use it in calvulate rotation quaternian

2.3 display.getrotation only return the display rotation values, not the device heading, so it's useless to calculate the vector to transfrom from true north to the device heading pose.

sorry , articles about arcore development is rare, my problems are a little bit too much, thank you very much if you can help me to understand the arcore system. @inio

inio commented 6 years ago

@mrrichardli

  1. k is, as described "a unit-length axis". That's the axis about which to rotate.

2.1. deviceOrientedPose just lets you put sensor values (e.g. magnetometer) into the ARCore coordinate space. By applying the rotation portion of this pose (.extractRotation()) to sensor readings you can get those readings in the world coordinate space instead of device coordinates.

2.2 Just an artifact of the way quaternions work. A 90° rotation quaternion about an axis will always have two values zero and two values sqrt(1/2).

2.3 as described above, it's needed to get device oriented pose. ARCore only provides display and camera oriented poses right now.

lee-carnevale commented 6 years ago

Please add this feature to the 1.0 release. Correct real world north alignment should be handled by the system. ARKit already implements this successfully.

abbana commented 6 years ago

+1 for this. Need to port the arkit app in arcore.

inio commented 6 years ago

Here's a helper class that aggregates magnetometer data in world space and example use orienting a compass needle:

https://github.com/inio/arcore-android-sdk/commit/e829c05cef0b42f882a7b896e41f66f311fffb71

This sample code is not an official release and is totally unsupported.

abbana commented 6 years ago

@inio It's a good start Inio ! Thanks a lot for that. Will test in the next weeks.

kdk96 commented 6 years ago

Please add this feature in upcoming release, cause it's really needed

ta10212 commented 6 years ago

I second that of @kdk96 . @inio , is this on the radar for an upcoming release of ARCore? On a different note, thank you very much for all your contributions thus far. You and the AR team are doing some pretty incredible work.

inio commented 6 years ago

We're looking at it. It's likely to show up as more formal sample code at some point, but becoming a first-class part of the ARCore API is looking unlikely. There's too much variation in magnetometer behavior across our supported device set, and using the magnetometer also can require user interaction to calibrate before you start getting good data.

ta10212 commented 6 years ago

Thanks @inio , I suppose ARKit has the luxury of fewer devices to support. Appreciate the quick response and look forward to more formal sample code in the future.

inio commented 6 years ago

For people using the above linked code, as of ARCore 1.3 CompassHelper.getDevicePose() can be replaced with Frame.getAndroidSensorPose().

morevar commented 6 years ago

@mrrichardli hello, have you finished the ar navigation demo? i have the same issue now.

AlexeyZatsepin commented 6 years ago

Thanks @inio, awesome compass demo! I can not understand how it works, mDisplayRotationHelper.getRotation() always returns 0. And why we rotate around Z axis? I tried to get euler angles from result Pose and it have some mismatching (yaw is pitch, pitch is roll, roll is yaw).

image

How can I rotate coordinate system to force Y axis to true north?

dev-aritra commented 5 years ago

@inio anything official yet?

inio commented 5 years ago

@AlexeyZatsepin Can't help with your earlier questions, but in ARCore +Y is always up.

@dev-aritra Nope.

dev-aritra commented 5 years ago

@inio So I figured if I align my model in the ARCore scene according to the phone's Pose, and then calculate the magnetic orientation of the phone and rotate my model accordingly, that solves my problem. In order to do that I was using the Magnetometer sensor, but observed if I take a clockwise spin around the y-axis, the values changes like this 0(at 0 degrees) --> -45(at 90 degrees) --> 0 (at 180 degrees ) --> 33 (at 270 degrees )--> 0 Why is it 45 on 90 but only goes max up to 33 in 270? Is this supposed to be like this only? P.S. I tested on Pixel and S8 Edge And values differ by a small margin on different devices, in your idea how to tackle this problem? And what sensor would you use? Anything from you would help a lot 👍

AlexLiuSheng commented 5 years ago

Please add this feature in upcoming release, cause it's really needed

ghost commented 5 years ago

@nvictornvictor @fredsa @inio Will this feature be released in the upcoming Arcore 2.0? Can we know when to release Arcore 2.0? Because this feature is really needed.

nhatvuminh commented 3 years ago

@nvictornvictor @fredsa @inio Anything up to date?

telpat0298 commented 1 year ago

Any news on this issue? It was opened 5 years ago...

barbeau commented 1 year ago

Check out the ARCore Geospatial API: https://developers.google.com/ar/develop/geospatial

telpat0298 commented 1 year ago

Thx @barbeau. But enabling the geospatial api by generating an api key, enabling location services and adding other gradle dependencies seems a little excessive for just wanting to know where north is. I did it my self now with the device sensors. But i guess it would be an easy addition for ArCore. ARKit's already doing it

KonradTHOC commented 2 months ago

Thx @barbeau. But enabling the geospatial api by generating an api key, enabling location services and adding other gradle dependencies seems a little excessive for just wanting to know where north is. I did it my self now with the device sensors. But i guess it would be an easy addition for ArCore. ARKit's already doing it

Excuse me for interrupting. I'm also facing a similar issue, and I was wondering if you could share how you solved it? If it's not convenient to share here, would you mind emailing me at 411185826@qq.com? Thank you very much.

Could you also share your solution with me? konrad.jurkowski16@gmail.com