Skip to content

Commit

Permalink
Merge branch 'main' into 29-pathfinding
Browse files Browse the repository at this point in the history
  • Loading branch information
HeeistHo committed Mar 9, 2024
2 parents a03c874 + 5ad1eb6 commit 4225c02
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
36 changes: 22 additions & 14 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,22 +351,30 @@ protected void configureSystemTests() {
}

public static Command hapticDriverCommand() {
return new StartEndCommand(() -> {
driver.setRumble(GenericHID.RumbleType.kRightRumble, 1d);
driver.setRumble(GenericHID.RumbleType.kLeftRumble, 1d);
}, () -> {
driver.setRumble(GenericHID.RumbleType.kRightRumble, 0);
driver.setRumble(GenericHID.RumbleType.kLeftRumble, 0);
});
if (DriverStation.isAutonomous()) {
return new StartEndCommand(() -> {
driver.setRumble(GenericHID.RumbleType.kRightRumble, 1d);
driver.setRumble(GenericHID.RumbleType.kLeftRumble, 1d);
}, () -> {
driver.setRumble(GenericHID.RumbleType.kRightRumble, 0);
driver.setRumble(GenericHID.RumbleType.kLeftRumble, 0);
});
} else {
return new InstantCommand();
}
}

public static Command hapticCopilotCommand() {
return new StartEndCommand(() -> {
coPilot.setRumble(GenericHID.RumbleType.kRightRumble, 1d);
coPilot.setRumble(GenericHID.RumbleType.kLeftRumble, 1d);
}, () -> {
coPilot.setRumble(GenericHID.RumbleType.kRightRumble, 0);
coPilot.setRumble(GenericHID.RumbleType.kLeftRumble, 0);
});
if (DriverStation.isAutonomous()) {
return new StartEndCommand(() -> {
coPilot.setRumble(GenericHID.RumbleType.kRightRumble, 1d);
coPilot.setRumble(GenericHID.RumbleType.kLeftRumble, 1d);
}, () -> {
coPilot.setRumble(GenericHID.RumbleType.kRightRumble, 0);
coPilot.setRumble(GenericHID.RumbleType.kLeftRumble, 0);
});
} else {
return new InstantCommand();
}
}
}
22 changes: 8 additions & 14 deletions src/main/java/frc/robot/subsystems/Indexer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package frc.robot.subsystems;

import edu.wpi.first.math.filter.Debouncer;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
Expand All @@ -18,15 +19,16 @@ public class Indexer extends SubsystemBase {
private DigitalInput indexerSensorEntry = new DigitalInput(DIO.INDEXER_ENTER_BEAMBREAK);
private DigitalInput indexerSensorExit = new DigitalInput(DIO.INDEXER_EXIT_BEAMBREAK);

private int exitIndexerIteration = 0;

private double timeLastTriggered = 0d;

private double targetPower = 0;

private PieceState currentState = PieceState.NONE;
private boolean didShoot = false;

private Debouncer entryDebouncer = new Debouncer(0.05);
private Debouncer exitDebouncer = new Debouncer(0.05);

public Indexer(Collector collector) {
this.collector = collector;

Expand Down Expand Up @@ -108,7 +110,7 @@ public void stop() {
* @return entry beambreak state
*/
public boolean getEntryBeamBreakState() {
return !indexerSensorEntry.get();
return entryDebouncer.calculate(!indexerSensorEntry.get());
}

/**
Expand All @@ -117,14 +119,14 @@ public boolean getEntryBeamBreakState() {
* @return exit beambreak state
*/
public boolean getExitBeamBreakState() {
return !indexerSensorExit.get();
return exitDebouncer.calculate(!indexerSensorExit.get());
}

/**
* @return true if piece is exiting the indexer
*/
public boolean isExiting() {
return exitIndexerIteration >= 1;
return getExitBeamBreakState() && getPieceState() == PieceState.IN_INDEXER;
}

/**
Expand All @@ -150,10 +152,7 @@ public void clearHasShot() {
public void periodic() {
// Update piece state based on beambreaks
if (getExitBeamBreakState()) {
exitIndexerIteration++;
if (exitIndexerIteration >= 3) {
setPieceState(PieceState.IN_INDEXER);
}
setPieceState(PieceState.IN_INDEXER);
} else if (getEntryBeamBreakState()) {
setPieceState(PieceState.IN_PIVOT);
} else if (collector.getEntryBeamBreakState()) {
Expand All @@ -165,11 +164,6 @@ public void periodic() {
didShoot = didShoot || hasNote();
setPieceState(PieceState.NONE);
}

// reset exitIndexerIteration
if (!getEntryBeamBreakState()) {
exitIndexerIteration = 0;
}
}

public boolean hasNote() {
Expand Down

0 comments on commit 4225c02

Please sign in to comment.