Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate rotation angle using Android Sensors?

I am doing an Opengl appln in which i have to rotate the camera, if the android device is rotated/tilted along Z axis.

I tried the SensorManager.getOrientation(R, orientVals); using the magnetic and accelerometer sensors. But the values are very much fluctuating. Gyroscope is also available in my device.

Since I am animating (rotate) the camera, I need a smooth rotation values

Please guide me in this regard.

like image 424
Arun AC Avatar asked Dec 07 '25 20:12

Arun AC


1 Answers

See How do you calculate the rate of rotation using the accelerometer values in Android for a particular axis on how to read Android's software-derived sensors that combine the data from the accelerometers, magnetometers, and (if available) gyroscopes.

To smooth values, use a low-pass filter or (better but more complicated) a Kalman filter. I suspect that Android's software-derived sensors such as the "rotation sensor" already use a Kalman filter to combine data from the different sensors. (One could search the source code...)

like image 99
Jerry101 Avatar answered Dec 11 '25 11:12

Jerry101



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!