2026-01-10 16:52:43 -07:00
|
|
|
package frc4388.robot.subsystems.shooter;
|
|
|
|
|
|
2026-02-09 17:18:54 -08:00
|
|
|
import static edu.wpi.first.units.Units.RotationsPerSecond;
|
|
|
|
|
|
2026-02-10 18:42:47 -08:00
|
|
|
import org.littletonrobotics.junction.AutoLogOutput;
|
2026-01-10 16:52:43 -07:00
|
|
|
import org.littletonrobotics.junction.Logger;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.math.geometry.Pose2d;
|
2026-02-11 15:18:12 -07:00
|
|
|
import edu.wpi.first.math.kinematics.ChassisSpeeds;
|
2026-01-10 16:52:43 -07:00
|
|
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
2026-02-11 15:18:12 -07:00
|
|
|
import frc4388.robot.constants.Constants;
|
2026-02-10 18:42:47 -08:00
|
|
|
import frc4388.robot.subsystems.LED;
|
|
|
|
|
import frc4388.robot.subsystems.intake.Intake;
|
|
|
|
|
import frc4388.robot.subsystems.intake.Intake.IntakeMode;
|
|
|
|
|
import frc4388.robot.subsystems.swerve.SwerveDrive;
|
2026-02-11 15:18:12 -07:00
|
|
|
import frc4388.utility.compute.FieldPositions;
|
2026-01-10 16:52:43 -07:00
|
|
|
|
|
|
|
|
public class Shooter extends SubsystemBase {
|
2026-02-09 17:18:54 -08:00
|
|
|
public ShooterIO io;
|
2026-01-10 16:52:43 -07:00
|
|
|
ShooterStateAutoLogged state = new ShooterStateAutoLogged();
|
|
|
|
|
|
2026-02-10 18:42:47 -08:00
|
|
|
SwerveDrive m_SwerveDrive;
|
|
|
|
|
Intake m_Intake;
|
|
|
|
|
LED m_robotLED;
|
|
|
|
|
|
|
|
|
|
|
2026-02-07 14:51:05 -07:00
|
|
|
// Supplier<Pose2d> m_swervePoseSupplier;
|
2026-01-10 16:52:43 -07:00
|
|
|
|
2026-01-29 18:07:19 -07:00
|
|
|
|
2026-01-10 16:52:43 -07:00
|
|
|
public Shooter(
|
2026-02-10 18:42:47 -08:00
|
|
|
ShooterIO io,
|
|
|
|
|
SwerveDrive swerveDrive,
|
|
|
|
|
Intake intake,
|
|
|
|
|
LED robotLED
|
2026-01-10 16:52:43 -07:00
|
|
|
) {
|
|
|
|
|
this.io = io;
|
2026-02-10 18:42:47 -08:00
|
|
|
this.m_SwerveDrive = swerveDrive;
|
|
|
|
|
this.m_Intake = intake;
|
|
|
|
|
this.m_robotLED = robotLED;
|
2026-02-07 14:51:05 -07:00
|
|
|
// this.m_swervePoseSupplier = swervePoseSupplier;
|
2026-01-10 16:52:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum FieldZone {
|
|
|
|
|
// The robot should aim at the hub
|
|
|
|
|
InShootZone,
|
|
|
|
|
// The robot should aim towards the wall
|
|
|
|
|
AimAtWall,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 18:07:19 -07:00
|
|
|
|
|
|
|
|
public enum ShooterMode {
|
2026-02-10 18:42:47 -08:00
|
|
|
// Shooter is actively shooting
|
|
|
|
|
Shooting,
|
|
|
|
|
// Shooter is going to fire soon
|
|
|
|
|
Ready,
|
|
|
|
|
// Not ready to shoot
|
|
|
|
|
NotReady,
|
2026-01-29 18:07:19 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-10 18:42:47 -08:00
|
|
|
private ShooterMode mode = ShooterMode.NotReady;
|
|
|
|
|
|
|
|
|
|
public void setShooterReady() {
|
2026-02-14 11:50:09 -08:00
|
|
|
// if(this.mode == ShooterMode.NotReady) {
|
2026-02-14 12:49:33 -08:00
|
|
|
this.mode = ShooterMode.Shooting;
|
2026-02-14 11:50:09 -08:00
|
|
|
// }
|
2026-02-10 18:42:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setShooterNotReady() {
|
|
|
|
|
this.mode = ShooterMode.NotReady;
|
2026-01-29 18:07:19 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-10 18:42:47 -08:00
|
|
|
@AutoLogOutput
|
|
|
|
|
public ShooterMode getMode() {
|
|
|
|
|
return mode;
|
2026-01-10 16:52:43 -07:00
|
|
|
}
|
|
|
|
|
|
2026-01-29 18:07:19 -07:00
|
|
|
|
2026-02-10 18:42:47 -08:00
|
|
|
|
2026-01-10 16:52:43 -07:00
|
|
|
@Override
|
|
|
|
|
public void periodic() {
|
|
|
|
|
// FaultReporter.register(this); // TODO Implement fault reporter
|
|
|
|
|
|
|
|
|
|
Logger.processInputs("Shooter", state);
|
2026-02-10 18:42:47 -08:00
|
|
|
io.updateInputs(state);
|
2026-01-10 16:52:43 -07:00
|
|
|
|
2026-02-10 18:42:47 -08:00
|
|
|
if(this.mode != ShooterMode.NotReady) {
|
2026-01-10 16:52:43 -07:00
|
|
|
|
2026-02-11 15:18:12 -07:00
|
|
|
ChassisSpeeds speed = m_SwerveDrive.chassisSpeeds;
|
|
|
|
|
double XYSpeed = Math.sqrt(Math.pow(speed.vxMetersPerSecond,2) + Math.pow(speed.vyMetersPerSecond,2));
|
|
|
|
|
double AngSpeed = Math.abs(speed.omegaRadiansPerSecond * (180/Math.PI));
|
|
|
|
|
|
|
|
|
|
Pose2d robotPose2d = m_SwerveDrive.getPose2d();
|
|
|
|
|
|
|
|
|
|
double distanceToHub = robotPose2d.getTranslation().minus(FieldPositions.HUB_POSITION).getNorm();
|
|
|
|
|
|
2026-02-14 12:49:33 -08:00
|
|
|
// this.mode = ShooterMode.Shooting;
|
2026-02-14 11:50:09 -08:00
|
|
|
|
2026-02-11 15:18:12 -07:00
|
|
|
// TODO: get if the robot is within the angle of the hub
|
|
|
|
|
|
2026-02-14 10:55:51 -08:00
|
|
|
// boolean driverError =
|
|
|
|
|
// XYSpeed <= ShooterConstants.ROBOT_SPEED_TOLERANCE.get() |
|
|
|
|
|
// AngSpeed <= ShooterConstants.ROBOT_ANG_SPEED_TOLERANCE.get() |
|
|
|
|
|
// distanceToHub <= ShooterConstants.ROBOT_MIN_HUB.get() |
|
|
|
|
|
// distanceToHub >= ShooterConstants.ROBOT_MAX_HUB.get();
|
2026-02-11 15:18:12 -07:00
|
|
|
|
2026-02-14 10:55:51 -08:00
|
|
|
// double shooterSpeed = Math.abs(state.motor1Velocity.in(RotationsPerSecond) + state.motor2Velocity.in(RotationsPerSecond)) / 2;
|
2026-02-11 15:18:12 -07:00
|
|
|
|
2026-02-14 10:55:51 -08:00
|
|
|
// boolean badShooterVelocity = shooterSpeed < ShooterConstants.SHOOTER_SPEED_TOLERANCE.get();
|
|
|
|
|
// boolean intakeBad = m_Intake.getMode() == IntakeMode.Extended;
|
2026-02-10 18:42:47 -08:00
|
|
|
|
2026-02-11 15:18:12 -07:00
|
|
|
|
2026-02-14 10:55:51 -08:00
|
|
|
// int bitmask = (driverError ? 1 : 0) + (badShooterVelocity ? 2 : 0) + (intakeBad ? 4 : 0);
|
|
|
|
|
// switch (bitmask) {
|
|
|
|
|
// case 0b000: // No Errors
|
|
|
|
|
// m_robotLED.setMode(Constants.LEDConstants.OPREADY);
|
|
|
|
|
// break;
|
|
|
|
|
// case 0b001: // No op err, yes driver err
|
|
|
|
|
// m_robotLED.setMode(Constants.LEDConstants.OPREADY_BADPHYS);
|
|
|
|
|
// break;
|
|
|
|
|
// case 0b010: // Bad flywheel, no driver err
|
|
|
|
|
// m_robotLED.setMode(Constants.LEDConstants.BAD_FLYWEEL);
|
|
|
|
|
// break;
|
|
|
|
|
// case 0b011: // Bad flywheel, yes driver err
|
|
|
|
|
// m_robotLED.setMode(Constants.LEDConstants.BAD_FLYWEEL_BADPHYS);
|
|
|
|
|
// break;
|
|
|
|
|
// case 0b100: // Bad intake, no driver err
|
|
|
|
|
// m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT);
|
|
|
|
|
// break;
|
|
|
|
|
// case 0b101: // Bad intake, yes driver err
|
|
|
|
|
// m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT_BADPHYS);
|
|
|
|
|
// break;
|
|
|
|
|
// case 0b110: // Bad intake and shooter (intake is more important), no driver err
|
|
|
|
|
// m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT);
|
|
|
|
|
// break;
|
|
|
|
|
// case 0b111: // Bad intake and shooter (intake is more important), yes driver err
|
|
|
|
|
// m_robotLED.setMode(Constants.LEDConstants.INTAKE_OUT_BADPHYS);
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // We set the shooter mode to ready if there are no errors
|
|
|
|
|
// mode = (
|
|
|
|
|
// bitmask == 0 ?
|
|
|
|
|
// ShooterMode.Ready :
|
|
|
|
|
// ShooterMode.NotReady
|
|
|
|
|
// );
|
|
|
|
|
|
2026-02-14 12:49:33 -08:00
|
|
|
}
|
|
|
|
|
|
2026-01-10 16:52:43 -07:00
|
|
|
|
2026-02-10 17:33:39 -08:00
|
|
|
switch (mode) {
|
2026-02-10 18:42:47 -08:00
|
|
|
case Shooting:
|
2026-02-10 17:33:39 -08:00
|
|
|
io.setShooterVelocity(state, RotationsPerSecond.of(ShooterConstants.SHOOTER_ACTIVE_VELOCITY.get()));
|
2026-02-10 18:42:47 -08:00
|
|
|
io.setIndexerVelocity(state, RotationsPerSecond.of(ShooterConstants.INDEXER_FORWARD_VELOCITY.get()));
|
2026-02-10 17:33:39 -08:00
|
|
|
break;
|
2026-02-10 18:42:47 -08:00
|
|
|
case Ready:
|
|
|
|
|
io.setShooterVelocity(state, RotationsPerSecond.of(ShooterConstants.SHOOTER_ACTIVE_VELOCITY.get()));
|
|
|
|
|
io.setIndexerVelocity(state, RotationsPerSecond.of(ShooterConstants.INDEXER_REVERSE_VELOCITY.get()));
|
2026-02-10 17:33:39 -08:00
|
|
|
break;
|
2026-02-10 18:42:47 -08:00
|
|
|
case NotReady:
|
|
|
|
|
io.setShooterVelocity(state, RotationsPerSecond.of(ShooterConstants.SHOOTER_RESTING_VELOCITY.get()));
|
|
|
|
|
io.setIndexerVelocity(state, RotationsPerSecond.of(ShooterConstants.INDEXER_REVERSE_VELOCITY.get()));
|
2026-02-10 17:33:39 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-10 16:52:43 -07:00
|
|
|
}
|
2026-02-14 12:49:33 -08:00
|
|
|
}
|