This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Averaging of angles done incorrectly
#1
I looked at heading_filter function as example.
It applies low pass on angle value. Angle value is a circular parameter. I think it’s invalid way to average
 angles.
Correct way of averaging angles is low pass on sin and cos, the normalization and reverting back to angle with atan2.

It seems everywhere in the code averaging of angles is not right.

Average between 170 and -170 degrees is 180. It’s not 0 or
whatever weighted currently coded in low pass filters. 

Average between 1 and 359 is 0. It’s not 180

This will be possibly the reason people can’t get heading right even
with working IMUs. 

I think it a serious bug. 

I’ve reported it here:  https://github.com/pypilot/pypilot/issues/258

Thanks,
Fair Winds!
Download BBN Marine OS for raspberry pi 

https://bareboat-necessities.github.io/m...at-os.html

Video of actual installation:

https://www.youtube.com/watch?v=3zMjUs2X3qU


Reply
#2
it does resolve the headings so that the first one is +- 180 of the second one before. I dont think this is a bug.

I tried all your cases it works as expected. However using vectors requires more trig to be computed.
Reply
#3
Actually no issue there. The original code correctly used short path.
My bad and apologies for waisted time.
Download BBN Marine OS for raspberry pi 

https://bareboat-necessities.github.io/m...at-os.html

Video of actual installation:

https://www.youtube.com/watch?v=3zMjUs2X3qU


Reply
#4
Its ok I have done this myself. I'm glad you are looking into details trying to find issues.
Reply
#5
Gee, brilliant. Spent in some other project hours of coding trying to do it without trigonometric functions, then succumbed to those functions and subsequently running into quadrant ambiguity until I learned about atan2. Now it turns out it is as simple as this. Simplicity is engineer's perfection. Any time learning is certainly not wasted!
Reply
#6
(2025-07-09, 09:30 PM)ironman Wrote:  Any time learning is certainly not wasted!

Big Grin

Multi tasking too these days. 
With google set on the phone to use Gemini, making coffee this morning -  "OK google, write a radio documentary about atan2"

Couple of minutes of a nice lady talking. 
Ah, the unsung hero of the digital world, works in all 4 quadrants of the cartesian plane.  Cool
Reply
#7
Didn't know Gemini would work this way. This accelerates learning even more!
Reply
#8
(2025-07-10, 07:48 PM)ironman Wrote: Didn't know Gemini would work this way. This accelerates learning even more!

I use it quite a lot, something to listen to washing the dishes Smile 
"You are a geoligist and radio presented and sailor. Desribe the rock formations and geological history on a sailing trip down the french, spanish and portuguese coasts to Gibraltar."

Works on the laptop as well, at the bottom of the response click the 3 dots "More" there's a listen button.

" Good evening, fellow adventurers of the sea and land! This is your resident geologist, radio presenter, and sometime sailor, here to take you on a truly epic voyage down the Atlantic coasts of France, Spain, and Portugal, culminating at the grand Rock of Gibraltar. Prepare to be amazed by the ancient stories etched in the very rocks beneath our keel....."  Cool
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)