generated from wpilibsuite/vendor-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converts the teeth amount of a gear to the pitch diameter.
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
math/src/main/java/coppercore/math/GearConversionFunctions.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package coppercore.math; | ||
|
||
public class GearConversionFunctions { | ||
public static double pitchPulley3mm(int teeth) { | ||
teeth = Math.abs(teeth); | ||
double pitchDiameter = 3 * teeth / ((double) Math.PI); | ||
return pitchDiameter; | ||
} | ||
|
||
public static double pitchPulley5mm(int teeth) { | ||
teeth = Math.abs(teeth); | ||
double pitchDiameter = 5 * teeth / ((double) Math.PI); | ||
return pitchDiameter; | ||
} | ||
|
||
public static double pulleyRT25(int teeth) { | ||
teeth = Math.abs(teeth); | ||
double pitchDiameter = 0.25 * teeth / ((double) Math.PI); | ||
return pitchDiameter; | ||
} | ||
|
||
public static double chainSprocket25(int teeth) { | ||
teeth = Math.abs(teeth); | ||
double pitchDiameter = 0.25 / (double) Math.sin(Math.PI / teeth); | ||
return pitchDiameter; | ||
} | ||
|
||
public static double chainSprocket35(int teeth) { | ||
teeth = Math.abs(teeth); | ||
double pitchDiameter = 0.375 / (double) Math.sin(Math.PI / teeth); | ||
return pitchDiameter; | ||
} | ||
|
||
public static double gear20DP(int teeth) { | ||
teeth = Math.abs(teeth); | ||
double pitchDiameter = (double) teeth / 20; | ||
return pitchDiameter; | ||
} | ||
|
||
public static double gear32DP(int teeth) { | ||
teeth = Math.abs(teeth); | ||
double pitchDiameter = (double) teeth / 32; | ||
return pitchDiameter; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
math/src/test/java/coppercore/math/GearConversionTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package coppercore.math; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class GearConversionTest { | ||
@Test | ||
public void pitchPulley3mmTest() { | ||
Assertions.assertEquals(12 / (Math.PI), GearConversionFunctions.pitchPulley3mm(4)); | ||
Assertions.assertEquals(150 / (Math.PI), GearConversionFunctions.pitchPulley3mm(50)); | ||
Assertions.assertEquals(0 / (Math.PI), GearConversionFunctions.pitchPulley3mm(0)); | ||
Assertions.assertEquals(21 / (Math.PI), GearConversionFunctions.pitchPulley3mm(-7)); | ||
} | ||
|
||
@Test | ||
public void pitchPulley5mmTest() { | ||
Assertions.assertEquals(20 / (Math.PI), GearConversionFunctions.pitchPulley5mm(4)); | ||
Assertions.assertEquals(250 / (Math.PI), GearConversionFunctions.pitchPulley5mm(50)); | ||
Assertions.assertEquals(0 / (Math.PI), GearConversionFunctions.pitchPulley5mm(0)); | ||
Assertions.assertEquals(35 / (Math.PI), GearConversionFunctions.pitchPulley5mm(-7)); | ||
} | ||
|
||
@Test | ||
public void pulleyRT25Test() { | ||
Assertions.assertEquals(1 / (Math.PI), GearConversionFunctions.pulleyRT25(4)); | ||
Assertions.assertEquals(13 / (Math.PI), GearConversionFunctions.pulleyRT25(52)); | ||
Assertions.assertEquals(0 / (Math.PI), GearConversionFunctions.pulleyRT25(0)); | ||
Assertions.assertEquals(2 / (Math.PI), GearConversionFunctions.pulleyRT25(-8)); | ||
} | ||
|
||
@Test | ||
public void chainSprocket25Test() { | ||
Assertions.assertEquals( | ||
0.25 / (1 / Math.sqrt(2)), GearConversionFunctions.chainSprocket25(4)); | ||
Assertions.assertEquals( | ||
0.25 / (Math.sqrt(3) / 2), GearConversionFunctions.chainSprocket25(3)); | ||
} | ||
|
||
@Test | ||
public void chainSprocket35Test() { | ||
Assertions.assertEquals( | ||
0.375 / (1 / Math.sqrt(2)), GearConversionFunctions.chainSprocket35(4)); | ||
Assertions.assertEquals( | ||
0.375 / (Math.sqrt(3) / 2), GearConversionFunctions.chainSprocket35(3)); | ||
} | ||
|
||
@Test | ||
public void gear20DPTest() { | ||
Assertions.assertEquals(0.2, GearConversionFunctions.gear20DP(4)); | ||
Assertions.assertEquals(1, GearConversionFunctions.gear20DP(20)); | ||
Assertions.assertEquals(0, GearConversionFunctions.gear20DP(0)); | ||
Assertions.assertEquals(2.0, GearConversionFunctions.gear20DP(-40)); | ||
} | ||
|
||
@Test | ||
public void gear32DPTest() { | ||
Assertions.assertEquals(0.125, GearConversionFunctions.gear32DP(4)); | ||
Assertions.assertEquals(1.0, GearConversionFunctions.gear32DP(32)); | ||
Assertions.assertEquals(0, GearConversionFunctions.gear32DP(0)); | ||
Assertions.assertEquals(2.0, GearConversionFunctions.gear32DP(-64)); | ||
} | ||
} |