ArcGisARView with compass not point to nord

479
1
Jump to solution
12-12-2022 08:55 AM
simone-vitale-overit
New Contributor II

Hello community,

I'm working on an Android App that use an ArcGISARView and to get the position of the device, I'm using

ArLocationDataSource

configured in this way:

var criteria = Criteria()
criteria.powerRequirement = Criteria.POWER_HIGH
criteria.accuracy = Criteria.ACCURACY_FINE
criteria.isSpeedRequired = true
criteria.isAltitudeRequired = false
criteria.isBearingRequired = true
criteria.isCostAllowed = true

val locationDataSource = ArLocationDataSource(this, criteria, 1000, 1.0F)

arSceneView.locationDataSource = locationDataSource

The localization work correctly, but in my Scene I show a Compass of the ESRI toolkit that I initialised in this way:

compass = Compass(this)
compass!!.isAutoHide = false
compass!!.addToGeoView(arSceneView.sceneView)

I have a strange behaviour by the compass, because not point on the north but I have a rotation of 20/30 degree respect to the real position of north, but not of the map, only of the compass, because the camera points to the real position in the world.

Someone have any idea of why I have this strange behaviour?

 

1 Solution

Accepted Solutions
simone-vitale-overit
New Contributor II

I found a solution by creating a custom LocationDatasource and making a method to manage what I have received onSensorChanged:

override fun onSensorChanged(event: SensorEvent) {
val type = event.sensor.type
if (type == Sensor.TYPE_ACCELEROMETER) {
gravity = lowPassFilter(event.values.clone(), gravity)
}

if (type == Sensor.TYPE_MAGNETIC_FIELD) {
geomagnetic = lowPassFilter(event.values.clone(), geomagnetic)
}

if(type == Sensor.TYPE_ROTATION_VECTOR)
{
val currentRotation = event.values
val rotationMatrix = FloatArray(9)
SensorManager.getRotationMatrixFromVector(rotationMatrix, currentRotation)
}

if(gravity != null && geomagnetic != null)
{
val R = FloatArray(9)
val outR = FloatArray(9)
val I = FloatArray(9)

val success = SensorManager.getRotationMatrix(R,I, gravity, geomagnetic)
if(success)
{
val orientation = FloatArray(3)
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, outR)
SensorManager.getOrientation(outR, orientation)
val azimut = orientation[0]
val azimutInDegree = (Math.toDegrees(azimut.toDouble()))%360
updateHeading(azimutInDegree)
}
}
}

 I hope that this solution help someone that has the same problem.

View solution in original post

0 Kudos
1 Reply
simone-vitale-overit
New Contributor II

I found a solution by creating a custom LocationDatasource and making a method to manage what I have received onSensorChanged:

override fun onSensorChanged(event: SensorEvent) {
val type = event.sensor.type
if (type == Sensor.TYPE_ACCELEROMETER) {
gravity = lowPassFilter(event.values.clone(), gravity)
}

if (type == Sensor.TYPE_MAGNETIC_FIELD) {
geomagnetic = lowPassFilter(event.values.clone(), geomagnetic)
}

if(type == Sensor.TYPE_ROTATION_VECTOR)
{
val currentRotation = event.values
val rotationMatrix = FloatArray(9)
SensorManager.getRotationMatrixFromVector(rotationMatrix, currentRotation)
}

if(gravity != null && geomagnetic != null)
{
val R = FloatArray(9)
val outR = FloatArray(9)
val I = FloatArray(9)

val success = SensorManager.getRotationMatrix(R,I, gravity, geomagnetic)
if(success)
{
val orientation = FloatArray(3)
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, outR)
SensorManager.getOrientation(outR, orientation)
val azimut = orientation[0]
val azimutInDegree = (Math.toDegrees(azimut.toDouble()))%360
updateHeading(azimutInDegree)
}
}
}

 I hope that this solution help someone that has the same problem.

0 Kudos