mirror of
https://github.com/Team4388/2026KPopRobotHunters.git
synced 2026-06-09 00:38:03 -06:00
limit switch through robot map
This commit is contained in:
@@ -16,15 +16,12 @@ public class Intake extends SubsystemBase {
|
||||
IntakeStateAutoLogged state = new IntakeStateAutoLogged();
|
||||
|
||||
Supplier<Pose2d> m_swervePoseSupplier;
|
||||
public DigitalInput m_armLimitSwitch;
|
||||
|
||||
public Intake(
|
||||
IntakeIO io,
|
||||
DigitalInput m_armLimitSwitch
|
||||
IntakeIO io
|
||||
// Supplier<Pose2d> swervePoseSupplier
|
||||
) {
|
||||
this.io = io;
|
||||
this.m_armLimitSwitch= m_armLimitSwitch;
|
||||
// this.m_swervePoseSupplier = swervePoseSupplier;
|
||||
}
|
||||
|
||||
@@ -76,8 +73,7 @@ public class Intake extends SubsystemBase {
|
||||
io.setRollerVelocity(state, RotationsPerSecond.of(IntakeConstants.ROLLER_ACTIVE.get()));
|
||||
break;
|
||||
case Retracted:
|
||||
if (!m_armLimitSwitch.get()){
|
||||
System.out.println("Triggered!");
|
||||
if (!state.retractedLimit){
|
||||
io.stopArm();
|
||||
} else {
|
||||
io.setArmAngle(state, Rotations.of(IntakeConstants.ARM_LIMIT_RETRACTED.get()));
|
||||
@@ -88,7 +84,11 @@ public class Intake extends SubsystemBase {
|
||||
io.armExtend(IntakeConstants.ARM_EXTEND_PERCENT_OUTPUT.get());
|
||||
break;
|
||||
case Retracting:
|
||||
io.armRetract(IntakeConstants.ARM_RETRACT_PERCENT_OUTPUT.get());
|
||||
if (!state.retractedLimit){
|
||||
io.stopArm();
|
||||
} else {
|
||||
io.armRetract(IntakeConstants.ARM_RETRACT_PERCENT_OUTPUT.get());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public class IntakeConstants {
|
||||
|
||||
public static final CanDevice ARM_ID = new CanDevice("ARM", 20);
|
||||
public static final CanDevice ROLLER_ID = new CanDevice("INTAKE_ROLLER", 21);
|
||||
public static final int ARM_LIMIT_SWITCH_CHANNEL = 9;
|
||||
|
||||
// Limits
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import edu.wpi.first.units.measure.Current;
|
||||
public interface IntakeIO {
|
||||
@AutoLog
|
||||
public class IntakeState {
|
||||
boolean retractedLimit = false;
|
||||
Angle armAngle = Rotations.of(0);
|
||||
Angle armTargetAngle = Rotations.of(0);
|
||||
Current armMotorCurrent = Amps.of(0);
|
||||
|
||||
@@ -5,18 +5,20 @@ import com.ctre.phoenix6.controls.VelocityDutyCycle;
|
||||
import com.ctre.phoenix6.hardware.TalonFX;
|
||||
|
||||
import edu.wpi.first.units.measure.*;
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
|
||||
public class IntakeReal implements IntakeIO {
|
||||
|
||||
|
||||
TalonFX m_armMotor;
|
||||
TalonFX m_rollerMotor;
|
||||
DigitalInput m_armLimitSwitch;
|
||||
|
||||
PositionDutyCycle armPosition = new PositionDutyCycle(0);
|
||||
VelocityDutyCycle rollerVelocity = new VelocityDutyCycle(0);
|
||||
|
||||
public IntakeReal(
|
||||
|
||||
DigitalInput armLimitSwitch,
|
||||
TalonFX armMotor,
|
||||
TalonFX rollerMotor
|
||||
) {
|
||||
@@ -24,6 +26,7 @@ public class IntakeReal implements IntakeIO {
|
||||
// m_pitchMotor = pitchMotor;
|
||||
m_armMotor = armMotor;
|
||||
m_rollerMotor = rollerMotor;
|
||||
m_armLimitSwitch = armLimitSwitch;
|
||||
|
||||
// Apply the configs
|
||||
m_armMotor.getConfigurator().apply(IntakeConstants.ARM_PID);
|
||||
@@ -96,7 +99,7 @@ public class IntakeReal implements IntakeIO {
|
||||
public void updateInputs(IntakeState state) {
|
||||
state.armAngle = m_armMotor.getPosition().getValue().div(IntakeConstants.ARM_MOTOR_GEAR_RATIO);
|
||||
state.armMotorCurrent = m_armMotor.getStatorCurrent().getValue();
|
||||
|
||||
state.retractedLimit = m_armLimitSwitch.get();
|
||||
state.rollerVelocity = m_rollerMotor.getVelocity().getValue().div(IntakeConstants.ROLLER_MOTOR_GEAR_RATIO);
|
||||
state.rollerMotorCurrent = m_rollerMotor.getStatorCurrent().getValue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user