Created
January 21, 2015 17:47
-
-
Save MetalCow-Robotics/6688f5c2dccfa82deff4 to your computer and use it in GitHub Desktop.
Angle subtraction code
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. | |
else if (error>180) | |
error-=360; | |
SmartDashboard.putNumber("Angle error", angle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment