Skip to content

Commit

Permalink
Fix Logic for Backlash Removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Java4First committed Mar 29, 2024
1 parent d108b58 commit 0c47c9d
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/main/java/frc/robot/subsystems/Mast.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public double getAngle() {
CommandXboxController operPad;

LoggedDashboardNumber testingAngleNumber;
private static double counts = 0; // used for encoder sync
private int counts = 0; // used for encoder sync

private static Task currentTask;
private static final double gearRatio = (48.0 / 32.0) * 125.0;
Expand Down Expand Up @@ -188,14 +188,30 @@ public void periodic() {
double error = relEncoderDeg - absEncoderDeg;

// Remove backlash from Launcher by syncing constantly
if (++counts == 30 && Math.abs(error) > .4) {
// double AbsToRel = getAbsoluteEncoderDegrees() * gearRatio / 360;
double AbsToRel =
new BigDecimal(absEncoderDeg * gearRatio / 360)
.setScale(3, RoundingMode.DOWN)
.doubleValue();
relMastLeftEncoder.setPosition(AbsToRel);
// if (++counts == 30 && Math.abs(error) > .4) {
// // double AbsToRel = getAbsoluteEncoderDegrees() * gearRatio / 360;
// double AbsToRel = new BigDecimal(absEncoderDeg * gearRatio / 360)
// .setScale(3, RoundingMode.DOWN)
// .doubleValue();
// relMastLeftEncoder.setPosition(AbsToRel);
// counts = 0;
// }

if (++counts >= 30) {
if (Math.abs(error) > .4) {
// System.out.println("*** fixing at " + counts);
// double AbsToRel = getAbsoluteEncoderDegrees() * gearRatio / 360;
double AbsToRel =
new BigDecimal(absEncoderDeg * gearRatio / 360)
.setScale(3, RoundingMode.DOWN)
.doubleValue();
relMastLeftEncoder.setPosition(AbsToRel);
} else {
// System.out.println("*** not fixing at " + counts);
}
counts = 0;
} else {
// System.out.println("skipping at " + counts);
}

// SmartDashboard.putNumber("Mast/Left_Enc", leftEncAngle);
Expand Down

0 comments on commit 0c47c9d

Please sign in to comment.