sparkfun/SparkFun_LSM9DS1_Arduino_Library

Code simplification?

KayakDiver opened this issue · 1 comments

In Examples-Basic I found:

if (heading > PI) heading -= (2 * PI);
else if (heading < -PI) heading += (2 * PI);
else if (heading < 0) heading += 2 * PI;

Could these 2 lines:
else if (heading < -PI) heading += (2 * PI);
else if (heading < 0) heading += 2 * PI;

be rewritten as:
else if (heading < 0) heading += (2 * PI);

What if, (by some miracle), (heading == PI) ?

Perhaps that last line could simply be:
else heading += (2 * PI);

Thank you for bringing this to our attention. It appears that the line else if (heading < 0) heading += 2 * PI; was erroneous and causing unexpected behaviors. This section is intended to constrain the value to the range from -π to π radians prior to be converting to degrees. The offending line of code caused the range to go from -π to 2π and caused some unexpected behavior when calculating heading. The latest commit reflects these changes. Please let us know if you have any questions or if you spot any more needlessly complicated or incorrect code!