HMC5883L Calibration

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
RyanPierce
 
Posts: 11
Joined: Thu Aug 23, 2012 7:12 pm

HMC5883L Calibration

Post by RyanPierce »

I'm working as a volunteer on a project for the Adler Planetarium involving launching high altitude balloons into the stratosphere. We've got a steerable parachute, and eventually we would like to develop autopilot control for it so we might have some control over where the experiment payload will come down after a flight. We're also using an MPU-6000 as an accelerometer and gyro, and a GPS. The MPU-6000 gives us a decent looking yaw, but it is relative to the direction the chip is pointed when it powers up, and it seems to drift on the order of a hundredth of a degree per second, which over a 3 hour balloon flight would be major. I'd like to use the HMC5883L to determine an offset between the IMU's yaw and magnetic north, and then continually use something like a Kalman filter between the IMU yaw and the magnetometer heading to update this, counteracting gyro drift and giving us a real magnetic heading.

I've been working quite a bit with the HMC5883L chip and have noticed some quirks. First, I discovered that there's a significant zero offset in the chip, and it varies per chip. I've put a breakout board on a breadboard and turned it while keeping it flat on a fairly level table. Plotting the X and Y flux, I get a circle, but it's not centered on 0,0 which implies that each axis needs an offset applied to it. OK, that's simple enough to correct. The spec sheet on the Jameco website includes app notes that describe this. As to its cause, I know "hard iron" types of interference produce a constant flux offset, but there's nothing like that on the breakout board, and I don't think the DC current flowing through the board would generate that much of a magnetic field. I am hypothesizing that the magnetometer's zero offset from the factory is relatively poor.

Now the second cause of error I'm seeing is tilt. In Illinois, the earth's magnetic field dips considerably, so tilting the magnetometer will produce significantly different results. The app note describes how to use trig to take the pitch and roll angles and project the X and Y vectors onto a level plane. I've got pitch and roll info from the MPU-6000, and I've been able to do this fairly successfully. Tilting the chip while keeping it pointed in the same direction causes major changes in X and/or Y flux, but the tilt-corrected flux number seems to match the raw numbers when the chip was flat within reasonable tolerances.

So now here's where I'm stuck: combining these two concepts. The app note talked about each individually, and implied that you'd tilt correct first, and then center the circle with offsets. This makes no sense to me, because any hard iron and/or chip offset errors would be relative to the chip itself, not the tilt-corrected level plane, so I'd think you'd need to correct these first before projecting the vector based on pitch and roll. But that leads me to question what to do about the Z axis, since the flat circle test didn't give me any way of determining an offset, and as tilt angle increases, errors here will add up.

To further complicate matters, one thing I tried was writing a sketch that would store the raw min and max values for each axis while I spun the breadboard in nearly every orientation I could in 3D space. In theory, I'd think this would give me a sphere with an offset from the origin, and these offsets would be the corrections I'd apply before doing the tilt correction. But to my surprise, the results were actually pretty close to the origin. That made no sense to me. It implied that the factory did a better job than I thought at setting the zero offset. But I expected the X and Y offsets to match what I observed with the chip flat, and they clearly didn't.

Any help here would be greatly appreciated. Thanks!

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: HMC5883L Calibration

Post by adafruit2 »

Hiya, we don't have a specific calibration function for this sensor, but check out Pololu's examples for the LSM303 (which includes a magnetometer too) with its calibration procedures, it may help!
https://github.com/pololu/lsm303-arduino

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”