Skip to content

fix(lis2mdl): Inconsistent atan2 argument order in heading_from_vectors. #344

@nedseb

Description

@nedseb

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions