The compass actually consists of a single Micromag3 magnetometer and an SCA3000 accelerometer, arranged on a breadboard in the following configuration. The N+ means that the magnetometer reading is positive when the arrow points to magnetic North. Note the opposite directions of the Y-axis: this will be corrected in code by inverting the sign of the Y-axis accelerometer reading. The Z-axis points down in both cases.
The magnetometer has been calibrated using the same technique previously described for the accelerometer, with the following results:
The magnetometer reads continuously and consecutively the X, Y and Z axis. A complete measurement of the 3 axis takes about 105 ms. The microprocessor can take 31 complete accelerometer readings while waiting for the magnetometer to complete its measurements. The normalized average of these 31 measurements (ax, ay, az) is used in the calculations, along with the current magnetometer result (mx, my, mz).
The tilt-compensation equations are:
In this first example, the breadboard is tilted on its side to produce a heel angle of around 35 degrees, and then slowly comes back to horizontal, as shown by the green curve. This produces a huge variation in the uncorrected heading (the blue curve). The tilt compensation does a decent job, but not good enough, as the red curve should ideally be horizontal. This means that the calibration should be improved.
The next example illustrates the dynamic response, as the breadboard is tilted from one side to the other. What is interesting here is that the tilt compensation is able to follow the moving compass without problem.
The next step will be to implement more robust calibration procedures for the magnetometer and the accelerometer, adding required corrections for the lack of perpendicularity of the axes and linearity of the responses.