Magnetometers and compass nightmares

Từ kế và cơn ác mộng la bàn

A magnetometer measures the magnetic field vector B in microteslas, reporting three orthogonal components in the phone's body frame. Earth's field ranges from roughly twenty-five to sixty-five microteslas depending on latitude and local geomagnetic anomalies — strong enough to orient a compass outdoors, yet fragile enough that a steel parking column two meters away can rotate the apparent north direction by forty to ninety degrees without the phone moving at all. Wheria's heading pipeline treats the compass as guilty until proven innocent: magnetometer measurements enter the fusion filter only when field magnitude and inclination fall within expected Earth bands, and the user interface surfaces distrust explicitly rather than drawing a confident arrow toward a wall.

Calibration literature distinguishes two distortion mechanisms that matter in practice. Hard iron errors produce constant offsets on each sensor axis — a speaker magnet, a ferrous phone case, or permanent magnetization of nearby steel shifts the center of the magnetometer's measurement ellipsoid away from the origin. Users can partially correct hard iron by tracing a figure-eight motion that samples the field across orientations, allowing an algebraic fit to estimate the offset vector. Soft iron errors arise when ferromagnetic material nearby distorts the field itself, stretching the ellipsoid into an ellipse rather than translating it. Parking pillars, rebar in concrete, and the body of your own car create soft iron distortion that varies with position, meaning calibration valid at one row may fail three meters later.

Fusion when the field lies

Textbook three-by-three soft-iron calibration requires diverse phone orientations sampled over time — excellent in a laboratory, unrealistic when someone is walking through a basement trying to remember whether they turned left at pillar forty-seven. Our approach calibrates slowly during straight walking segments, accumulating samples only when the gyroscope reports low turn rate, and discarding measurements when the user turns sharply because the magnetic field direction should not change at the rate a quick pivot produces. Between detected steps, the gyroscope integrates heading at one hundred to two hundred hertz with drift on the order of one to three degrees per minute without correction — acceptable over the half-second gap between footfalls but unacceptable over a two-minute walk without magnetometer assistance.

When variance of heading residuals spikes — the telltale signature of entering a steel zone near EV charging stations where DC cables and transformers superimpose local fields — the Extended Kalman Filter inflates magnetometer measurement noise R by an order of magnitude, effectively reducing to gyro-only dead reckoning until the field stabilizes. The interface responds with a yellow or red compass confidence chip and widens the augmented-reality arrow's cone of uncertainty. If heading standard deviation exceeds twenty-five degrees, Find mode shifts to distance-first presentation: walk approximately sixty meters, then rescan compass in a clearer area. We would rather under-instruct than confidently navigate you into structural concrete.

Real-world offenders and platform parity

ktuyen's regression matrix documents the worst environments: electric vehicle charging bays with heavy DC cabling, structural steel within two meters of the walking path, and the occasional second phone in a back pocket creating a moving hard-iron source. iOS and Android report magnetometer axes with different native conventions; we normalize to a consistent north-east-down or east-north-up frame in shared logic modules before either SwiftUI or Compose renders direction. Phyzix shows raw and calibrated magnetometer vectors side by side, letting students watch the ellipsoid flatten as they walk into Landmark 81's basement — the same data Wheria uses, presented as physics rather than navigation.

We do not promise five-degree compass accuracy in all garages because physics does not permit that promise. We promise not to navigate you confidently into a wall, and we promise that when the instrument distrusts itself, you see that distrust on screen. The Kalman fusion mathematics are detailed in Kalman filters for parking; step-based position updates that heading feeds into are covered in step detection and IMU odometry; the broader indoor context lives in indoor navigation when GPS dies.

Từ kế đo vector từ trường B theo microtesla, báo ba thành phần trực giao trong khung thân máy. Từ trường Trái Đất khoảng 25–65 µT tùy vĩ độ và anomaly địa từ local — đủ orient la bàn ngoài trời, nhưng mong manh đến mức cột thép hầm cách hai mét có thể xoay hướng bắc hiệu dụng 40–90° mà máy không hề di chuyển. Pipeline heading Wheria coi la bàn có tội đến khi chứng minh ngược lại: đo từ kế chỉ vào bộ lọc fusion khi độ lớn field và inclination nằm trong band Trái Đất kỳ vọng, và giao diện thể hiện nghi ngờ tường minh thay vì vẽ mũi tên tự tin về phía tường.

Literature hiệu chuẩn phân biệt hai cơ chế méo thực tế quan trọng. Lỗi hard iron tạo offset hằng trên mỗi trục cảm biến — nam châm loa, ốp sắt, hoặc từ hóa thép gần lệch tâm ellipsoid đo từ kế khỏi gốc. User có thể hiệu chuẩn phần hard iron bằng động tác figure-eight lấy mẫu field qua nhiều hướng, cho fit đại số ước lượng vector offset. Lỗi soft iron xảy ra khi vật ferromagnetic gần méo field, kéo ellipsoid thành ellipse thay vì chỉ dịch chuyển. Cột hầm, cốt thép bê tông và thân xe bạn tạo méo soft iron thay đổi theo vị trí — calibrate đúng ở một hàng có thể fail ba mét sau.

Fusion khi field nói dối

Hiệu chuẩn soft-iron ma trận 3×3 kinh điển cần nhiều tư thế phone theo thời gian — tuyệt trong lab, không thực tế khi ai đó đi hầm cố nhớ quẹo trái ở cột 47. Cách team calibrate chậm trong đoạn đi thẳng, tích lũy mẫu chỉ khi con quay báo tốc quay thấp, và bỏ đo khi user quẹo gắt vì hướng từ trường không nên đổi nhanh như pivot. Giữa các bước phát hiện, con quay tích heading 100–200 Hz với drift ~1–3°/phút không hiệu chỉnh — chấp nhận trong khe ~0,5 giây giữa bước chân nhưng không chấp nhận qua walk hai phút không hỗ trợ từ kế.

Khi phương sai residual heading tăng vọt — dấu hiệu vào vùng thép gần trạm sạc EV với cáp DC và transformer chồng field local — Extended Kalman Filter phồng nhiễu đo từ kế R lên một bậc, thực tế giảm về dead reckoning chủ yếu gyro đến khi field ổn. Giao diện phản hồi chip confidence la bàn vàng hoặc đỏ và mở rộng cone uncertainty mũi tên AR. Nếu độ lệch chuẩn heading vượt 25°, Find mode chuyển presentation ưu tiên khoảng cách: đi khoảng 60 m, rồi quét la bàn ở vùng thoáng. Team thà hướng dẫn ít còn hơn chỉ sai tự tin vào bê tông kết cấu.

Thủ phạm thực tế và parity nền tảng

Ma trận regression ktuyen ghi môi trường tệ nhất: bãi sạc EV cáp DC nặng, thép kết cấu trong 2 m lối đi, và thỉnh thoảng điện thoại thứ hai trong túi sau tạo nguồn hard-iron di chuyển. iOS và Android báo trục từ kế convention native khác; team normalize khung north-east-down hoặc east-north-up nhất quán trong module logic dùng chung trước khi SwiftUI hay Compose render hướng. Phyzix hiện vector từ kế raw và calibrated cạnh nhau, cho học sinh xem ellipsoid méo khi bước vào hầm Landmark 81 — cùng data Wheria dùng, trình bày như vật lý thay vì navigation.

Team không hứa accuracy la bàn 5° mọi hầm vì vật lý không cho phép hứa đó. Team hứa không chỉ sai tự tin vào tường, và hứa khi dụng cụ nghi ngờ chính nó, bạn thấy nghi ngờ đó trên màn hình. Toán fusion Kalman chi tiết trong bộ lọc Kalman cho đỗ xe; cập nhật vị trí theo bước mà heading nuôi: phát hiện bước và IMU odometry; bối cảnh indoor rộng: dẫn đường trong nhà khi GPS chết.