Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magnetic declination West (negative value) causes incorrect heading calculation #123

Open
AlexC176 opened this issue Jun 4, 2022 · 0 comments

Comments

@AlexC176
Copy link

AlexC176 commented Jun 4, 2022

Some more tracker testing and tuning. Using a west magnetic declination of -1556 causes an overflow of the tracker heading at approx 350 degrees. Version 11.1.0 on SPRacing hardware.

flight / imu.c file
function int16_t imuCalculateHeading(t_fp_vector *vec)

For bearings close to North (example -10) the calculation results in a int16_t overflow/underflow
return (int16_t) ((hd * 1800.0 / M_PIf) + magneticDeclination + OFFSET * 10.0f)%3600;

Suggest

float truehd = ((hd * 1800.0 / M_PIf) + magneticDeclination + OFFSET * 10.0f);
// always positive
if ( truehd < 0.0f ) { truehd = truehd + 3600.0f; )
return (int16_t) truehd%3600;

This same issue can be replicated using negative offsets. For example: magneticDeclination +10degrees (E), OFFSET -15degrees

@AlexC176 AlexC176 changed the title Magnetic declination West (negative value) cause incorrect heading calculation Magnetic declination West (negative value) causes incorrect heading calculation Jun 4, 2022
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

No branches or pull requests

1 participant