New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

Reply To: Compass heading lags behind on turns in the console, is the filter wrong?

Translated from Türkçe by AI ·

Widening the window increases the delay, you need to do the opposite. I went through the same thing once while working with drones.The source of the lag is the average itself: a 20-sample moving average comes in about 1 second late, and the error grows as the turn rate increases. The calibration deficiency Büşra Hanım mentioned also explains the difference between right and left.The solution is to combine it with the gyroscope. The gyroscope sees the rotation instantly but drifts slowly, the magnetometer is slow but does not drift. A complementary filter combines the two:

// dt = 0.1 s, gz = derece/s (z ekseni jiroskop)
float a = 0.98;
heading = a * (heading + gz * dt) + (1 - a) * magHeading;
// 0/360 geçişini düzelt
float fark = magHeading - heading;
if (fark > 180) heading += 360 * (1 - a);
if (fark < -180) heading -= 360 * (1 - a);
heading = fmod(heading + 360, 360);

If the board has no gyroscope, adding an MPU6050 is the cheapest way. First, turn the boat two full circles in the water and perform the hard/soft iron calibration.The 180 issue is separate: an angle cannot be averaged. The average of 359 and 1 comes out as 180. The weekly chart reads hourly aggregated values and the default function is average. On the heading chart, set the function to last, and for analysis send heading_sin and heading_cos alongside the heading; their average comes out correctly.

Kayıtta yoksa olmamıştır.
Accepted solution♥ 7