Skip to content

Commit

Permalink
Feat: added beam breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
NateLydem committed Jun 12, 2024
1 parent 21d64a2 commit a09f5b9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/team1540/robot2024/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public static class Auto {
}

public static class Indexer {
public static final int BEAM_BREAK_ID = IS_COMPETITION_ROBOT ? 7 : 8;
public static final int BEAM_BREAK_BACK_ID = IS_COMPETITION_ROBOT ? 7 : 8;
public static final int BEAM_BREAK_FRONT_ID = 0; // TODO: update id
public static final int BEAM_BREAK_SHOOTER_ID = 0; // TODO: update id
public static final int INTAKE_ID = 13;
public static final int FEEDER_ID = 15;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,16 @@ public void setIntakePercent(double percent) {
io.setIntakeVoltage(percent * 12.0);
}

public boolean isNoteStaged() {
return inputs.noteInIntake;
public boolean isNoteStagedBack() {
return inputs.noteInIntakeBack;
}

public boolean isNoteStagedFront() {
return inputs.noteInIntakeFront;
}

public boolean isNoteStagedShooter() {
return inputs.noteInIntakeShooter;
}

public void setFeederVelocity(double setpointRPM) {
Expand Down Expand Up @@ -120,7 +128,7 @@ public Command moveNoteOut() {
() -> setIntakePercent(-1),
() -> {},
(interrupted) -> stopIntake(),
() -> !isNoteStaged(),
() -> !isNoteStagedBack(),
this
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class IndexerIOInputs {
public double feederCurrentAmps = 0.0;
public double feederVelocityRPM = 0.0;
public double feederTempCelsius = 0.0;
public boolean noteInIntake = false;
public boolean noteInIntakeFront = false;
public boolean noteInIntakeBack = false;
public boolean noteInIntakeShooter = false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class IndexerIOSim implements IndexerIO {
private final DCMotorSim intakeSim = new DCMotorSim(DCMotor.getNEO(1), INTAKE_GEAR_RATIO, INTAKE_MOI);
private final DCMotorSim feederSim = new DCMotorSim(DCMotor.getNEO(1), FEEDER_GEAR_RATIO, FEEDER_MOI);
// private final SimDeviceSim beamBreakSim = new SimDeviceSim("Indexer Beam Break");
private final DigitalInput indexerBeamBreak = new DigitalInput(BEAM_BREAK_ID);
private final DigitalInput indexerBeamBreakFront = new DigitalInput(BEAM_BREAK_FRONT_ID);
private final DigitalInput indexerBeamBreakBack = new DigitalInput(BEAM_BREAK_BACK_ID);
private final DigitalInput indexerBeamBreakShooter = new DigitalInput(BEAM_BREAK_SHOOTER_ID);
private final PIDController feederSimPID = new PIDController(FEEDER_KP, FEEDER_KI, FEEDER_KD);
private boolean isClosedLoop = true;
private double intakeVoltage = 0.0;
Expand All @@ -39,7 +41,9 @@ public void updateInputs(IndexerIOInputs inputs) {
inputs.feederCurrentAmps = feederSim.getCurrentDrawAmps();
inputs.feederVoltage = feederVoltage;
inputs.feederVelocityRPM = feederSim.getAngularVelocityRPM();
inputs.noteInIntake = indexerBeamBreak.get();
inputs.noteInIntakeFront = indexerBeamBreakFront.get();
inputs.noteInIntakeBack = indexerBeamBreakBack.get();
inputs.noteInIntakeShooter = indexerBeamBreakShooter.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
public class IndexerIOSparkMax implements IndexerIO {
private final CANSparkMax intakeMotor = new CANSparkMax(INTAKE_ID, CANSparkLowLevel.MotorType.kBrushless);
private final CANSparkMax feederMotor = new CANSparkMax(FEEDER_ID, CANSparkLowLevel.MotorType.kBrushless);
private final DigitalInput indexerBeamBreak = new DigitalInput(7);
private final DigitalInput indexerBeamBreakFront = new DigitalInput(0); // TODO: update id
private final DigitalInput indexerBeamBreakBack = new DigitalInput(7);
private final DigitalInput indexerBeamBreakShooter = new DigitalInput(0); // TODO: update id

private final RelativeEncoder intakeEncoder = intakeMotor.getEncoder();
private final RelativeEncoder feederEncoder = feederMotor.getEncoder();
Expand Down Expand Up @@ -43,7 +45,10 @@ public void updateInputs(IndexerIOInputs inputs) {
inputs.feederVoltage = feederMotor.getBusVoltage() * feederMotor.getAppliedOutput();
inputs.feederVelocityRPM = feederEncoder.getVelocity();
inputs.feederTempCelsius = feederMotor.getMotorTemperature();
inputs.noteInIntake = !indexerBeamBreak.get();
inputs.noteInIntakeFront = !indexerBeamBreakFront.get();
inputs.noteInIntakeBack = !indexerBeamBreakBack.get();
inputs.noteInIntakeShooter = !indexerBeamBreakShooter.get();

}

@Override
Expand Down

0 comments on commit a09f5b9

Please sign in to comment.