Page 1 of 1
HMC5883 compass centering drift
Posted: Sat Dec 21, 2013 6:33 pm
by jwatte
I wired up the compass sensor and read the output values along X and Y, plotting them to a window while keeping the sensor pushed to a wooden surface, and turning it around about 8-10 revolutions.
The result is a bit annoyingly hard to make sense of. There is a centering problem, where 0,0 is not the actual center; this can be fixed with calibration. But, once in a while, the readings go way out into the ether, as can be seen by the trails in the upper-right side, and sometimes they pull in towards the actual center of the measurement range.
As you can see, the compass is pretty far from anything with a strong magnetic field. The rover in the back is aluminum, and the motors are not energized; the leads are copper, and the wooden surface is all-wood joinery. The closest ferrous substance is proably the resistor leads in the plastic container bin in the background, so I don't think this is the issue.
What can I do to stabilize these readings? I use the default sensitivity of 1.3 Ga.

Re: HMC5883 compass centering drift
Posted: Fri Jan 10, 2014 4:38 pm
by oz
jwatte,
You have a data display system set up so try some of the following:
Insure that your data display system is bulletproof as communicating serial values can be slightly tricky requiring some means of insuring that X & Y data do not get swapped.
Take a plastic straw or wooden chop stick and tape it to the sensor with masking tape. This will tell you if any of the noise you are seeing is capacitively coupled noise from your body. You can check more simply by trying to hold the sensor by its very edges, staying well away from anything that is conductive. We do find that we have to do that in the shop while testing. Also as you pointed out, the sensors are tilt sensitive and it requires holding them level, or an accelerometer and a moderate amount of math and code to take the tilt insensitivity out of the readings.
Also using shielded cable will tend to minimize any noise coming in on the power lines. Adding more decoupling caps can't hurt.
In particular make sure that you don't have DC motors on the same supply lines as the compass sensor. If you've got a scope, scope the supply lines on AC coupling and look at your finest setting - switch on and off other items in the system such as motors to see if they make any difference in scope display and data output.
Also don't be so sure that magnetic fields from the motors and other equipment are not affecting the readings. I once proved out a similar sensor / chip in a car (it was cold), and noticed that the readings changed by about 20 degrees after I got out of the car and the field caused by the iron block of the engine.
There is also an Arduino library someone has cooked up for calibrating the sensor for iron although I can't find the library I was looking for just now. A lot of work and coding have been done on that sensor so google around and check the Arduino forum.
Let me know how you make out with that and I'll see if I can think about anything else, or try to reproduce your results with another sensor.
Re: HMC5883 compass centering drift
Posted: Fri Jan 10, 2014 9:28 pm
by jwatte
Thanks for the suggestions! I will try it and see how it goes.
Also, I have resigned myself to the bot having to do a 360 to calibrate itself before it starts running. I'm hoping that my four-wheel steering will let me do that in place, though
The goal is to mount the sensor a bit up from the bot, currently I'm thinking using aluminum tubing, as I think that has no magnetic distortion. I could go with wood or plastic, but prefer to stick to aluminum as that's a theme of this bot.
The power comes from a 5V switching voltage converter, that in turn takes its vin from the same 12.8V LeFePO4 battery as the motors, but it is pretty well isolated (> 80 dB rejection on the converter, and I've added caps, too.) The motors are not on while doing these measurements. I can see up to a +/- 50 mV ripple at 500 kHz on the output, though; I'm assuming this won't actually be a problem.