I was wondering how I could find which direction to turn to an angle the fastest based on the current angle.
I am using @jpearman 's gyro library (which totally rocks!) that returns a float between 0 and 359.9
The problem that is really getting me is how to make the robot differentiate that 0 degrees is closer to (for instance) 358 degrees than it is 10 degrees. Can I make a program do this and possibly make my PID loop have the ability to make this differentiation as well?
@discovery answered my question in a private message, seen below. I did end up making somewhat different equations to find the shortest angle based on the current angle and the target angle which were longer (at least calculation B) but the overall idea of calculating the degrees needed to turn and then using my PID loop on that really helped.
I ended up having it calculate a non-rollover value (calculation A, which is the degrees needed to not rollover zero, and can be returned as a negative or positive) and a rollover value (calculation B, degrees needed to rollover zero to desired angle, and can only return a negative) and then comparing the absolute values of each, choosing the lesser one, and inputting the real value of the chosen one to a function that uses PID to turn a certain amount of degrees so it knows which way to turn and how many degrees to turn.
Thanks!