I am building a tilt-compensated magnetic compass for another autonomous vehicle project I am starting. The vehicle ground speed will be relatively slow and tilt should never exceed 20 degrees in the x or y axes for this application. I hope to use old hardware I had in my parts drawers, but that is presenting some questions.
My compass is a Devantech CMPS03 and my Accelerometer is a Dimension Engineering DE-ACCM2G2 Buffered 2G Accelerometer.
I have both units running a simple test program on A RedBoard Turbo SAMD21 board. I did some level shifting on the PWM output from the Compass because I wanted to be sure not to damage the SAMD21 board.
The Compass calibrates well and gives satisfactory headings while sitting level, and the accelerometer gives good steady indications of tilt in the x/y axes up to about 70 degrees, which is good for my application. My challenge now is in applying the pitch/roll readings into compensation coefficients for the heading angle, and this is presenting me with just one challenge: Even though prior to posting this I have done days of searching and research, and having found a bewildering array of formulas and code for magnetic compass tilt compensation, everything I have seen thus far addresses applying accelerometer (and sometimes gyro) pitch/roll (and sometimes yaw) factors to the x/y/z magnetometer values, and then deriving a heading angle.
My challenge, on the other hand, is that I do not have direct access to the x/y/z magnetometer outputs in my application. The CMPS03 compass module I am using only feeds the actual (but uncorrected) magnetic heading value. I would think there must be some way to apply the pitch/roll values to my heading angle as it is, without needing to know the x/y magnetometer values from which the heading was calculated.
I feel that if I was just a bit more comfortable with my trig functions I could work through this myself, but it is a bit much for me. I am thinking that by breaking down the problem in four functions, each addressing its own quadrant, I might simplify the task, but thus far I am still hitting a wall.
I had even considered simply building a number of lookup tables by experimentation and just looking up a given compensation angle based on heading/pitch and roll, but in order to build those lookup tables to apply through 360 degrees of rotation and possible +/- 20 degrees of tilt in the x/y axes, I decided that approach would be possible, but cumbersome.
I am hoping someone with stronger math skills than mine can provide a solution here. Again, I have magnetic heading being read out in degrees, I have pitch and roll being read out in degrees +/- 0 with 0 as the origin (level). FYI I am at around 46 degrees latitude with local magnetic declination around 15 degrees east and magnetic inclination (dip) of about 69 degrees.
Any help is much appreciated.- Rob