-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converts the teeth amount of a gear to the pitch diameter. #72
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per #52 all these functions should return a Distance, which is a unit from wpilib. So that needs to be added to all functions. Also you'll need to include the following in your build.gradle in the
|
||
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; | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comparing floating point numbers with equality is generally considered bad practice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To use it just provide a third parameter which it the delta |
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)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to consistently name these functions. I propose renaming the functions to follow the format
pitchDiameterFromMechanismName
since that seems intuitiveFor example:
pitchDiameterFrom3mmPulley
orpitchDiameterFrom25ChainSprocket