HMC6352 compass calibration problems

I recently bought the HMC6352 compass for a mobile robotics project and was happy to see that it was very easy to get connected and reading the heading using the Duemilanove. However, I noticed that the compass did not turn linearly with the robot. For instance, I could read a stationary point at say 60 degrees and then rotate the robot 20 degrees but the new compass reading would be 240 degrees. I thought this could be related to some nearby magnetic field but I get the same response in mulitple locations, by itself, not attached to the robot.

I also thought maybe I could resolve this issue by entering the calibration mode and doing a user calibration. This however was apparently very bad because now the compass will only read value 0-25 degrees and then start over as the compass moves in a circle. I manually rewrote the EEPROM offsets back to 0 and still have the same issue.

I dont think I did the calibration wrong simply because the read is done in a very similar way.

Yes I realize I should have got the calibration values before I tried a manual calibration but i didnt. If you do have some typical calibration value that might help?

Has anyone else encountered this problem?

I had issues similar to what you describe when interfacing an HMC6352. Other users have reported this as a "late startup issue" which seems also to be related. This suggests that if you leave the compass running for some time (several minutes) it will eventually perform as expected.

In the manual there is reference to an "update bridge offsets" command ('O'). This will force a reinitialize of the compass and I think you will see improvement if you execute this command as part of your setup routine. When the compass is working ok you may then procede to run the calibration routine again.

The default calibration parameters are zero - so no need to worry here.

Thanks for the response.

Another question though. Is the calibration routine meant to filter out constant magnetic interference (like if you run close to a motor) or help with the problem of the heading not moving linearly with the turning of the compass (as described above)? If it just filters out the constant interference, what good is it in a mobile robot that can run into all sorts of interference as it moves around a room?

The initial non-linearity/wrong heading is a separate issue and you can remedy that as suggested above.

The calibration routine will correct for any magnetic deviations int its vicinity be it global or local. The compass will also auto-calibrate when used, but these offsets will be lost when you cycle power. If you choose to force calibration, offsets are saved and will be used as a starting point when you cycle power.

Digital compass modules give us headings with an impressive precision (1/10 of a degree for the HMC6532), but keep in mind that it's still not more than a magnetic compass. As such they are inherently inaccurate and very sensitive to correct orientation and magnectic influence form nearby objects. Even the earths magnetic field can't be trusted in many places. If you spent twice the money on a more high-end compass, you would probably still not be impressed.

What I've done is to combine the readings from a gyro and the HMC6532 so that calculated headings use the gyro for short term changes and compass for longer term. I also heavily average the readings (fast sampling) before I use them in calculations.