- Tue Feb 27, 2007 11:11 am
#26552
Hello,
I would appreciate some assistance with developing some code that is capable of using a MicroMag3 magneto to provide a tilt compensated heading. I have searched these forums and the net; however, I have been unable to get this to work.
My understanding is that to calculate the heading the following formulas should be used:
Xh = X*Cos(pitch) + Y*Sin(roll) * Sin(pitch) – Z*Cos(roll)*Sin(pitch)
Yh = Y*Cos(roll) + Z*Sin(roll)
Heading = arcTan(Yh/Xh)
So far, I am only able to get a heading when the device is level. My tilt values also seem accurate.
My X and Y values have been calibrated, however I am unsure on how to use the Z value, do you just use the raw sampled value? I find that tilt is sometimes compensated when the magneto is pointing in certain directions and the tilt is one way. I have played about with the roll and pitch values such that they range from 0 to 360, as well as 0 to +/- 180.
Does anyone have sample code? This is driving me crazy!
Also this is my first post and I’d just like to say I think sparkfun is great, though I think I’m getting addicted to buying new parts!
I would appreciate some assistance with developing some code that is capable of using a MicroMag3 magneto to provide a tilt compensated heading. I have searched these forums and the net; however, I have been unable to get this to work.
My understanding is that to calculate the heading the following formulas should be used:
Xh = X*Cos(pitch) + Y*Sin(roll) * Sin(pitch) – Z*Cos(roll)*Sin(pitch)
Yh = Y*Cos(roll) + Z*Sin(roll)
Heading = arcTan(Yh/Xh)
So far, I am only able to get a heading when the device is level. My tilt values also seem accurate.
My X and Y values have been calibrated, however I am unsure on how to use the Z value, do you just use the raw sampled value? I find that tilt is sometimes compensated when the magneto is pointing in certain directions and the tilt is one way. I have played about with the roll and pitch values such that they range from 0 to 360, as well as 0 to +/- 180.
Does anyone have sample code? This is driving me crazy!
Also this is my first post and I’d just like to say I think sparkfun is great, though I think I’m getting addicted to buying new parts!
Thanks,
Andrew Murray
Andrew Murray