Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange behavior with android orientation sensor

Currently, I'm trying to rotate 3D Cube using orientation sensor values, using getRotation() method. Some unexpected behaviors are observed when the android device is rotated above some bounds. For instance, if I make the device 'stand up', the value of the 'roll' just becomes crazy.

Also I'm experiencing the phenomenon similar to so-called gimbal-lock. The only difference is I'm experiencing the very problem even before applying the sensor values to the 3D rotation. When I try to change the 'pitch' value by rotating the device around only 'pitch' axis, the 'yaw' value also changes according to the rotation of the pitch. It seems completely unreasonable to me.

Could somebody help me?? I'm stuck in this problem for a month.

like image 671
Kyoung-Rok Jang Avatar asked Apr 07 '11 07:04

Kyoung-Rok Jang


People also ask

How to get orientation sensor values in Android?

Then in the onSensorChanged () method, through the values ​​array of SensorEvent, you can get all the sensor values ​​output. The orientation sensor or direction in android will record the rotation angle of the phone in all directions, as shown in the below Figure.

What happened to sensor type_orientation in Android?

But unfortunately, Android has long abandoned Sensor.TYPE_ORIENTATION. For this type of sensor, although the code is still valid, it is no longer recommended. In fact, Android gets hand’s direction and angle of the machine’s rotation are calculated by the accelerometer sensor and the geomagnetic sensor. This is also the purpose of Android.

What are the most commonly used sensors in Android?

To say that another commonly used sensor in Android should be the direction sensor. Use of direction sensor in android the scene is wider than other sensors. It can accurately determine the rotation angle of the mobile phone in all directions. Use this from these angles, useful tools such as compass and horizon can be written.

How do I monitor the orientation of the device?

The only answer is to monitor the device orientation manually using the sensor manager. I'll show you how to do that in this tutorial. Follow along with the step-by-step instructions, or download and import the project directly into Eclipse. 1. Create a new Android project in Eclipse. Target SDK 9 (Gingerbread) or better. 2.


1 Answers

This is a common problem with yaw, pitch and roll. You cannot get rid of it as long as you are using yaw, pitch and roll (Euler angles). This video explains why.

I use rotation matrices instead of Euler angles in my motion sensing application. For an introduction to rotation matrices I recommend:

Direction Cosine Matrix IMU: Theory

Rotation matrices work like a charm.

Quaternions are also very popular and said to be the most stable.

[This answer was copied from here.]

like image 199
Ali Avatar answered Oct 23 '22 01:10

Ali