-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: thenetworkgrinch <thenetworkgrinch@users.noreply.github.com>
- Loading branch information
1 parent
08f4c9a
commit 05bce95
Showing
6 changed files
with
200 additions
and
17 deletions.
There are no files selected for viewing
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 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 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
41 changes: 41 additions & 0 deletions
41
src/main/java/swervelib/parser/json/modules/AngleConversionFactorsJson.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,41 @@ | ||
package swervelib.parser.json.modules; | ||
|
||
import swervelib.math.SwerveMath; | ||
import swervelib.telemetry.Alert; | ||
import swervelib.telemetry.Alert.AlertType; | ||
|
||
/** | ||
* Angle motor conversion factors composite JSON parse class. | ||
*/ | ||
public class AngleConversionFactorsJson | ||
{ | ||
|
||
/** | ||
* Gear ratio for the angle/steering/azimuth motor on the Swerve Module. Motor rotations to 1 wheel rotation. | ||
*/ | ||
public double gearRatio = 0; | ||
/** | ||
* Calculated or given conversion factor. | ||
*/ | ||
public double factor = 0; | ||
|
||
/** | ||
* Calculate the drive conversion factor. | ||
* | ||
* @return Drive conversion factor, if factor isn't set. | ||
*/ | ||
public double calculate() | ||
{ | ||
if (factor != 0 && gearRatio != 0) | ||
{ | ||
new Alert("Configuration", | ||
"The given angle conversion factor takes precedence over the composite conversion factor, please remove 'factor' if you want to use the composite factor instead.", | ||
AlertType.WARNING).set(true); | ||
} | ||
if (factor == 0) | ||
{ | ||
factor = SwerveMath.calculateDegreesPerSteeringRotation(gearRatio); | ||
} | ||
return factor; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/swervelib/parser/json/modules/ConversionFactorsJson.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,37 @@ | ||
package swervelib.parser.json.modules; | ||
|
||
/** | ||
* Conversion Factors parsed JSON class | ||
*/ | ||
public class ConversionFactorsJson | ||
{ | ||
|
||
/** | ||
* Drive motor conversion factors composition. | ||
*/ | ||
public DriveConversionFactorsJson drive = new DriveConversionFactorsJson(); | ||
/** | ||
* Angle motor conversion factors composition. | ||
*/ | ||
public AngleConversionFactorsJson angle = new AngleConversionFactorsJson(); | ||
|
||
/** | ||
* Check if the conversion factors are set for the drive motor. | ||
* | ||
* @return Empty | ||
*/ | ||
public boolean isDriveEmpty() | ||
{ | ||
return drive.factor == 0 && drive.diameter == 0 && drive.gearRatio == 0; | ||
} | ||
|
||
/** | ||
* Check if the conversion factors are set for the angle motor. | ||
* | ||
* @return Empty | ||
*/ | ||
public boolean isAngleEmpty() | ||
{ | ||
return angle.factor == 0 && angle.gearRatio == 0; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/swervelib/parser/json/modules/DriveConversionFactorsJson.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,46 @@ | ||
package swervelib.parser.json.modules; | ||
|
||
import edu.wpi.first.math.util.Units; | ||
import swervelib.math.SwerveMath; | ||
import swervelib.telemetry.Alert; | ||
import swervelib.telemetry.Alert.AlertType; | ||
|
||
/** | ||
* Drive motor composite JSON parse class. | ||
*/ | ||
public class DriveConversionFactorsJson | ||
{ | ||
|
||
/** | ||
* Gear ratio for the drive motor rotations to turn the wheel 1 complete rotation. | ||
*/ | ||
public double gearRatio = 0; | ||
/** | ||
* Diameter of the wheel in inches. | ||
*/ | ||
public double diameter = 0; | ||
/** | ||
* Calculated conversion factor. | ||
*/ | ||
public double factor = 0; | ||
|
||
/** | ||
* Calculate the drive conversion factor. | ||
* | ||
* @return Drive conversion factor, if factor isn't set. | ||
*/ | ||
public double calculate() | ||
{ | ||
if (factor != 0 && (diameter != 0 || gearRatio != 0)) | ||
{ | ||
new Alert("Configuration", | ||
"The given drive conversion factor takes precedence over the composite conversion factor, please remove 'factor' if you want to use the composite factor instead.", | ||
AlertType.WARNING).set(true); | ||
} | ||
if (factor == 0) | ||
{ | ||
factor = SwerveMath.calculateMetersPerRotation(Units.inchesToMeters(this.diameter), this.gearRatio); | ||
} | ||
return factor; | ||
} | ||
} |