True Story Follows
So I’m on the grind like Rumpelstiltskin turning keyboard strokes into gold and developing an autopilot module for Blimp Drones. I bought the super convenient and excellent hardware package, the Navio2 in conjunction with a Raspberry Pi, but I had some problems getting the compass working properly. Pitch and roll are quite simple because the direction is relative only to gravity, but getting an azimuth can be trickier because this direction relies on a compass.
From the example code packaged with the Navio, I could not get yaw working. It demonstrated how raw values could be obtained, but the hurdle to ascertain a compass heading from the raw values was not as trivial to me as it was made out to be. I ended up taking the arc tangent of raw magnetometer values, but it turns out this only works if the device is perfectly flat (no pitch or roll). That, of course, is not a valid assumption for an aircraft. The other example code I could find on the internets was coupled to a particular hardware set (mostly Arduino’s). Compilation required dependencies that I didn’t have, and it wasn’t so straightforward to extract the exact components.
After a little bit of effort, I’ve distilled the publicly available code on the internets into a more straightforward package meant to be compiled on a Raspberry Pi in conjunction with a Navio2.
All of the code for this project can be found on GitHub.
- Does this code work? Yes.
- Is there copied code from Emlid? Yes.
- Do I owe Kris Winer a beer based on his licensing agreements? Yes
- Does it have corresponding test coverage? No.
- Are there some hacks in place to make it work? Yes (Rather than figure out orienting the x, y, z planes properly I just added degree offsets to final values)
With that said, here’s some example usage of the 3d compass files: