Android Question Compass and Tilt

synasir

Member
Licensed User
Longtime User
Dear everyone,

I am using the orientation sensor as my compass and my device is at #SupportedOrientations: landscape

PCMain.Initialize2(PCMain.TYPE_ORIENTATION, 0)
PCMain.StartListening("SensorCMain")

Sub SensorCMain_SensorChanged (Values() As Float)

Racc1 = Values(0)

End Sub

The code above works fine if the device is lying flat. If I were to tilt the device 90 degrees or more, the compass gets reversed. I know that I can use Javaobject remapCoordianteSystem to overcome this but I have no idea on how to get about doing this. I have been reading through the forums but I have no idea how to start.

Dim jo As JavaObject
jo.InitializeStatic("android.hardware.SensorManager")
jo.RunMethod("remapCoordianteSystem", Array(inR, X, Y, outR))


Thanks.
 

synasir

Member
Licensed User
Longtime User
Thanks for the prompt reply. I have seen the post. Do I need to change the sensors used to just orientation instead of magnetic and accelerometer?

Private Sub CalcOrientation
If accValues.Length = 0 Or magValues.Length = 0 Then Return
Dim R(9), I(9) As Float
Dim success As Boolean = smjo.RunMethod("getRotationMatrix", Array(R, I, accValues, magValues))
If success Then
Dim orientation(3) As Float
smjo.RunMethod("getOrientation", Array(R, orientation))
Azimuth = ((orientation(0) * 180 / cPI + 360) Mod 360)
End If
End Sub

Using the code as it with Azimuth as my compass data causes the compass to jump all over the place.
 
Upvote 0

synasir

Member
Licensed User
Longtime User
No.

Now that I read the following posts, I see that it will only return the correct values when the device is horizontally flat.

Thanks again for the prompt reply. The only solution now is the my device can be flat and can be tilted no more than 80 degree. Beyond that the compass will be reversed.

Any idea how to overcome this? Thanks
 
Upvote 0
Top