Electronic – simple IMU – tilt magnetometer

imu

I am in the process of building a simple IMU for an autopilot. I am using Sparkfun, 9 Degrees of Freedom – Razor IMU. It is surprisingly user friendly.

I was able to get accelerometer, gyro and magnetometer data right out of the box. After calibration of the sensors and a simple complementary filter i have reliable roll and pitch values.

Now I have a problem with the yaw…

I found here http://www.pololu.com/file/download/…?file_id=0J434 the equation to get the yaw out of the magnetometer value:

$$X_h = X_m\cdot cos(Pitch) + Z_m \cdot sin(Pitch)$$
$$Y_h= X_m\cdot sin(Roll)\cdot sin(Pitch) + Y_m\cdot cos(Roll) – Z_m\cdot sin(Roll)\cdot cos(Pitch)$$
with Xm, Ym, and Zm are magnetic sensor measurements

$$Yaw = Heading = arctan( \frac{Y_h}{X_h} )$$

It sound be simple, but I can't do it. I hope that someone who already worked on IMUs can help me solve this problem.

Here (http://diydrones.com/forum/attachment/download?id=705844%3AUploadedFile%3A1327110) is an excel file with IMU data and equations.

The graph (in Excel file) shows results (first i rolled 90 degrees, then I pitched 90 degrees then I yawed 90 degrees).

Roll and pitch are calculated by the IMU (programmed with Arduino IDE), they are good.

Yaw is calculated in Excel using gyro (good but drift over time) and I also calculated Yaw using the equation above (green line) and it is totally wrong (it should follow the gyro line / purple).

Any help will be appreciated.

Best Answer

It looks like the Gyro and the Magnetometer are slightly miscalibrated. In excel, it looks like they are about 135 degrees apart. Try changing your formula to be this instead:

=DEGREES(ATAN2(U3,T3))+Dcal

Where Dcal is some calibration value. It looks like the data matches up fairly well when Dcal is about 135 degrees.