# Bno055 compass error

I'm using a BNO055 as a compass on my Ultralight airplane.
However I'm finding due to installation that it's off a few degrees. Can I just subtract the error from the compass reading and constrain() from 000-359? Or would that just cause the compass to stop if outside the 000-359 range until the reading is within? Ie raw reading is 003* but should be 353*, subtracting 10* from 003 I want it to show 353 and not -7

Is there a better way?

Bump

Ok so I figured out a solution on my own, but I'm wondering if there is a better way.

``````If (MAG == -1) {
MAG=359;
}
``````

Did this about 30 x to -30

``````If (MAG == 361) {
MAG = 1;
}
``````

Did this another 30 x to 390

Is there a more efficient way to do this?

Qhergt1987:
I’m using a BNO055 as a compass on my Ultralight airplane.
However I’m finding due to installation that it’s off a few degrees. Can I just subtract the error from the compass reading and constrain() from 000-359? Or would that just cause the compass to stop if outside the 000-359 range until the reading is within? Ie raw reading is 003* but should be 353*, subtracting 10* from 003 I want it to show 353 and not -7

Is there a better way?

assuming that the error is constant, it this what you are trying to achieve for any value received?

``````int corrected_val = raw_val-10; //since you use 10 in your example for correcting the value! ;)

if(corrected_val<0) corrected_val += 360; //gets rid of negative angles
else if(corrected_val>360) corrected_val -= 360;//for values beyond 360 degrees
``````

hope that helps

Absolutely. 160 lines of code down to 2!!!
Will have to test them both out and see.