Device yaw in degrees using gyroscope.

synasir

Member
Licensed User
Longtime User
I am trying to determine the device's yaw in degrees using the gyro sensor on my S3. I am using Erel's sample code to get the gyro data but I have no idea on how to use the X,Y,Z data. Can anyone help me on this. Thanks!
 

MLDev

Active Member
Licensed User
Longtime User
The accelerometer can do that. Hold your device like a steering wheel and this will show the angle it's tilted.

B4X:
Sub Process_Globals
    Dim Accelerometer As PhoneAccelerometer
End Sub

Sub Globals
   Dim lblAngle As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
      lblAngle.Initialize("")
      lblAngle.TextSize = 20
      Activity.AddView(lblAngle, 40%x, 45%y, 20%x, 30dip)
    End If
End Sub

Sub Activity_Resume
    Accelerometer.StartListening("Accelerometer")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Accelerometer.StopListening
End Sub

Sub Accelerometer_AccelerometerChanged (X As Float, Y As Float, Z As Float)
   lblAngle.Text = "Angle = " & Round(ATan2D(Y, X))
End Sub
 
Last edited:
Upvote 0

synasir

Member
Licensed User
Longtime User
The accelerometer can do that. Hold your device like a steering wheel and this will show the angle it's tilted.

B4X:
Sub Process_Globals
    Dim Accelerometer As PhoneAccelerometer
End Sub

Sub Globals
   Dim lblAngle As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
      lblAngle.Initialize("")
      lblAngle.TextSize = 20
      Activity.AddView(lblAngle, 40%x, 45%y, 20%x, 30dip)
    End If
End Sub

Sub Activity_Resume
    Accelerometer.StartListening("Accelerometer")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Accelerometer.StopListening
End Sub

Sub Accelerometer_AccelerometerChanged (X As Float, Y As Float, Z As Float)
   lblAngle.Text = "Angle = " & Round(ATan2D(Y, X))
End Sub

Ok, thanks. Will try that.:sign0098:
 
Upvote 0
Top