It's possible that your confusion stems from the fact that there are multiple solutions to the problem. While your accelerometer can tell you which way is up, it cannot distinguish between North and West. I.E. If you rotate the device about the vertical axis, the outputs of the accelerometers won't change.
How can you distinguish between North and West? The best way is probably to add a digital compass to the mix. Alternatively, you may not care to know the difference between real North and real West. You may only want two orthogonal horizontal axes. I'll assume the latter.
Define our frames first. The device's frame is (X, Y, Z). The earth's frame is (V, H1, H2).
Lets assume your accelerometer readings (Ax, Ay, Az) are in the range -1 .. +1, where +1 means straight up. Immediately you know which direction is up: it's simply (Ax, Ay, Az). But how do we obtain a horizontal axis? There's a function called the Cross Product, which takes any two vectors as inputs, and returns another vector at right angles to both. Therefore, we can easily find a vector at right angles to Up. In C:
Vector3D V = (Ax, Ay, Az);
Vector3D H1 = RANDOM_VECTOR;
Vector3D H2 = CrossProduct(V, H1);
H1 = CrossProduct(V, H2);
Normalise(H1);
Normalise(H2);
So, now we have a vertical vector V, and two horizontal vectors H1 and H2. Now we just need to rotate the gyroscope readings into the same frame.
Let's call the gyroscope readings (Gx, Gy, Gz). We're going to convert them into earth frame rotation coordinates (GV, GH1, GH2). All you have to do is to think about the gyro readings like a single 3D vector. Which way is it pointing in the device's frame. Which way is it pointing in the Earth's frame?
The answer is simply:
GV = (Gx*V.x) + (Gy*V.y) + (Gz*V.z);
GH1 = (Gx*H1.x) + (Gy*H1.y) + (Gz*H1.z);
GH2 = (Gx*H2.x) + (Gy*H2.y) + (Gz*H2.z);
(I hope that's right)...
(This question has been posted more than a year ago)
You need these angles in order to apply a control, a PID for example, to stabilize the quadcopter in hovering mode. Your control is supposed to be active when you are not remote controlling your drone and you want it to be perfectly horizontal. This means that the theta(x axis) and phi(y axis) angles will be close to zero and will reach the desired reference value ( =0 ) thanks to the control.
I have a question for you: Have you recorded these values while the motors were spinning? I've noticed an important increase in noise amplitude caused by vibrations on the chassis.
Best Answer
I'm not 100% sure what you mean by "wave elevation on a tank", but I'll assume that it's a liquid height of some sort.
As you've discovered, you will get integration errors when going from acceleration to displacement. In vibration analysis, typically data is measured with accels, then integrated as needed to get velocity or displacement, typically though, the data will be run through a high pass filter since the noise in the lower frequencies gets amplified with each integration and a signal that looks great as acceleration will be garbage as displacement. Of course, the phenomena you're measuring is probably a low enough frequency that a high pass filter sufficient to remove the noise will also be removing important parts of your signal.
My suggestion would be that you're simply using the wrong tool for the job. There are plenty of proven ways to measure a fluid level in a tank. A magneto-restrictive float sensor would be a good place to start.