I've worked on a project to implement the Kalman filter on an embedded system that was similar in hardware to the iNemo unit from STMicroelectronics.
Even if you can find these IMU (Inertial Measuring Unit) with 90% chance you will have to implement your algorithm by yourself; or if you're lucky, you can find someone that has the code. The problem is that this filter requires a lot of computation, and in our best experiment (using fixed point variables and trying to optimize the code) we were able to run it 45 times per second, in a STM32 at 72 MHz.
So maybe there is one, but as far as I know requires a good microcontroller or maybe a FPGA\ASIC.
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)...
Best Answer
Both the accelerometer and the gyro provide delta measurements. If you need an absolute reference, you need to provide it by another means. Even gravity is not a reliable reference because you can't tell what component of your acceleration is due to gravity and what is due to motion.
The accelerometers are not very good for angle measurements on their own. They measure linear acceleration, not rotation or angle. You can get a crude orientation out of them by assuming everything is static and therefore the acceleration vector is due entirely to gravity. The challenge is that the accel can't tell the difference between gravity and motion-- if you move the device, the acceleration will be the sum of gravity and motion leading to an ambiguous result.
A magnetometer can give an absolute reference to the earth's magnetic field, but it is sloppy and easily distorted.
The IMU probably has a reference frame labeled on the device that will give you a clue as to the internal arrangement of sensors, but that is still subject to manufacturing tolerances and is probably not labeled with care.
A common solution is to calibrate the device periodically using a technique known as a ZUPT (zero velocity update). Place the device in a known orientation, don't move it, let the filters settle out, and call that your global frame. From then, calculate your deltas from that pose. Errors will grow quickly, so you'll need to repeat this procedure periodically.
The ZUPT will cancel out accumulated measurement errors due to drift and bias, but if you want to coordinate measurements from multiple sensors (3 accelerometers, 3 gyros, for example) then you need to do an alignment calibration. You don't know how well aligned the various sensors are-- how orthogonal are the x,y and z accels and pitch, roll and yaw gyros to each other (they can't be perfect). Also, how coaxial is the yaw gyro with the z accelerometer, etc. This will require making controlled movements of the sensor set to check alignment. Generally this only needs to be done infrequently, and possibly at the factory. Your IMU may have the calibration parameters stored in it.
Every sensor is independent, so the system needs to have the various devices referenced to each other. That is what I referred to as an alignment calibration. That gives you a (non-orthogonal) coordinate system relative to some origin on the IMU itself. Then there are errors that will build over run time that need to be canceled, which the ZUPT will help with. As far as tying to a global reference frame external to the IMU, that needs to be done by some other form of measurement. Possibly by ZUPTing in a known reference pose, or by some external measurement system that can reference your local to global frames.