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.
I tried it here, using the pre-Scanteched Klaus gauges, and it seemed ok, certainly not as jittery as the video of your phone at the end, where I assume you were holding the phone upright. Could be difference in sensors, although I have a cheap brand, not a Samsung.
Thoughts are:
1/ How fast are the accelerometer readings coming in? Perhaps rather than updating the gauges for each new acceleration reading, just update a general DeviceAngle global, and then use that when you are updating the gauges anyway ie the needle angles.
2/ If you do filter (average) to get rid of the jitters, probably simpler and possibly better to do it on the accelerations (X and Y) and not on the angle. If you do average the angle, watch out when the phone is hovering near upright ie 359..0..1 degrees, where the average will be ~180 degrees (no prizes for guessing how I found that out).
3/ I am not sure of the timing of the acceleration readings, ie, are they regular like clockwork, or are there more of them when the readings are changing?
4/ I assume you've got the phone relatively "upright" so the Z axis is closer to horizontal than vertical. As the phone is tilted towards being flat horizontal, the X and Y accelerations will become smaller, and their relative errors larger, causing more jitter.
On my phone, and done on an actual steering wheel because I was running out of hands...
No damping:
Too much damping:
My damping code looks like:
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 )
The idea with the threshold was that, if the rotation changed by more than a specified amount, then no need to apply damping. Damping would only be applied to steady the gauges when the phone was steady.