Last active
January 16, 2019 19:29
-
-
Save jhh/cf77dbaadc9622aa1fd2e9edf4c6a58b to your computer and use it in GitHub Desktop.
Azimuth Encoder Calcs
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) { | |
minRotationIEEERemainder(4095, 1); // expect +2 | |
minRotationIEEERemainder(10 * 0x1000 + 4095, 1); // same, plus 10 revolutions | |
minRotationIEEERemainder(-1024, 1024); // expect +/- 2048 | |
minRotationIEEERemainder(10 * 0x1000 - 1024, 1024); // same, plus 10 revolutions | |
minRotationIEEERemainder(2730, 1365); // 240 -> 120 expect -120 (-1365) | |
minRotationIEEERemainder(10 * 0x1000 + 2730, 1365); // 240 -> 120 expect -120 (-1365) | |
minRotationMaskCurrent(4095, 1); // expect +2 | |
minRotationMaskCurrent(10 * 0x1000 + 4095, 1); // same, plus 10 revolutions | |
minRotationMaskCurrent(-1024, 1024); // expect +/- 2048 | |
minRotationMaskCurrent(10 * 0x1000 - 1024, 1024); // same, plus 10 revolutions | |
minRotationMaskCurrent(2730, 1365); // 240 -> 120 expect -120 (-1365) | |
minRotationMaskCurrent(10 * 0x1000 + 2730, 1365); // 240 -> 120 expect -120 (-1365) | |
minRotationMaskError(4095, 1); // expect +2 | |
minRotationMaskError(10 * 0x1000 + 4095, 1); // same, plus 10 revolutions | |
minRotationMaskError(-1024, 1024); // expect +/- 2048 | |
minRotationMaskError(10 * 0x1000 - 1024, 1024); // same, plus 10 revolutions | |
minRotationMaskError(2730, 1365); // 240 -> 120 expect -120 (-1365) | |
minRotationMaskError(10 * 0x1000 + 2730, 1365); // 240 -> 120 expect -120 (-1365) | |
} | |
static void minRotationIEEERemainder(int current, int desired) { | |
double rotation = Math.IEEEremainder(desired - current, 0x1000); | |
System.out.printf( | |
"IEEERemainder: current = %7d, desired = %7d, rotation = %7.0f%n", | |
current, desired, rotation); | |
} | |
static void minRotationMaskCurrent(int current, int desired) { | |
int rotation = desired - (current & 0xFFF); | |
System.out.printf( | |
"Mask Current: current = %7d, desired = %7d, rotation = %7d%n", | |
current, desired, rotation); | |
} | |
static void minRotationMaskError(int current, int desired) { | |
int rotation = (desired - current) & 0xFFF; | |
System.out.printf( | |
"Mask Error: current = %7d, desired = %7d, rotation = %7d%n", | |
current, desired, rotation); | |
} | |
} |
Author
jhh
commented
Jan 16, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment