Magnetometer HMC5843 and I2C

Here is the place for all your dsPic or autopilot questions.

Moderator: lukasz

Magnetometer HMC5843 and I2C

Postby Mitch » Sat Jan 30, 2010 6:10 pm

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
Attachments
hmc5843.zip
(14.22 KiB) Downloaded 1034 times
Last edited by Mitch on Sun Jan 31, 2010 3:11 pm, edited 4 times in total.
User avatar
Mitch
 
Posts: 118
Joined: Sat Dec 05, 2009 1:59 pm
Location: Florida, USA

Re: Magnetometer HMC5843 and I2C

Postby asifjahmed » Sat Jan 30, 2010 11:14 pm

Wow - thanks Mitch!

Are you building a quadrocopter?

-Jamie
asifjahmed
 
Posts: 11
Joined: Mon Dec 14, 2009 6:27 pm

Re: Magnetometer HMC5843 and I2C

Postby Mitch » Sun Jan 31, 2010 12:16 am

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
Last edited by Mitch on Mon Feb 01, 2010 1:28 am, edited 2 times in total.
User avatar
Mitch
 
Posts: 118
Joined: Sat Dec 05, 2009 1:59 pm
Location: Florida, USA

Re: Magnetometer HMC5843 and I2C

Postby Tom » Sun Jan 31, 2010 5:07 pm

Great! Thanks!

I have the 2-axis magnetometer, but still need to find some time to check it out :-)
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: Magnetometer HMC5843 and I2C

Postby Mitch » Thu Feb 11, 2010 12:56 am

Judging from the excellent progress on the configuration utility, I'd say you've been very busy!!!
User avatar
Mitch
 
Posts: 118
Joined: Sat Dec 05, 2009 1:59 pm
Location: Florida, USA

Re: Magnetometer HMC5843 and I2C

Postby Goldfinch » Fri Feb 25, 2011 7:00 pm

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?
Goldfinch
 
Posts: 12
Joined: Mon Mar 15, 2010 11:22 am
Location: Russia

Re: Magnetometer HMC5843 and I2C

Postby Tom » Sat Feb 26, 2011 4:26 pm

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.
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: Magnetometer HMC5843 and I2C

Postby Tom » Fri Mar 11, 2011 10:48 pm

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?
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: Magnetometer HMC5843 and I2C

Postby magellan » Wed Mar 16, 2011 12:07 pm

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.
magellan
 
Posts: 38
Joined: Fri Jan 29, 2010 12:08 am

Re: Magnetometer HMC5843 and I2C

Postby Tom » Wed Mar 16, 2011 6:43 pm

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 :-)
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Next

Return to Firmware

Who is online

Users browsing this forum: No registered users and 5 guests

cron