Calculate the rotation matrix using an accelerometer

I am currently facing a more mathematical problem. I am developing an application that is interested in acceleration on the X and Y axis. In other words, I want to track the acceleration that goes left or right and forward or backward.

If the device lies on the table up, all accelerations in the desired direction are visible in the acceleration values ​​of this axis. There is a problem: the device does not fit in this position and has a certain rotation around the X or Y axis (step, roll).

I need a rotation matrix (Rm), which I can multiply by the acceleration vector (x) to get a new calibrated vector (x '), other classes can work with: x' = Rm * x . This should be calculated from the reference vector (0,0, -1) and the current device gravity vector.

I know that this has something to do with Euler angles, but I cannot understand how I can calculate them and create my rotation matrix with them. I also know that the CMAttitude class has a rotation matrix, but I would like more information on how this matrix is ​​calculated.

Example:

Imagine that you want to take care of how hard you brake your bike. If your iPhone is mounted on a bicycle and the display is pointing straight up, you can read the acceleration in the y value of the acceleration vector. Other classes in your project assume that braking acceleration can always be seen in this value.

The problem is that the iPhone fits in a portrait view of a display pointing at you. Then braking does not increase the value of y, but instead the value of z. Thus, you must rotate your acceleration value by -90 degrees around the x axis.

I need this rotation matrix for arbitrary rotation of the device. I know that it is impossible to calculate the rotation around the z axis from gravity vectors, but as long as the x and y turns are denied, I'm fine.

Many thanks for your help

+4
source share
2 answers

To calculate the Euler angle, you need to calculate the angle between the reference vector and the current gravity vector.

http://chemistry.about.com/od/workedchemistryproblems/a/scalar-product-vectors-problem.htm

After that, the rotation matrix is ​​pretty simple. http://en.wikipedia.org/wiki/Rotation_matrix

Note. I am sure there are many easy ways to do this in ios and android without having to do these calculations manually. This answer is how geometry comes about.

+1
source

I think the following link should be useful Converting iPhone accelerometer data into car axes note that there is an error in the rotation matrix, the element rm11 should be cos "Beta" * cos "gamma" and not cos "alpha" * cos "gamma "

+1
source

Source: https://habr.com/ru/post/1385603/


All Articles