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);