When I was simulating the boat movement in rough ocean waves, the compass output was too noisy and I wasn’t satisfied with the result. As the boat will be constantly climbing up a wave or surfing down a wave, the magnetometer is not reliable enough to estimate the correct heading. Fortunately, this kind of problem has already been solved in flying drones and I have implemented an open-source solution.
The new compass crunches the data from different sensors (magnetometer, accelerometer and gyro) and calculates not only the accurate heading, but also the pitch and the angle of heel. The boat knows how it is oriented with a 2-degree accuracy at any moment. Furthermore, the compass constantly auto-calibrates itself along the journey and adapts to the local Earth magnetic field. It’s a pretty advanced stuff. I have been testing the compass for a few days by constantly shaking it and logging the output. It seems the noise is completely eliminated.
There are four compasses and a dedicated microcontroller on the same board. If one compass fails for any reason, the microcontroller will automatically switch to the backup compass. The other two compasses are for experimental purposes. Each compass is actually a complex unit that consists of a magnetometer, accelerometer, gyro and a coprocessor that’s doing heavy calculations.
The board is potted in a thermally conductive epoxy to make it waterproof and mechanically robust.
With this compass, I solved another problem:
The compass must be located far away from high currents or anything that generates a magnetic field (solar panels, motors, magnets, etc.). Therefore it’s communicating with the main controller over a 1.5-meter long cable. The microcontroller that’s embedded in the new compass implements a communication protocol that’s more suitable for such a long distance (serial communication is for a long distance while the previous I2C protocol is reliable only at a very short distance).
The old compass is a tilt-compensated magnetometer and the noise occurs during fast up-and-down movements. The new compass is a more sophisticated solution that collects data from motion sensors and the noise is filtered out.