|
2 | 2 |
|
3 | 3 | import com.ctre.phoenix6.hardware.TalonFX;
|
4 | 4 |
|
| 5 | +import dev.doglog.DogLog; |
| 6 | +import edu.wpi.first.math.filter.Debouncer; |
5 | 7 | import edu.wpi.first.wpilibj.DigitalInput;
|
6 | 8 | import frc.robot.util.scheduling.SubsystemPriority;
|
7 | 9 | import frc.robot.util.state_machines.StateMachine;
|
8 | 10 |
|
| 11 | + |
9 | 12 | public class QueuerSubsystem extends StateMachine<QueuerState> {
|
10 | 13 | private final TalonFX motor;
|
11 | 14 | private final DigitalInput sensor;
|
| 15 | + private boolean sensorHasNote = false; |
| 16 | + private boolean debouncedSensorHasNote = false; |
| 17 | + private final Debouncer debouncer= new Debouncer(3 * 0.02); |
12 | 18 |
|
13 | 19 | public QueuerSubsystem(TalonFX motor, DigitalInput sensor) {
|
14 | 20 | super(SubsystemPriority.QUEUER, QueuerState.IDLE_NO_GP);
|
15 | 21 |
|
16 | 22 | this.sensor = sensor;
|
17 | 23 | this.motor = motor;
|
18 |
| - }} |
| 24 | + } |
| 25 | + public void seState(QueuerState newState){ |
| 26 | + setStateFromRequest(newState); |
| 27 | + } |
| 28 | + @Override |
| 29 | + protected void collectInputs(){ |
| 30 | + sensorHasNote=sensor.get(); |
| 31 | + debouncedSensorHasNote = debouncer.calculate(sensorHasNote); |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + protected QueuerState getNextState(QueuerState currentState){ |
| 36 | + // State transitions are done by robot manager, not here |
| 37 | + return currentState; |
| 38 | + } |
| 39 | + |
| 40 | + public boolean hasNote() { |
| 41 | + return debouncedSensorHasNote; |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + @Override |
| 46 | + protected void afterTransition(QueuerState newState){ |
| 47 | + switch(newState){ |
| 48 | + case IDLE_NO_GP->motor.disable(); |
| 49 | + case IDLE_WITH_GP->motor.disable(); |
| 50 | + case SHOOTING->motor.setVoltage(0);//probably like 12 |
| 51 | + case INTAKING->motor.setVoltage(0);//probably like 4 |
| 52 | + case OUTTAKING->motor.setVoltage(0);//proabably like -4 |
| 53 | + } |
| 54 | + } |
| 55 | + @Override |
| 56 | + public void robotPeriodic(){ |
| 57 | + DogLog.log("Queuer/StatorCurrent", motor.getStatorCurrent().getValueAsDouble()); |
| 58 | + DogLog.log("Queuer/SupplyCurrent", motor.getSupplyCurrent().getValueAsDouble()); |
| 59 | + DogLog.log("Queuer/AppliedVoltage", motor.getMotorVoltage().getValueAsDouble()); |
| 60 | + } |
| 61 | +} |
0 commit comments