# Can I find the magnetic components from magnetic heading and pitch/roll/yaw?

I'm trying to get a simulated magnetometer (B0x, B0y, B0z) via X-Plane. Can magnetic heading be reverse engineered into its components so I can run an EKF on it. I've got it working with the real thing but it'd be nice if everyone could get the EKF to run without hardware.

I've introduced an unrelated bug to my EKF that I've been spending time on so I'm hoping someone can beat me to figuring this out. I realize potentially their could be more than one solution which would make it impossible but if that's the case can someone confirm it?

X, Y, Z = magnetic components in x, y and z axis
Xh = X * cos(roll) + Y * sin(pitch) * sin(roll) - Z * cos(pitch) * sin(roll)
Yh = Y * cos(pitch) + Z * sin(pitch)
Azimuth = arcTan(Yh/Xh)

Summary: The problem is I have Azimuth and I need X, Y, Z. Can it be done?

Views: 260

### Replies to This Discussion

This might not follow your exact convention but you should be able to follow. Hope you can read the pic if not I have it on hand.
-Beall

@Michael
Yeah, that is correct. Tim has everything he needs (phi,theta,psi from sim) minus looking up the local magnetic vector strength and direction which is pretty easy.

http://www.ngdc.noaa.gov/geomagmodels/IGRFWMM.jsp
-Beall
I forgot to mention:
I can't remember what Xplane outputs for heading (mag or true) but psi in the above equations is true so if Xplane is giving you magnetic then convert to true before you use it.

-Beall
@ Tim,
Ref: Michael's post: >>>>For these reasons, I do not believe a specific X, Y, Z can be deduced from the Azimuth alone
or rather there would be more than one set of values for X, Y, Z that would give you the same Azimuth. So reverse engineering it would give you no specific value that would be considered the only correct answer which is what I guess you are hoping for, This explaination makes sence to me. :)
What I do to "measure" (simulate) a magnetometer in X-Plane is the next:

1º Take the GPS coordinates.
2º Calculate the XYZ with an Earth's magnetic model with the GPS coordinates.
3º Rotate this coordinates from the Flat Earth's Frame to Body's Frame (roll, pitch, yaw) to simulate the magnetometer measurement.

Do you know if X-Plane 10 will include magnetometer measurements?

1

2

3

4

5

6

7

8

9

10

## Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.

A list of all T3 contests is here

1298 members

51 members

87 members

106 members

47 members