Last active
January 16, 2019 19:10
-
-
Save jhh/98801440e6c924e38a91beb1911cca30 to your computer and use it in GitHub Desktop.
Minimum Swerve Wheel Rotation
This file contains hidden or 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
public class Main { | |
public static void main(String[] args) { | |
minRotation(359, 0); | |
minRotation(359, 1); | |
minRotation(90, -90); | |
minRotation(180, -180); | |
minRotationWithReverse(359, 1); | |
minRotationWithReverse(90, -90); | |
minRotationWithReverse(180, -180); | |
minRotationWithReverse(30, 270); | |
minRotationWithReverse(0, 90); | |
minRotationWithReverse(0, 91); | |
} | |
static void minRotation(double current, double desired) { | |
double rotation = Math.IEEEremainder(desired - current, 360); | |
System.out.printf("current = %7.2f, desired = %7.2f, rotation = %7.2f%n", current, desired, rotation); | |
} | |
static void minRotationWithReverse(double current, double desired) { | |
double rotation = Math.IEEEremainder(desired - current, 360); | |
boolean reverse = false; | |
if (Math.abs(rotation) > 90) { | |
rotation -= Math.copySign(180, rotation); | |
reverse = true; | |
} | |
System.out.printf("current = %7.2f, desired = %7.2f, rotation = %7.2f, reverse = %b %n", current, desired, rotation, reverse); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: