Boat Heave Sensor on m5stack atomS3.
m5stack atomS3 is ESP32 microcontroller with built-in IMU MPU6886 (accelerometer and gyroscope)
Use arduino IDE to compile and upload sketch to esp32
Check required libraries and version in .github/workflows/build.yaml
Produces NMEA-0183 XDR sentences over USB (See NmeaXDR.h). Baud rate: 115200.
Mount atomS3 with LCD facing up.
Estimate vessel heave (vertical displacement) in ocean waves using IMU on esp32
The method for estimating wave height and heave from a moving boat implemented here using the following on-line algorithm:
- Sample MPU6886 3D acceleration and 3D gyroscope (angular velocities) measurements at about 250 Hz.
- Estimate attitude and get attitude quaternion using Mahony algorithm. Using acceleration and gyroscope is enough. No magnetometer is required because we are only interested in vertical acceleration for the next steps.
- Double integrate vertical acceleration into vertical displacement using specially designed Kalman filter which corrects for integral drift in wave and corrects for the constant accelerometer bias.
- Estimate observed heave frequency with Aranovskiy on-line filter (without need for FFT). The correction for accelerometer bias is important for this step.
- Smooth frequency produced by Aranovskiy filter with Kalman smoother.
- Use another specially designed Kalman filter knowing the frequency and fusing model with trochoidal wave model to double integrate vertical acceleration. Assuming convergence of frequency, this method would give real-time phase correction of heave compared to the first Kalman method. Doppler effect due to boat movement in waves has no impact on displacement amplitude.
Kalman filter to double integrate vertical acceleration in wave into vertical displacement, correct for accelerometer bias, estimate accelerometer bias, correct integral for zero average displacement. The third integral (responsible for zero average vertical displacement) is taken as a measurement of zero.
Process model:
velocity:
displacement:
displacement integral:
accelerometer bias:
State vector:
Process model in matrix form:
Input
Measurement
Observation matrix:
Process matrix:
Transition matrix:
Kalman filter to estimate vertical displacement in wave using accelerometer, correct for accelerometer bias, estimate accelerometer bias. This method assumes that displacement follows trochoidal model and the frequency of wave is known. Frequency can be estimated using another step with Aranovskiy filter.
In trochoidal wave model there is simple linear dependency between displacement and acceleration.
wave length L:
wave period via frequency:
acceleration:
let
Process model:
displacement integral:
displacement:
velocity:
acceleration (from trochoidal wave model):
accelerometer bias:
Process model in matrix form:
State vector:
Input
Measurements:
Observation matrix:
Process matrix:
- Rolling min/max algorithm with window of about a couple wave period samples to produce wave height measurements. Algorithm: https://github.com/lemire/runningmaxmin from Daniel Lemire paper, and improvements from: https://github.com/EvanBalster/STL_mono_wedge
- Provide real-time heave data for ships with active heave compensation system (pipe laying ships, crane platforms, etc)
- Recording sea state
- Prediction of likelihood of sea sickness
- Estimating risk of breaking from anchor
- Autotuning gains of autopilots
wget https://github.com/bareboat-necessities/bbn-wave-period-esp32/releases/download/v0.9.9/bbn_wave_freq_m5atomS3_bin-2024-12-07.zip
unzip bbn_wave_freq_m5atomS3_bin-2024-12-07.zip
/srv/esphome/bin/esptool.py --chip esp32s3 --port "/dev/ttyACM0" --baud 921600 --before default_reset --after hard_reset write_flash 0x0 bbn_wave_freq_m5atomS3_firmware.bin
wget https://raw.githubusercontent.com/bareboat-necessities/my-bareboat/refs/heads/master/m5stack-tools/bbn-flash-m5-wave.sh
chmod +x bbn-flash-m5-wave.sh
./bbn-flash-m5-wave.sh -p /dev/ttyACM0
- Try to find a way for mpu6886 to sample at higher (than 250Hz) frequency
- The method can be improved for less regular waves by splitting original signal with band pass filter into several signals of different frequencies bands. Then it would be possible to apply the method separately to each band and sum up the results received for each band. Effectively it would approximate the signal spectrum and identify main frequency within each band, giving possibly better results. Coefficients used by filters can be tuned better for each band to give faster convergence.
https://bareboat-necessities.github.io/
https://github.com/bareboat-necessities/bbn-m5atomS3-lite
-
Alexey A. Bobtsov, Nikolay A. Nikolaev, Olga V. Slita, Alexander S. Borgul, Stanislav V. Aranovskiy: The New Algorithm of Sinusoidal Signal Frequency Estimation. 11th IFAC International Workshop on Adaptation and Learning in Control and Signal Processing, 2013
-
Sharkh S. M., Hendijanizadeh2 M., Moshrefi-Torbati3 M., Abusara M. A.: A Novel Kalman Filter Based Technique for Calculating the Time History of Vertical Displacement of a Boat from Measured Acceleration, Marine Engineering Frontiers Volume 2, 2014
-
Daniel Lemire, Streaming Maximum-Minimum Filter Using No More than Three Comparisons per Element. Nordic Journal of Computing, 13 (4), pages 328-339, 2006.
-
Trochoidal Wave Wikipedia