Skip to content

Wind direction: circular median over averaging window#1

Draft
w1ndhunter wants to merge 1 commit into
mainfrom
cursor/circular-median-wind-direction-ea53
Draft

Wind direction: circular median over averaging window#1
w1ndhunter wants to merge 1 commit into
mainfrom
cursor/circular-median-wind-direction-ea53

Conversation

@w1ndhunter
Copy link
Copy Markdown
Owner

Summary

Wind direction during wind_speed_and_direction_avg was computed as a vector mean of per-sample directions, then quantized to 45° sectors. When the vane or ADC jitters between adjacent bins (e.g. W vs NW), the mean can drift and the reported heading can bounce.

This change keeps the same confidence check (normalized resultant length over samples) but replaces the final heading with the circular median on the 8-sector ring (indices 0..7): the sector that minimizes the sum of shortest arc distances in 45° steps. Ties favor the bin that appears most often, then the smaller index.

Details

  • New helpers: _wind_direction_resultant_from_bins and _circular_median_bin.
  • Samples still use voltage_to_degrees each dir_sample_interval_ms; only the aggregation from bin list to reported degrees changed.

Testing

No automated tests in repo for MicroPython board code; logic is pure Python and suitable for a quick desktop sanity check of _circular_median_bin if needed.

Open in Web Open in Cursor 

Replace vector mean of unit vectors with median on the 8-sector ring
to reduce flip-flopping when the vane jitters between adjacent bins.
Keep resultant-length check for low-confidence fallback to wind_direction().

Co-authored-by: Michael Lechner <w1ndhunter@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants