Quote:
Originally Posted by Joe Ross
It's in Math, rather then the squawk MathUtils workaround, but it still works.
|
Thanks Joe.
For those of you reading this thread for the first time, Math.IEEEremainder(angle,360.0) can be used to convert any angle (in degrees) to the range -180 to 180.
This can be very useful when working with the gyro.
Let's say you want to find the shortest angular error between your joystick direction angle and the gyro angle. This can be accomplished in one clean line of code as follows:
angle_error = Math.IEEEremainder(joystick-gyro,360.0);
There's no need for conditional logic. It cleanly handles all input angle ranges for joystick and gyro, including angles greater than 360 degrees and less than -360 degrees.
The above assumes that gyro and joystick share the same zero and measurement direction.