This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.metalcowrobotics.rapinterpreter; | |
import java.util.HashMap; | |
import java.util.Map; | |
/* | |
Ever wanted to add and deal with units cleanly in Java? | |
Well now you can! | |
Include this file, and do stuff like this: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This only works if both of these variables are in the domain of [-180,180] | |
double currentHeading=90; | |
double desiredHeading=49; | |
// Do the subtraction | |
double error=currentHeading-desiredHeading; | |
// If the error is under -180, it is inefficient. So, add a full turn to that number. That way something like -190 becomes 170. The magnitude is smaller but if you plot that angle, it is the same angle. | |
if (error<-180) | |
error+=360; | |
// Same logic, but different signs. |