Limit to beam break

Changed limit switch basin to beam break basin
This commit is contained in:
Michael Mikovsky
2025-02-17 11:48:43 -07:00
parent 7335c8e73b
commit b4b123237b
2 changed files with 31 additions and 11 deletions
+5 -4
View File
@@ -398,13 +398,14 @@ public final class Constants {
public static final CanDevice ENDEFFECTOR_ID = new CanDevice("Endeffector", 15);
public static final CanDevice ELEVATOR_ID = new CanDevice("Elevator", 16);
public static final int BASIN_LIMIT_SWITCH = 0; // TODO: FIND
public static final int ENDEFFECTOR_LIMIT_SWITCH = 1; // TODO: FIND
public static final int BASIN_LIMIT_SWITCH = 8; // TODO: FIND
public static final int ENDEFFECTOR_LIMIT_SWITCH = 9; // TODO: FIND
public static final double GEAR_RATIO_ELEVATOR = 9.0;
public static final double GEAR_RATIO_ELEVATOR = -9.0;
public static final double GROUND_POSITION_ELEVATOR = 0 * GEAR_RATIO_ELEVATOR;
public static final double WAITING_POSITION_ELEVATOR = 2 * GEAR_RATIO_ELEVATOR; // TODO: find 4-6 off the ground
public static final double WAITING_POSITION_ELEVATOR = 2 * GEAR_RATIO_ELEVATOR; // TODO: find 2-4 in off the pipe
public static final double WAITING_POSITION_BEAM_BREAK_ELEVATOR = 2 * GEAR_RATIO_ELEVATOR; // TODO: find on the pipe
public static final double MAX_POSITION_ELEVATOR = 4.5 * GEAR_RATIO_ELEVATOR; // TODO: find MAX position
public static final double GEAR_RATIO_ENDEFECTOR = 100.0;
@@ -9,7 +9,10 @@ import com.ctre.phoenix6.controls.PositionVoltage;
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc4388.robot.Constants.ElevatorConstants;
@@ -18,12 +21,13 @@ public class Elevator extends SubsystemBase {
private TalonFX elevatorMotor;
private TalonFX endefectorMotor;
private DigitalInput basinLimitSwitch;
private DigitalInput basinBeamBreak;
private DigitalInput endefectorLimitSwitch;
public enum CoordinationState {
Waiting, // for coral into the though
Ready, // Has coral in enefector
Waiting, // for coral into the though
WatingBeamTriped, //once the beam break trips
Ready, // Has coral in endefector
PrimedThree, // Arm and elevator Waiting to score in the level 3 position
ScoringThree, // Arm and elevator in the level three position
PrimedFour, // Arm and elevator Waiting to score in the level 4 position
@@ -40,7 +44,7 @@ public class Elevator extends SubsystemBase {
elevatorMotor = elevatorTalonFX;
endefectorMotor = endefectorTalonFX;
this.basinLimitSwitch = basinLimitSwitch;
this.basinBeamBreak = basinLimitSwitch;
this.endefectorLimitSwitch = endefectorLimitSwitch;
elevatorMotor.setNeutralMode(NeutralModeValue.Brake);
@@ -75,6 +79,12 @@ public class Elevator extends SubsystemBase {
break;
}
case WatingBeamTriped: {
PIDPosition(elevatorMotor, ElevatorConstants.WAITING_POSITION_BEAM_BREAK_ELEVATOR);
PIDPosition(endefectorMotor, ElevatorConstants.COMPLETLY_DOWN_ENDEFECTOR);
break;
}
case Ready: {
PIDPosition(elevatorMotor, ElevatorConstants.GROUND_POSITION_ELEVATOR);
PIDPosition(endefectorMotor, ElevatorConstants.COMPLETLY_DOWN_ENDEFECTOR);
@@ -97,7 +107,11 @@ public class Elevator extends SubsystemBase {
}
private void periodicWaiting() {
if (basinLimitSwitch.get()) transitionState(CoordinationState.Ready);
if (basinBeamBreak.get()) transitionState(CoordinationState.WatingBeamTriped);
}
private void periodicWaitingTripped() {
if (basinBeamBreak.get()) transitionState(CoordinationState.Ready);
}
private void periodicScoring() {
@@ -107,8 +121,13 @@ public class Elevator extends SubsystemBase {
@Override
public void periodic() {
// This method will be called once per scheduler run
// if (currentState == CoordinationState.Waiting) {
// periodicWaiting();
SmartDashboard.putNumber("Basin", basinBeamBreak.get() ? 1 : 0);
SmartDashboard.putNumber("endefector", basinBeamBreak.get() ? 1 : 0);
if (currentState == CoordinationState.Waiting) {
periodicWaiting();
} else if (currentState == CoordinationState.WatingBeamTriped) {
periodicWaitingTripped();
}
// } else if (currentState == CoordinationState.ScoringThree || currentState == CoordinationState.ScoringFour) {
// periodicScoring();
// }