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.
Pencereyi büyütmek gecikmeyi artırır, tersini yapmak lazım. Bir dönem drone ile uğraşırken aynı şeyi yaşadım.
Gecikmenin kaynağı ortalamanın kendisi: 20 okumalık hareketli ortalama yaklaşık 1 saniye geriden gelir, dönüş hızı arttıkça hata büyür. Büşra Hanım’ın dediği kalibrasyon eksikliği de sağ-sol farkını açıklıyor.
Çözüm jiroskopla birleştirmek. Jiroskop dönüşü anında görür ama yavaşça kayar, manyetometre yavaş ama kaymaz. Tamamlayıcı filtre ikisini birleştirir:
// 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);
Kartta jiroskop yoksa bir MPU6050 eklemek en ucuz yol. Önce tekneyi suda iki tam tur döndürüp hard/soft iron kalibrasyonunu yapın.
180 meselesi ayrı: açının ortalaması alınamaz. 359 ile 1’in ortalaması 180 çıkar. Haftalık grafik saatlik toplu değerleri okuyor ve varsayılan fonksiyon ortalama. Başlık grafiğinde fonksiyonu last yapın, analiz için de başlığın yanında heading_sin ve heading_cos gönderin, onların ortalaması doğru çıkar.

