Heading > 180 degrees with magnetic declination

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
Batperson
Posts: 18
Joined: Mon May 11, 2015 2:52 pm

Heading > 180 degrees with magnetic declination

Post by Batperson »

Hi,

I noticed that if you configure a magnetic declination, positive headings extend beyond 180 degrees. Eg the declination where I am is 19.4 degrees and if I can have a heading of up to 199 degrees before it becomes negative.

This is occurring because the magnetic declination is simply added to the current heading without taking account of whether it should be positive or negative. This code change will fix it if inserted at line 264 in IMU.cpp.

Code: Select all

if(att.heading > 180)
  att.heading = -180 + (att.heading % 180);  // compensate for mag_declination
else if(att.heading < -179)
  att.heading = 180 + (att.heading % 180);

User avatar
Leo
Posts: 372
Joined: Wed Sep 17, 2014 7:01 am
Location: Germany
Contact:

Re: Heading > 180 degrees with magnetic declination

Post by Leo »

Thanks for this. I've updated my code on both my QC's.

Post Reply