This post mentions:Is Phone Sensor Orientation Type X value ranges from 0 to 360? x seems a bit off. Do we have to calibrate it to have it set at x = 0 when phone is portrait mode?
which sounds like perhaps it relates to your question.I chose to use the accelerometer instead of orientation, as I found orientation to be very "noisy" and generally finicky to handle
angle x y -135 7 -7 -90 10 0 -45 7 7 0 0 10 45 -7 7 90 -10 0 135 -7 -7
'these were all globals in my test program so's could display them on screen Dim X, Y, Z As Float Dim R As Float Dim ArcSinX, ArcSinY, ArcCosX, ArcCosY As Float Dim Angle As Float Private Sub Accelerometer_SensorChanged (Values() As Float) X = Values(0) Y = Values(1) '''Z = Values(2) R = Sqrt(X * X + Y * Y ) 'length of gravity vector = approx. 9.8 ms-2 if no Z tilt If R > 1.234 Then 'arbitrary cut-off of orientation detection as phone is tilted towards flat horizontal '''ArcSinX = ASin(X / R) / cPI * 180 '''ArcSinY = ASin(Y / R) / cPI * 180 '''ArcCosX = ACos(X / R) / cPI * 180 ArcCosY = ACos(Y / R) / cPI * 180 If X < 0 Then Angle = ArcCosY 'returns angles 0 .. 180 Else 'choose one of the below, depending on whether prefer angles -180 .. 180 or 0 .. 360 Angle = -ArcCosY 'returns angles -180 .. 0 Angle = 360 - ArcCosY 'returns angles 180 .. 360 End If End If End Sub
Private Sub Accelerometer2_SensorChanged (Values() As Float) If blnSteeringMode = False Then Return Dim dbX,dbY As Float Dim dbR As Float Dim ArcCosY As Float Dim dbAngle As Float dbX = Values(0) dbY = Values(1) dbR = Sqrt(dbX * dbX + dbY * dbY ) 'length of gravity vector = approx. 9.8 ms-2 if no Z tilt If dbR > 1.234 Then 'arbitrary cut-off of orientation detection as phone is tilted towards flat horizontal ArcCosY = ACos(dbY / dbR) / cPI * 180 If dbX < 0 Then dbAngle = ArcCosY 'returns angles 0 .. 180 Else 'choose one of the below, depending on whether prefer angles -180 .. 180 or 0 .. 360 dbAngle = -ArcCosY 'returns angles -180 .. 0 dbAngle = 360 - ArcCosY 'returns angles 180 .. 360 End If RotateDashboardSteering(dbAngle) End If End Sub Sub RotateDashboardSteering(Angle As Float) Try If StateManager.blnNewDashboard = True Then Dim strAngle As String If isPortraitLayout = True Then strAngle = Angle - (Angle * 2) Else End If strAngle = NumberFormat2(strAngle, 1, 0, 0, False) If Starter.GaugeNb > 0 Then For x = 0 To Starter.GaugeNb - 1 xGauge(x).asView.Rotation = strAngle Next End If End If Catch Log(LastException) End Try End Sub
Work in Progress.. Jitters alot with Samsung S6 held by my hand and rotating it. I need some kind of filter to eliminate the jitters. Did not try at Steering Wheel. I assume it should be less vibration with steering wheel mount then hand.
Private Sub Accelerometer_SensorChanged (Values() As Float) Dim Damping As Int = DampingSeekBar.Value DampingLabel.Text = Damping Dim Threshold As Int = ThresholdSeekBar.Value ThresholdLabel.Text = Threshold Dim TotalChange As Float = Abs(Values(0) - X) + Abs(Values(1) - Y) TotalChange = TotalChange * 10 'approximate %G If TotalChange > Threshold Then Damping = 0 End If X = (X * Damping + Values(0)) / (Damping + 1) Y = (Y * Damping + Values(1)) / (Damping + 1) Dim R As Float = Sqrt(X * X + Y * Y )
Not sure per second, but coming in really fast. The behavior with slow rates is not as jittery then fast rates.How fast are the accelerometer readings coming in?
There was a slight tilt, maybe more then 10degrees towards horizontal.assume you've got the phone relatively "upright" so the Z axis is closer to horizontal than vertical
Done.Can you upload the source code?
That seems odd. The damping is done in these two lines here:The damping code is not working on either of my 2 phones.
X = (X * Damping + Values(0)) / (Damping + 1) Y = (Y * Damping + Values(1)) / (Damping + 1)
The amount of damping is controlled by the two sliders (top and bottom of screen). I think they default to 50. For no damping, slide the bottom one to zero (and the top one too if you like, to be sure, to be sure). For maximum damping, like they're in oil or something, slide both sliders to 100.The damping code is not working on either of my 2 phones.
You did the right thing using 20 ms timer to call rotations. ... I was calling rotation in accelerometer change event which is not recommended.