Page 1 of 2

Magnetometer HMC5843 and I2C

PostPosted: Sat Jan 30, 2010 6:10 pm
by Mitch
I've been playing with the Honeywell HMC5843 I2C magnetometer triad as a potential hardware addition to the gluonpilot. It is a three axis magnetometer which provides a lot of potential for not only obtaining static heading data, but also vector matching to supplement the accelerometers. For development I've used the breakout board from sparkfun (the breakout I received was flakey as supplied and I had to replace the capacitor with a 10uF ceramic for consistent operation - see the forums at sparkfun.com).

Image

I've attached a working MPLAB project. The code should be all inclusive and self explanatory. It's close to Tom's code guidelines - except I'm using the internal FRC on my dspic hardware platform (btw nice to see the boards are in and anxiously waiting). I've substituted microcontroller.c with my own micro_frc.c. Switching to the external oscillator should only require using Tom's microcontroller.c and possibly adjusting I2C1BRG for the I2C frequency.

The code also demonstrates how to use a c union structure to avoid shifting bits around when reading values by the byte - see hmc5843.h

Note - like accelerometers you don't have to calibrate these devices if you calculate using ratios of the axis.

Some example uses:
Total measured magnetic field is |Hearth| = sqrt(Hx2 + Hy2 + Hz2)
For level conditions true heading = atan (YH / XH) +- declination

If the attitude is known phi=roll theta=pitch, first project onto xy plane with
YH = Y*cos(phi) + Z*sin(theta)
XH = X*cos(theta) + Y*sin(phi)*sin(theta) - Z*cos(phi)*sin(theta)

More data can be derived knowing the local inclination which defines the vertical component of the local magnetic field. See http://www.ngdc.noaa.gov/geomagmodels/IGRFGrid.jsp

Use the code as you please.

Mitch

Re: Magnetometer HMC5843 and I2C

PostPosted: Sat Jan 30, 2010 11:14 pm
by asifjahmed
Wow - thanks Mitch!

Are you building a quadrocopter?

-Jamie

Re: Magnetometer HMC5843 and I2C

PostPosted: Sun Jan 31, 2010 12:16 am
by Mitch
No Quad! I have several projects underway. Some stability and control and some autopilot. I really wanted the magnetometer for the project in the video below. Several months of hover tests led to the youtube video which was the first flight in "airplane" mode, nine months ago, on a very windy day. It hovers but I'm looking for rock solid stability. I'm running out of room, processing power, and lacking all of the sensors I want/need!


Link


More photos here http://www.jaxrc.com/gallery/index.php?cat=1026

Mitch

Re: Magnetometer HMC5843 and I2C

PostPosted: Sun Jan 31, 2010 5:07 pm
by Tom
Great! Thanks!

I have the 2-axis magnetometer, but still need to find some time to check it out :-)

Re: Magnetometer HMC5843 and I2C

PostPosted: Thu Feb 11, 2010 12:56 am
by Mitch
Judging from the excellent progress on the configuration utility, I'd say you've been very busy!!!

Re: Magnetometer HMC5843 and I2C

PostPosted: Fri Feb 25, 2011 7:00 pm
by Goldfinch
Did You get good magnetic course measurement with HMC 5843? This sensor must be calibrated for soft- and hard-iron disturbances after installation onboard. I can't find any detailed information about calibration methods. I found only one example where compass was used on car so only circle driving is needed for calibration. For example I have Garmin hand-held gps with built-in compass. You need to rotate the unit about each of three orthogonal axes while calibrating. If I rotate HMC 5843 in such manner as Garmin I will get 6 offsets (X-Z, X-Y, Y-Z) and I'm confused because they are different for the same axis. How do you solve this problem?

Re: Magnetometer HMC5843 and I2C

PostPosted: Sat Feb 26, 2011 4:26 pm
by Tom
I ordered this one at sparkfun and will test it soon!

So far I have only used the HMC6352, and this one has on-board hard-and soft-iron compensation.

Re: Magnetometer HMC5843 and I2C

PostPosted: Fri Mar 11, 2011 10:48 pm
by Tom
Hi Mitch,

Better late than never: The HMC5843 code is now integrated into the gluonpilot code tree, and it's based on your code!
The matlab scripts for calibration were very interesting! I'll sure implement it on-board or in the config tool!

Any more news from you lately?

Re: Magnetometer HMC5843 and I2C

PostPosted: Wed Mar 16, 2011 12:07 pm
by magellan
Hi Tom,

I see everything is in stock, I will order my Gluon very soon, work has been so busy I have put all the plans on the back burner for now.

I am glad to see you are integrating the magnetometer. It's great for Quads and why not for fixed wing too?
Isn't it better to have an extra degree of measurement in the attitude estimation for both Quads and Fix Wings? Once we add an airspeed sensor, we have a real complete solution no?
And in the future, compare GPS Speed with Airspeed and figure out the crosswind component for drift compensation! I think Bill Premerlani did a wind drift compensation code on the UAVDev board, I wonder if we could integrate that at some point.

Re: Magnetometer HMC5843 and I2C

PostPosted: Wed Mar 16, 2011 6:43 pm
by Tom
Good to see you are back! :-)

Yes the magnetometer could also be used for fixed-wings, but the advantage would be rather small I think.
Indeed pitot tubes are more important for fixed-wings so you can estimate the wind.

The coming weeks I'm going to focus on quadrocopters. After that we'll see which thing i will implement first for fixed wings :-)