Problem
In lib/lis2mdl/lis2mdl/device.py:561, heading_from_vectors() calls math.atan2(x, y):
ang = math.degrees(math.atan2(x, y)) # atan2(Y, X) for compass heading
But the tilt-compensated path in the same file uses math.atan2(yh, xh), which is the correct convention for compass heading (Y is forward, X is right).
With a flat board (roll/pitch = 0), the two methods produce different headings because the argument order is swapped.
Expected behavior
Both paths should use atan2(y, x) consistently for compass heading.
Proposed fix
ang = math.degrees(math.atan2(y, x))
Impact
This affects heading_flat_only() when called via heading_from_vectors(). The tilt-compensated heading is correct.
Found by
Copilot review on PR #343.
Problem
In
lib/lis2mdl/lis2mdl/device.py:561,heading_from_vectors()callsmath.atan2(x, y):But the tilt-compensated path in the same file uses
math.atan2(yh, xh), which is the correct convention for compass heading (Y is forward, X is right).With a flat board (roll/pitch = 0), the two methods produce different headings because the argument order is swapped.
Expected behavior
Both paths should use
atan2(y, x)consistently for compass heading.Proposed fix
Impact
This affects
heading_flat_only()when called viaheading_from_vectors(). The tilt-compensated heading is correct.Found by
Copilot review on PR #343.