The DIYDrones HMC5843 breakout board and the Ardupilot Mega/Oilpan.
by
on 07-11-2010 at 02:28 AM (873 Views)
I am slowly working through validating all the diffrent parts of hardware for my Quad and I got to the Compass today.
With the break-away sides removed it fits nicely on-top of the Oilpan. The I2C holes line up well. It does stick a little off the end, but thats ok.
The only problem is that the axis directions of the board are now different from the ones for the APM/Oilpan.
I have been using the mounting orientation that arducoptor guys are using. The servo and RX connections (and relay) are at the "back" of the quad. GPS connector is at the front.
With the APM orientated this way the HMC5843 is oriented out by 90 degrees clockwise.
Software to the rescue. Its easy enough to correct in code.
The easiest way to do this is swap the X and Y readings, and then invert the Y reading.
This brings things back to the correct orientation and you now get correct readings that are pointed the same way as the APM board.
While I was going through the process of testing things I stumbled across a very helpful tool. Its a combination Arduino sketch and a Processing sketch.
It lets you visualize the magnetic readings as you move the board around. It really helped me find out how things were oriented and how they should be orientated.
The code is originally from here: http://www.evilmadscientist.com/article.php/fields
(Scroll down to a little past half way. They use the HMC5843 to demonstrate magnetic fields.)
I have modified the Arduino sketch to perform the changes I described to get the sensor "pointing" the right direction when mounted on the APM board. But you can easily comment out the code to see it in its native orientation.
You are going to need the HMC library to use this test. Its available here:
http://eclecti.cc/hardware/hmc5843-m...ry-for-arduino
You can also use the APM library for the sensor, but you'll have to tweak the code to use that. Though its basically the exact same library, so it doesn't much matter.
The processing sketch is almost stock, I just commented out the line that prints out the calculated readings as it gets them.
You can see the magnetic readings plotted in 3d as you move the board around.
If you spin the board around all its axis you should get something resembling a sphere after a little bit.
When you exit the Processing sketch as well it will print the max, min, and offset for each axis. Its quite useful and makes scaling the data easy.
The other thing I learned is how the "dots" should show up as you move things around. This enabled me to sort out the axis swapping and inverting. The information I gathered is as follows.
X Axis - Roll
- Tip front edge of board down dots go cw
- Tip up dots go ccw
Y Axis - Pitch
- Tip right edge of board down dots go ccw
- Tip up dots go cw
Z Axis - Yaw
- rotate ccw dots go cw
- rotate cw dots go ccw
So the next step is to perform the roll and pitch correction to get a valid compass reading even when the quad is pitching left and right.
The boys over in this forum thread seam to have that all organized as well.
http://aeroquad.com/showthread.php?6...hlight=HMC5843
Hope this helps anybody else who is trying to get this stuff all working together.
chris.





Email Blog Entry
