A Marine-Optimized Tilt-Compensated Compass
Lightweight, robust heading for a sailboat
Designing a compass for a sailboat is very different from building one for a drone or a lab bench. Offshore, the boat is constantly rolling, pitching, yawing, vibrating, and occasionally passing near magnetic disturbances. A usable marine compass must remain smooth, stable, and trustworthy under all of that.
This implementation uses:
LSM6DSO (gyro + accelerometer)LIS3MDL (magnetometer)A lightweight complementary fusion structureA 50 Hz control loopThe goal is not maximum dynamics — it’s stable, natural marine behavior.
Sensor Setup (Optimized for Sailboats)
Update Rates
Accel/Gyro: 52 HzMagnetometer: 10 HzFusion loop: 50 HzSailboat heading changes are slow (typically < 1 Hz). Higher rates only add noise and CPU load without benefit.
Gyroscope Filtering
LPF1 set to 9.7 HzLPF2 fixed at 16.6 Hz (hardware)Why 9.7 Hz?
Because we only care about low-frequency yaw motion (helm input and waves). This setting:
Reduces vibration from hull and riggingStabilizes gyro integrationImproves sea-state detectionDoes not reduce steering responsivenessMagnetometer Configuration
ODR: 10 HzMode: Ultra-High PerformanceExternal 2nd-order low-pass ≈ 2 HzThis:
Passes real helm motionRejects wave spikesReduces magnetic jitterKeeps heading natural and smoothTilt Compensation
Roll and pitch are computed from the accelerometer and used to rotate the magnetic field into the horizontal plane before computing yaw.
This ensures correct heading even at 20–30° of heel — common under sail.
Fusion Strategy (Why Not Full AHRS?)
Instead of Mahony or Madgwick, this design uses a minimal complementary structure:
Gyro → short-term yaw stabilityMagnetometer → long-term heading referenceAccelerometer → tilt referenceAdvantages:
Predictable behaviorVery low CPU loadRuns on small microcontrollersEasy to tune for marine dynamicsThis is a deliberate choice: sailboats do not need aggressive high-dynamic fusion.
Adaptive Yaw Gain (Sea-State Aware)
A rolling RMS of gyro magnitude estimates boat motion.
Calm water → higher magnetic correction gainRough sea → reduced magnetic trustThis prevents wave-induced heading jitter while maintaining long-term accuracy.
Automatic Magnetic Anomaly Rejection
Magnetometer updates are rejected if:
Field magnitude deviates from expected normHeading jump exceeds plausible rateDuring rejection, the system runs gyro-only temporarily and resumes correction smoothly once the field stabilizes.
This is essential for real onboard installations.
Why This Works
Because it matches:
The frequency content of sailboat motionThe noise characteristics of MEMS sensorsThe computational limits of embedded hardwareThe real-world behavior of marine environmentsThe result is not just a tilt-compensated compass.
It’s a marine-tuned heading system — smooth in swell, responsive to the helm, stable near interference, and efficient enough to run continuously onboard.
No comments:
Post a Comment