Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ot2024 into zach/fix
  • Loading branch information
WeilSimon committed Sep 23, 2024
2 parents 6374ae9 + 64eb89e commit e40e8de
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 109 deletions.
4 changes: 0 additions & 4 deletions src/main/java/org/team1540/robot2024/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
public class Robot extends LoggedRobot {
private Command autonomousCommand;
private RobotContainer robotContainer;
private DigitalInput intakeBeamBreak = new DigitalInput(Constants.DIO.INTAKE_BEAM_BREAK);
private DigitalInput shooterBeamBreak = new DigitalInput(Constants.DIO.SHOOTER_BEAM_BREAK);

/**
* This function is run when the robot is first started up and should be used for any
Expand Down Expand Up @@ -125,8 +123,6 @@ public void robotPeriodic() {
// the Command-based framework to work.
CommandScheduler.getInstance().run();
if (Constants.currentMode == Constants.Mode.REAL) robotContainer.odometrySignalRefresher.periodic();
Logger.recordOutput("beambreak/shooter", shooterBeamBreak.get());
Logger.recordOutput("beambreak/intake", intakeBeamBreak.get());
// Update mechanism visualiser in sim
if (Robot.isSimulation()) MechanismVisualiser.periodic();
// robotContainer.leds.setPattern(Leds.Zone.ZONE1, SimpleLedPattern.alternating(Color.kBlueViolet, Color.kGreen));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/team1540/robot2024/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private void configureButtonBindings() {
.alongWith(leds.commandShowPattern(
new LedPatternProgressBar(shooter::getSpinUpPercent, "#00ffbc", 33),
Leds.PatternLevel.DRIVER_LOCK));

Command ampLock = new DriveWithAmpSideLock(drivetrain, driver.getHID())
.alongWith(leds.commandShowPattern(new LedPatternWave("#ffffff"), Leds.PatternLevel.DRIVER_LOCK));
Command cancelAlignment = Commands.runOnce(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ public void initialize() {

@Override
public void execute() {
if (indexer.isNoteStaged()) {
if (indexer.getNoteState() == Indexer.NotePosition.INDEXER) {
indexer.stopIntake();
if (leds != null) {
leds.clearPatternAll(Leds.PatternLevel.INTAKE_PREREADY);
}
} else {
if (leds != null) {
if (indexer.getIntakeVoltage() == 0) {
timer.restart();
}
if (timer.hasElapsed(0.3) && indexer.getIntakeCurrent() > 30) {
if (indexer.getNoteState() == Indexer.NotePosition.INTAKE) {
leds.setPatternAll(detected, Leds.PatternLevel.INTAKE_PREREADY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import edu.wpi.first.wpilibj.RobotState;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.FunctionalCommand;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import org.littletonrobotics.junction.AutoLogOutput;
import org.littletonrobotics.junction.Logger;
import org.team1540.robot2024.Constants;
import org.team1540.robot2024.util.LoggedTunableNumber;

import java.util.function.BooleanSupplier;

import static org.team1540.robot2024.Constants.Indexer.*;

Expand All @@ -18,10 +18,6 @@ public class Indexer extends SubsystemBase {
private final IndexerIO io;
private final IndexerIOInputsAutoLogged inputs = new IndexerIOInputsAutoLogged();

private final LoggedTunableNumber kP = new LoggedTunableNumber("Indexer/kP", FEEDER_KP);
private final LoggedTunableNumber kI = new LoggedTunableNumber("Indexer/kI", FEEDER_KI);
private final LoggedTunableNumber kD = new LoggedTunableNumber("Indexer/kD", FEEDER_KD);

private double feederSetpointRPM = 0.0;

private static boolean hasInstance = false;
Expand Down Expand Up @@ -68,7 +64,23 @@ public void setIntakePercent(double percent) {
}

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

public BooleanSupplier checkNoteReached(NotePosition position) {
return () -> getNoteState().ordinal() >= position.ordinal();
}
public NotePosition getNoteState() {
if (inputs.noteInShooter) {
return NotePosition.SHOOTER;
}
if (inputs.noteInIndexer) {
return NotePosition.INDEXER;
}
if (inputs.noteInIntake) {
return NotePosition.INTAKE;
}
return NotePosition.NONE;
}

public void setFeederVelocity(double setpointRPM) {
Expand Down Expand Up @@ -114,16 +126,6 @@ public Command feedToAmp() {
public Command feedToShooter() {
return Commands.runOnce(() -> io.setFeederVelocity(1200), this);
}

public Command moveNoteOut() {
return new FunctionalCommand(
() -> setIntakePercent(-1),
() -> {},
(interrupted) -> stopIntake(),
() -> !isNoteStaged(),
this
);
}

public Command commandRunIntake(double percent) {
return Commands.startEnd(
Expand All @@ -133,6 +135,13 @@ public Command commandRunIntake(double percent) {
);
}

public Command moveNoteTo(NotePosition position) {
return Commands.startEnd(() -> {
this.setIntakePercent(1);
this.setFeederPercent(1);
}, this::stopAll).until(this.checkNoteReached(NotePosition.SHOOTER));
}

public void setIntakeBrakeMode(boolean isBrake) {
io.setIntakeBrakeMode(isBrake);
}
Expand All @@ -145,4 +154,10 @@ public double getIntakeCurrent() {
return inputs.intakeCurrentAmps;
}

public enum NotePosition {
NONE,
INTAKE,
INDEXER,
SHOOTER;
}
}
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 noteInIndexer = false;
public boolean noteInIntake = false;
public boolean noteInShooter = false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void updateInputs(IndexerIOInputs inputs) {
inputs.feederCurrentAmps = feederSim.getCurrentDrawAmps();
inputs.feederVoltage = feederVoltage;
inputs.feederVelocityRPM = feederSim.getAngularVelocityRPM();
inputs.noteInIntake = indexerBeamBreak.get();
inputs.noteInIndexer = indexerBeamBreak.get();
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class IndexerIOTalonFX implements IndexerIO {
private final TalonFX intakeMotor = new TalonFX(INTAKE_ID);
private final TalonFX feederMotor = new TalonFX(FEEDER_ID);
private final DigitalInput indexerBeamBreak = new DigitalInput(Constants.DIO.INDEXER_BEAM_BREAK);
private final DigitalInput intakeBeamBreak = new DigitalInput(Constants.DIO.INTAKE_BEAM_BREAK);
private final DigitalInput shooterBeamBreak = new DigitalInput(Constants.DIO.SHOOTER_BEAM_BREAK);

private final VoltageOut feederVoltageCtrlReq = new VoltageOut(0).withEnableFOC(true);
private final VelocityVoltage feederVelocityCtrlReq = new VelocityVoltage(0).withEnableFOC(true);
Expand Down Expand Up @@ -88,7 +90,9 @@ public void updateInputs(IndexerIOInputs inputs) {
inputs.feederCurrentAmps = feederCurrent.getValueAsDouble();
inputs.feederVelocityRPM = feederVelocity.getValueAsDouble() * 60;
inputs.feederTempCelsius = feederTemp.getValueAsDouble();
inputs.noteInIntake = !indexerBeamBreak.get();
inputs.noteInIndexer = !indexerBeamBreak.get();
inputs.noteInIntake = !intakeBeamBreak.get();
inputs.noteInShooter = !shooterBeamBreak.get();
}

@Override
Expand Down

0 comments on commit e40e8de

Please sign in to comment.