i got the Pololu IMU9(L3G4200D gyro and LSM303 acc/mag) and wrote my own program(Digitalduino: Pololu MiniIMU-9 Code) that reads the values from ACC, Gyro and MAG. i have gotten pitch(top row of pic) and roll(second row) quite stable with a kalman filter(and will later do PID), but i cant seem to get Yaw calculations to work-- the output(last row of pic) is completely wrong. the yaw code is based off of this: imu - Magnetometer dynamic calibration - Electrical Engineering Stack Exchange and http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267295038
code. MAGx is the raw value from the mag, same for MAGy etc
void YawCalc() // calculate yaw from mag
{
//YAW!
//this part is required to normalize the magnetic vector
//get Min and Max Reading for MAGic Axis
if (MAGx>xMAGMax) {
xMAGMax = MAGx;
}
if (MAGy>yMAGMax) {
yMAGMax = MAGy;
}
if (MAGz>zMAGMax) {
zMAGMax = MAGz;
}
if (MAGx<xMAGMin) {
xMAGMin = MAGx;
}
if (MAGy<yMAGMin) {
yMAGMin = MAGy;
}
if (MAGz<zMAGMin) {
zMAGMin = MAGz;
}
//Map the incoming Data from -1 to 1
xMAGMap = float(map(MAGx, xMAGMin, xMAGMax, -30000, 30000))/30000.0;
yMAGMap = float(map(MAGy, yMAGMin, yMAGMax, -30000, 30000))/30000.0;
zMAGMap = float(map(MAGz, zMAGMin, zMAGMax, -30000, 30000))/30000.0;
//normalize the magnetic vector
float norm = sqrt( sq(xMAGMap) + sq(yMAGMap) + sq(zMAGMap));
xMAGMap /=norm;
yMAGMap /=norm;
zMAGMap /=norm;
yawRaw=atan2( (-yMAGMap*cos(rollPrediction) + zMAGMap*sin(rollPrediction) ) , xMAGMap*cos(pitchPrediction) + zMAGMap*sin(pitchPrediction)*sin(rollPrediction)+ zMAGMap*sin(pitchPrediction)*cos(rollPrediction)) *180/PI;
//YawU=(atan2(-yMAGMap, xMAGMap) *180)/PI;
}
thanks.