mirror of
https://github.com/Team4388/2026KPopRobotHunters.git
synced 2026-06-09 00:38:03 -06:00
Limit Switch
This commit is contained in:
@@ -13,6 +13,7 @@ import com.pathplanner.lib.commands.PathPlannerAuto;
|
|||||||
|
|
||||||
import edu.wpi.first.math.geometry.Rotation2d;
|
import edu.wpi.first.math.geometry.Rotation2d;
|
||||||
import edu.wpi.first.math.geometry.Translation2d;
|
import edu.wpi.first.math.geometry.Translation2d;
|
||||||
|
import edu.wpi.first.wpilibj.DigitalInput;
|
||||||
import edu.wpi.first.wpilibj.DriverStation;
|
import edu.wpi.first.wpilibj.DriverStation;
|
||||||
import edu.wpi.first.wpilibj.GenericHID;
|
import edu.wpi.first.wpilibj.GenericHID;
|
||||||
import edu.wpi.first.wpilibj.RobotBase;
|
import edu.wpi.first.wpilibj.RobotBase;
|
||||||
@@ -34,6 +35,7 @@ import frc4388.robot.subsystems.LED;
|
|||||||
import frc4388.robot.subsystems.intake.Intake;
|
import frc4388.robot.subsystems.intake.Intake;
|
||||||
import frc4388.robot.subsystems.intake.Intake.IntakeMode;
|
import frc4388.robot.subsystems.intake.Intake.IntakeMode;
|
||||||
import frc4388.robot.subsystems.shooter.Shooter;
|
import frc4388.robot.subsystems.shooter.Shooter;
|
||||||
|
import frc4388.robot.subsystems.shooter.Shooter.ShooterMode;
|
||||||
import frc4388.robot.subsystems.swerve.SwerveDrive;
|
import frc4388.robot.subsystems.swerve.SwerveDrive;
|
||||||
import frc4388.robot.subsystems.vision.Vision;
|
import frc4388.robot.subsystems.vision.Vision;
|
||||||
import frc4388.utility.DeferredBlock;
|
import frc4388.utility.DeferredBlock;
|
||||||
@@ -56,18 +58,23 @@ public class RobotContainer {
|
|||||||
|
|
||||||
public final RobotMap m_robotMap = new RobotMap(Mode.REAL);
|
public final RobotMap m_robotMap = new RobotMap(Mode.REAL);
|
||||||
|
|
||||||
|
/*Limit Switch */
|
||||||
|
public final DigitalInput m_armLimitSwitch = new DigitalInput(9);
|
||||||
|
|
||||||
/* Subsystems */
|
/* Subsystems */
|
||||||
public final LED m_robotLED = new LED(Constants.LEDConstants.LED_SPARK_ID);
|
public final LED m_robotLED = new LED(Constants.LEDConstants.LED_SPARK_ID);
|
||||||
//Testing of Colors
|
//Testing of Colors
|
||||||
public final Vision m_vision = new Vision();
|
public final Vision m_vision = new Vision();
|
||||||
public final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.swerveDrivetrain, m_vision);
|
public final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.swerveDrivetrain, m_vision);
|
||||||
public final Intake m_robotIntake = new Intake(m_robotMap.intakeIO);
|
public final Intake m_robotIntake = new Intake(m_robotMap.intakeIO, m_armLimitSwitch);
|
||||||
public final Shooter m_robotShooter = new Shooter(m_robotMap.shooterIO, m_robotSwerveDrive, m_robotIntake, m_robotLED);
|
public final Shooter m_robotShooter = new Shooter(m_robotMap.shooterIO, m_robotSwerveDrive, m_robotIntake, m_robotLED);
|
||||||
|
|
||||||
|
|
||||||
/* Controllers */
|
/* Controllers */
|
||||||
private final DeadbandedXboxController m_driverXbox = new DeadbandedXboxController(OIConstants.XBOX_DRIVER_ID);
|
private final DeadbandedXboxController m_driverXbox = new DeadbandedXboxController(OIConstants.XBOX_DRIVER_ID);
|
||||||
private final DeadbandedXboxController m_operatorXbox = new DeadbandedXboxController(OIConstants.XBOX_OPERATOR_ID);
|
private final DeadbandedXboxController m_operatorXbox = new DeadbandedXboxController(OIConstants.XBOX_OPERATOR_ID);
|
||||||
|
|
||||||
|
|
||||||
// private final ButtonBox m_buttonBox = new ButtonBox(OIConstants.BUTTONBOX_ID);
|
// private final ButtonBox m_buttonBox = new ButtonBox(OIConstants.BUTTONBOX_ID);
|
||||||
|
|
||||||
// public List<Subsystem> subsystems = new ArrayList<>();
|
// public List<Subsystem> subsystems = new ArrayList<>();
|
||||||
@@ -146,8 +153,8 @@ public class RobotContainer {
|
|||||||
private void configureButtonBindings() {
|
private void configureButtonBindings() {
|
||||||
|
|
||||||
|
|
||||||
// new JoystickButton(getDeadbandedDriverController(), XboxController.A_BUTTON)
|
new JoystickButton(getDeadbandedDriverController(), XboxController.A_BUTTON)
|
||||||
// .onTrue(new InstantCommand(() -> m_robotSwerveDrive.resetGyro()));
|
.onTrue(new InstantCommand(() -> m_robotSwerveDrive.resetGyro()));
|
||||||
|
|
||||||
|
|
||||||
// new JoystickButton(getDeadbandedDriverController(), XboxController.X_BUTTON)
|
// new JoystickButton(getDeadbandedDriverController(), XboxController.X_BUTTON)
|
||||||
@@ -209,25 +216,25 @@ public class RobotContainer {
|
|||||||
.onFalse(new InstantCommand(() -> {
|
.onFalse(new InstantCommand(() -> {
|
||||||
m_robotIntake.setMode(IntakeMode.Retracted);
|
m_robotIntake.setMode(IntakeMode.Retracted);
|
||||||
m_robotSwerveDrive.softStop();
|
m_robotSwerveDrive.softStop();
|
||||||
}, m_robotSwerveDrive));
|
}));
|
||||||
|
|
||||||
// IF the driver is holding the aim button, aim the robot towards the hub and shooter ready
|
// IF the driver is holding the aim button, aim the robot towards the hub and shooter ready
|
||||||
new Trigger(() -> getDeadbandedDriverController().getRightTriggerAxis() >= 0.5)
|
new Trigger(() -> getDeadbandedDriverController().getRightTriggerAxis() >= 0.5)
|
||||||
.whileTrue(new RunCommand(
|
.whileTrue(new RunCommand(
|
||||||
() -> {
|
() -> {
|
||||||
m_robotSwerveDrive.driveFacingPosition(
|
// m_robotSwerveDrive.driveFacingPosition(
|
||||||
getDeadbandedDriverController().getLeft(),
|
// getDeadbandedDriverController().getLeft(),
|
||||||
FieldPositions.HUB_POSITION);
|
// FieldPositions.HUB_POSITION);
|
||||||
}, m_robotSwerveDrive)
|
}, m_robotSwerveDrive)
|
||||||
)
|
)
|
||||||
.onTrue(new InstantCommand(() -> {
|
.onTrue(new InstantCommand(() -> {
|
||||||
// When Right trigger is pressed,
|
// When Right trigger is pressed,
|
||||||
m_robotIntake.setMode(IntakeMode.Extended);
|
m_robotShooter.setShooterReady();
|
||||||
}))
|
}))
|
||||||
.onFalse(new InstantCommand(() -> {
|
.onFalse(new InstantCommand(() -> {
|
||||||
m_robotIntake.setMode(IntakeMode.Retracted);
|
m_robotIntake.setMode(IntakeMode.Retracted);
|
||||||
m_robotSwerveDrive.softStop();
|
m_robotShooter.setShooterNotReady();
|
||||||
}, m_robotSwerveDrive));
|
}));
|
||||||
|
|
||||||
|
|
||||||
// D-PAD fine alignment
|
// D-PAD fine alignment
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ package frc4388.robot.constants;
|
|||||||
*/
|
*/
|
||||||
public final class BuildConstants {
|
public final class BuildConstants {
|
||||||
public static final String MAVEN_GROUP = "";
|
public static final String MAVEN_GROUP = "";
|
||||||
public static final String MAVEN_NAME = "2026KPopRobotHunters-new";
|
public static final String MAVEN_NAME = "2026KPopRobotHunters";
|
||||||
public static final String VERSION = "unspecified";
|
public static final String VERSION = "unspecified";
|
||||||
public static final int GIT_REVISION = 40;
|
public static final int GIT_REVISION = 49;
|
||||||
public static final String GIT_SHA = "983b95fdc704ef35b6f5e2dada2c6348f3c67190";
|
public static final String GIT_SHA = "0425cdd0a1e794109348c7369dc21b377fca569b";
|
||||||
public static final String GIT_DATE = "2026-02-10 19:42:47 MST";
|
public static final String GIT_DATE = "2026-02-12 14:36:26 MST";
|
||||||
public static final String GIT_BRANCH = "shoot-button";
|
public static final String GIT_BRANCH = "shoot-button";
|
||||||
public static final String BUILD_DATE = "2026-02-11 12:41:33 MST";
|
public static final String BUILD_DATE = "2026-02-14 11:48:31 MST";
|
||||||
public static final long BUILD_UNIX_TIME = 1770838893524L;
|
public static final long BUILD_UNIX_TIME = 1771094911048L;
|
||||||
public static final int DIRTY = 0;
|
public static final int DIRTY = 1;
|
||||||
|
|
||||||
private BuildConstants(){}
|
private BuildConstants(){}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,19 +7,24 @@ import java.util.function.Supplier;
|
|||||||
import org.littletonrobotics.junction.Logger;
|
import org.littletonrobotics.junction.Logger;
|
||||||
|
|
||||||
import edu.wpi.first.math.geometry.Pose2d;
|
import edu.wpi.first.math.geometry.Pose2d;
|
||||||
|
import edu.wpi.first.wpilibj.DigitalInput;
|
||||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||||
|
import frc4388.robot.subsystems.intake.Intake.IntakeMode;
|
||||||
|
|
||||||
public class Intake extends SubsystemBase {
|
public class Intake extends SubsystemBase {
|
||||||
public IntakeIO io;
|
public IntakeIO io;
|
||||||
IntakeStateAutoLogged state = new IntakeStateAutoLogged();
|
IntakeStateAutoLogged state = new IntakeStateAutoLogged();
|
||||||
|
|
||||||
Supplier<Pose2d> m_swervePoseSupplier;
|
Supplier<Pose2d> m_swervePoseSupplier;
|
||||||
|
public DigitalInput m_armLimitSwitch;
|
||||||
|
|
||||||
public Intake(
|
public Intake(
|
||||||
IntakeIO io
|
IntakeIO io,
|
||||||
|
DigitalInput m_armLimitSwitch
|
||||||
// Supplier<Pose2d> swervePoseSupplier
|
// Supplier<Pose2d> swervePoseSupplier
|
||||||
) {
|
) {
|
||||||
this.io = io;
|
this.io = io;
|
||||||
|
this.m_armLimitSwitch= m_armLimitSwitch;
|
||||||
// this.m_swervePoseSupplier = swervePoseSupplier;
|
// this.m_swervePoseSupplier = swervePoseSupplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +61,7 @@ public class Intake extends SubsystemBase {
|
|||||||
@Override
|
@Override
|
||||||
public void periodic() {
|
public void periodic() {
|
||||||
// FaultReporter.register(this); // TODO Implement fault reporter
|
// FaultReporter.register(this); // TODO Implement fault reporter
|
||||||
|
// System.out.println(m_armLimitSwitch.get());
|
||||||
|
|
||||||
|
|
||||||
Logger.processInputs("Intake", state);
|
Logger.processInputs("Intake", state);
|
||||||
@@ -68,7 +74,12 @@ public class Intake extends SubsystemBase {
|
|||||||
io.setRollerVelocity(state, RotationsPerSecond.of(IntakeConstants.ROLLER_ACTIVE.get()));
|
io.setRollerVelocity(state, RotationsPerSecond.of(IntakeConstants.ROLLER_ACTIVE.get()));
|
||||||
break;
|
break;
|
||||||
case Retracted:
|
case Retracted:
|
||||||
io.setArmAngle(state, Rotations.of(IntakeConstants.ARM_LIMIT_RETRACTED.get()));
|
if (!m_armLimitSwitch.get()){
|
||||||
|
System.out.println("Triggered!");
|
||||||
|
io.stopArm();
|
||||||
|
} else {
|
||||||
|
io.setArmAngle(state, Rotations.of(IntakeConstants.ARM_LIMIT_RETRACTED.get()));
|
||||||
|
}
|
||||||
io.setRollerVelocity(state, RotationsPerSecond.of(0));
|
io.setRollerVelocity(state, RotationsPerSecond.of(0));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import frc4388.utility.status.CanDevice;
|
|||||||
public class IntakeConstants {
|
public class IntakeConstants {
|
||||||
// Motor conversions
|
// Motor conversions
|
||||||
|
|
||||||
public static final double ARM_MOTOR_GEAR_RATIO = 100;
|
public static final double ARM_MOTOR_GEAR_RATIO = 125;
|
||||||
public static final double ROLLER_MOTOR_GEAR_RATIO = 3;
|
public static final double ROLLER_MOTOR_GEAR_RATIO = 3;
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ public class IntakeConstants {
|
|||||||
public static final TalonFXConfiguration ARM_MOTOR_CONFIG = new TalonFXConfiguration()
|
public static final TalonFXConfiguration ARM_MOTOR_CONFIG = new TalonFXConfiguration()
|
||||||
.withCurrentLimits(
|
.withCurrentLimits(
|
||||||
new CurrentLimitsConfigs()
|
new CurrentLimitsConfigs()
|
||||||
.withStatorCurrentLimit(40) // TODO: tune???
|
.withStatorCurrentLimit(15) // TODO: tune???
|
||||||
.withStatorCurrentLimitEnable(true)
|
.withStatorCurrentLimitEnable(true)
|
||||||
).withMotorOutput(
|
).withMotorOutput(
|
||||||
new MotorOutputConfigs()
|
new MotorOutputConfigs()
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public interface IntakeIO {
|
|||||||
// public default void setShooterAngle(ShooterState state, Angle angle) {}
|
// public default void setShooterAngle(ShooterState state, Angle angle) {}
|
||||||
// public default void setShooterPitch(ShooterState state, Angle angle) {}
|
// public default void setShooterPitch(ShooterState state, Angle angle) {}
|
||||||
public default void setArmAngle(IntakeState state, Angle angle) {}
|
public default void setArmAngle(IntakeState state, Angle angle) {}
|
||||||
|
public default void stopArm() {}
|
||||||
public default void setRollerVelocity(IntakeState state, AngularVelocity angularVelocity) {}
|
public default void setRollerVelocity(IntakeState state, AngularVelocity angularVelocity) {}
|
||||||
|
|
||||||
public default void updateInputs(IntakeState state) {}
|
public default void updateInputs(IntakeState state) {}
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ public class IntakeReal implements IntakeIO {
|
|||||||
// PositionDutyCycle posRequest = new PositionDutyCycle(motorTargetAngle);
|
// PositionDutyCycle posRequest = new PositionDutyCycle(motorTargetAngle);
|
||||||
m_armMotor.setControl(armPosition.withPosition(motorAngle));
|
m_armMotor.setControl(armPosition.withPosition(motorAngle));
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void stopArm(){
|
||||||
|
m_armMotor.set(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateInputs(IntakeState state) {
|
public void updateInputs(IntakeState state) {
|
||||||
|
|||||||
@@ -97,54 +97,54 @@ public class Shooter extends SubsystemBase {
|
|||||||
|
|
||||||
// TODO: get if the robot is within the angle of the hub
|
// TODO: get if the robot is within the angle of the hub
|
||||||
|
|
||||||
boolean driverError =
|
// boolean driverError =
|
||||||
XYSpeed <= ShooterConstants.ROBOT_SPEED_TOLERANCE.get() |
|
// XYSpeed <= ShooterConstants.ROBOT_SPEED_TOLERANCE.get() |
|
||||||
AngSpeed <= ShooterConstants.ROBOT_ANG_SPEED_TOLERANCE.get() |
|
// AngSpeed <= ShooterConstants.ROBOT_ANG_SPEED_TOLERANCE.get() |
|
||||||
distanceToHub <= ShooterConstants.ROBOT_MIN_HUB.get() |
|
// distanceToHub <= ShooterConstants.ROBOT_MIN_HUB.get() |
|
||||||
distanceToHub >= ShooterConstants.ROBOT_MAX_HUB.get();
|
// distanceToHub >= ShooterConstants.ROBOT_MAX_HUB.get();
|
||||||
|
|
||||||
double shooterSpeed = Math.abs(state.motor1Velocity.in(RotationsPerSecond) + state.motor2Velocity.in(RotationsPerSecond)) / 2;
|
// double shooterSpeed = Math.abs(state.motor1Velocity.in(RotationsPerSecond) + state.motor2Velocity.in(RotationsPerSecond)) / 2;
|
||||||
|
|
||||||
boolean badShooterVelocity = shooterSpeed < ShooterConstants.SHOOTER_SPEED_TOLERANCE.get();
|
// boolean badShooterVelocity = shooterSpeed < ShooterConstants.SHOOTER_SPEED_TOLERANCE.get();
|
||||||
boolean intakeBad = m_Intake.getMode() == IntakeMode.Extended;
|
// boolean intakeBad = m_Intake.getMode() == IntakeMode.Extended;
|
||||||
|
|
||||||
|
|
||||||
int bitmask = (driverError ? 1 : 0) + (badShooterVelocity ? 2 : 0) + (intakeBad ? 4 : 0);
|
// int bitmask = (driverError ? 1 : 0) + (badShooterVelocity ? 2 : 0) + (intakeBad ? 4 : 0);
|
||||||
switch (bitmask) {
|
// switch (bitmask) {
|
||||||
case 0b000: // No Errors
|
// case 0b000: // No Errors
|
||||||
m_robotLED.setMode(Constants.LEDConstants.OPREADY);
|
// m_robotLED.setMode(Constants.LEDConstants.OPREADY);
|
||||||
break;
|
// break;
|
||||||
case 0b001: // No op err, yes driver err
|
// case 0b001: // No op err, yes driver err
|
||||||
m_robotLED.setMode(Constants.LEDConstants.OPREADY_BADPHYS);
|
// m_robotLED.setMode(Constants.LEDConstants.OPREADY_BADPHYS);
|
||||||
break;
|
// break;
|
||||||
case 0b010: // Bad flywheel, no driver err
|
// case 0b010: // Bad flywheel, no driver err
|
||||||
m_robotLED.setMode(Constants.LEDConstants.BAD_FLYWEEL);
|
// m_robotLED.setMode(Constants.LEDConstants.BAD_FLYWEEL);
|
||||||
break;
|
// break;
|
||||||
case 0b011: // Bad flywheel, yes driver err
|
// case 0b011: // Bad flywheel, yes driver err
|
||||||
m_robotLED.setMode(Constants.LEDConstants.BAD_FLYWEEL_BADPHYS);
|
// m_robotLED.setMode(Constants.LEDConstants.BAD_FLYWEEL_BADPHYS);
|
||||||
break;
|
// break;
|
||||||
case 0b100: // Bad intake, no driver err
|
// case 0b100: // Bad intake, no driver err
|
||||||
m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT);
|
// m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT);
|
||||||
break;
|
// break;
|
||||||
case 0b101: // Bad intake, yes driver err
|
// case 0b101: // Bad intake, yes driver err
|
||||||
m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT_BADPHYS);
|
// m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT_BADPHYS);
|
||||||
break;
|
// break;
|
||||||
case 0b110: // Bad intake and shooter (intake is more important), no driver err
|
// case 0b110: // Bad intake and shooter (intake is more important), no driver err
|
||||||
m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT);
|
// m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT);
|
||||||
break;
|
// break;
|
||||||
case 0b111: // Bad intake and shooter (intake is more important), yes driver err
|
// case 0b111: // Bad intake and shooter (intake is more important), yes driver err
|
||||||
m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT_BADPHYS);
|
// m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT_BADPHYS);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// We set the shooter mode to ready if there are no errors
|
// // We set the shooter mode to ready if there are no errors
|
||||||
mode = (
|
// mode = (
|
||||||
bitmask == 0 ?
|
// bitmask == 0 ?
|
||||||
ShooterMode.Ready :
|
// ShooterMode.Ready :
|
||||||
ShooterMode.NotReady
|
// ShooterMode.NotReady
|
||||||
);
|
// );
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case Shooting:
|
case Shooting:
|
||||||
@@ -162,4 +162,4 @@ public class Shooter extends SubsystemBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public class ShooterConstants {
|
|||||||
// public static final AngularVelocity INDEXER_ACTIVE_VELOCITY = RotationsPerSecond.of(10);
|
// public static final AngularVelocity INDEXER_ACTIVE_VELOCITY = RotationsPerSecond.of(10);
|
||||||
// public static final AngularVelocity INDEXER_INACTIVE_VELOCITY = RotationsPerSecond.of(0.0);
|
// public static final AngularVelocity INDEXER_INACTIVE_VELOCITY = RotationsPerSecond.of(0.0);
|
||||||
|
|
||||||
public static final ConfigurableDouble SHOOTER_ACTIVE_VELOCITY = new ConfigurableDouble("Shooter Active Velocity", 30);
|
public static final ConfigurableDouble SHOOTER_ACTIVE_VELOCITY = new ConfigurableDouble("Shooter Active Velocity", 0);
|
||||||
public static final ConfigurableDouble SHOOTER_RESTING_VELOCITY = new ConfigurableDouble("Shooter Resting Velocity", 15);
|
public static final ConfigurableDouble SHOOTER_RESTING_VELOCITY = new ConfigurableDouble("Shooter Resting Velocity", 0);
|
||||||
|
|
||||||
public static final ConfigurableDouble INDEXER_FORWARD_VELOCITY = new ConfigurableDouble("Indexer FWD Velocity", 10);
|
public static final ConfigurableDouble INDEXER_FORWARD_VELOCITY = new ConfigurableDouble("Indexer FWD Velocity", 10);
|
||||||
public static final ConfigurableDouble INDEXER_REVERSE_VELOCITY = new ConfigurableDouble("Indexer reverse Velocity", 10);
|
public static final ConfigurableDouble INDEXER_REVERSE_VELOCITY = new ConfigurableDouble("Indexer reverse Velocity", 10);
|
||||||
|
|||||||
Reference in New Issue
Block a user