0

I want to build something similar to the Euler's compass and I need a bit of guidance. Using the Accelerometer and Magnetic sensors I managed to compute the yaw, pitch and roll angles(radians). Now, what should be the next step? I searched over the internet for several hours and I cannot find something relevant. Should I compose the angles according to the reference axis?

dfeuer
  • 48,079
  • 5
  • 63
  • 167
Ispas Claudiu
  • 1,890
  • 2
  • 28
  • 54

1 Answers1

4

I assume you're referring to Euler Compass on the Android Play Store?
The Accelerometer and Magnetic compass readings are very noisy. You would get better results if you also factor in the Gyroscope, maybe with a Kalman filter, or something similar. On windows tablets, most of the complex math is already done for you, but on Android and iPhone, you have to do it yourself:

I suggest you start with a transform matrix to represent the device orientation. If you're only interested in orientation, a 3x3 matrix will do, like so:
1 0 0 (First row is a vector pointing along the X-axis)
0 1 0 (Second row is a vector pointing along the Y-axis)
0 0 1 (Third row is a vector pointing along the Z-axis)

First apply the Gyroscope rotations to your matrix.
The Gyroscope gives you acceleration around each axis.
Multiply by time, to get angular velocity. (speed)
Multiply by time again, to get angular distance.(degrees)
In the short term, the Gyroscope is very accurate and stable, compared to the other two sensors, but it has no fixed point of reference, like the other two. i.e. it only gives you the angular distance you've moved, since your previous reading, so over time, rounding errors will cause it to slowly drift off course. That is where the other two sensors come in... (Use them to counteract the gyroscope;s drift.)
The Accelerometer and Magnetometer are very noisy in the sort term, but you can get a more accurate result by taking the average of several consecutive readings. (low-pass filter) This makes them sluggish, but more accurate in the long term... the opposite weakness of the Gyroscope. So the trick is to combine them, to get the best of both. ;)

The Accelerometer represents a down-vector, and the magnetometer represents a north-vector. So, look at what the difference is between your matrix down vector, and that of the accelerometer, and then rotate your matrix towards that of the accelerometer. Not all the way... just small steps, to avoid introducing the noise, but just enough to counter-act the gyroscope's drift. (Continuous re-calibration.) Then do the same with the Magnetic compass.

Now you should have a rotation matrix that fairly accurately represents your device orientation. Next, you just need to add a blank row and column to the matrix, and pass it to OpenGL, so you can render your graphics.

I hope this helps.

Rene