Calculate relative orientation, considering azimuth, pitch and roll in android?

When I listen to the orientation event in the Android application, I get a SensorEvent that contains 3 floats - azimuth, step and roll relative to the axis of the real world.

Now say that I am creating an application, such as a maze, but I do not want to force the user to be on the phone and hold the phone so that the xy plane is parallel to the ground. Instead, I want to be able to allow the user to hold the phone as they see fit, stack or possibly sit down and hold the phone at an angle. In other words, I need to calibrate the phone according to user preferences.

How can i do this?

Also note that I believe my answer is related to getRotationMatrix and getOrientation , but I'm not sure how to do this.

Please, help! I'm stuck in this for hours.

+4
source share
2 answers

To apply the maze style, you probably care more about the acceleration (gravity) vector than the axial orientation. This vector in the phoneโ€™s coordinate system is defined by a combination of three dimensions of accelerometers, rather than rotation angles. In particular, only the readings x and y should influence the movement of the ball.

If you really need orientation, then 3 angular readings represent 3 Euler angles. However, I suspect that you probably do not need the corners themselves, but rather the R rotation matrix, which is returned by the getRotationMatrix () API. When you have this matrix, then - This is basically the calibration you are looking for. If you want to convert a vector into world coordinates into the coordinates of your device, you must multiply it by the inverse of this matrix (where in this special case inv ( R ) = transpose ( R ).

So, following the example I found in the documentation, if you want to convert the global gravity vector g ([0 0 g]) to the coordinates of the device, multiply it by inv ( R ),

g = inv ( R ) * g

(note that this should give you the same result as reading accelerometers)

Possible APIs to use here are the invertM () and multiplyMV () methods for the matrix class.

+3
source

I donโ€™t know any Android-specific APIs, but all you want to do is reduce the azimuth by a certain amount, right? Thus, you move the โ€œoriginโ€ from (0,0,0) to the right place. In pseudo code:

 myGetRotationMatrix: return getRotationMatrix() - origin 
0
source

All Articles