Flywheel shooters require consistent surface velocity to achieve repeatable trajectory arcs into scoring targets. Because flywheels operate at continuous high RPM (typically 3,000 to 6,000 RPM), velocity feedforward () delivers the majority of the motor voltage, while corrects for aerodynamic drag and game-piece compression.
Subsystem Implementation
Section titled “Subsystem Implementation”package frc.robot.subsystems;
import com.ctre.phoenix6.configs.TalonFXConfiguration;import com.ctre.phoenix6.controls.VelocityVoltage;import com.ctre.phoenix6.controls.VoltageOut;import com.ctre.phoenix6.hardware.TalonFX;import com.ctre.phoenix6.signals.InvertedValue;import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.units.measure.AngularVelocity;import static edu.wpi.first.units.Units.*;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;import edu.wpi.first.wpilibj2.command.Command;import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class ShooterSubsystem extends SubsystemBase { // Dual flywheels: Top and Bottom rollers for spin control private final TalonFX m_topMotor = new TalonFX(15, "rio"); private final TalonFX m_bottomMotor = new TalonFX(16, "rio");
private final VelocityVoltage m_topVelocity = new VelocityVoltage(0).withSlot(0); private final VelocityVoltage m_bottomVelocity = new VelocityVoltage(0).withSlot(0); private final VoltageOut m_stop = new VoltageOut(0);
private AngularVelocity m_targetTopSpeed = RotationsPerSecond.of(0); private AngularVelocity m_targetBottomSpeed = RotationsPerSecond.of(0);
public ShooterSubsystem() { configureHardware(); setDefaultCommand(stopShooterCommand()); }
private void configureHardware() { TalonFXConfiguration cfg = new TalonFXConfiguration();
// Flywheels must coast to prevent gearbox stress on deceleration cfg.MotorOutput.NeutralMode = NeutralModeValue.Coast; cfg.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive;
// Current Limits cfg.CurrentLimits.StatorCurrentLimitEnable = true; cfg.CurrentLimits.StatorCurrentLimit = 60.0; // 60A peak acceleration cfg.CurrentLimits.SupplyCurrentLimitEnable = true; cfg.CurrentLimits.SupplyCurrentLimit = 40.0; // 40A supply limit
// Slot 0 Velocity Closed Loop Gains // Free speed of Kraken X60 is ~100 rot/s at 12V -> kV ≈ 12V / 100 rot/s = 0.12 V/(rot/s) cfg.Slot0.kS = 0.18; // 0.18V friction voltage cfg.Slot0.kV = 0.118; // Velocity feedforward cfg.Slot0.kP = 0.25; // Proportional recovery gain cfg.Slot0.kD = 0.005; // Light derivative damping
m_topMotor.getConfigurator().apply(cfg);
// Bottom motor spins opposite direction cfg.MotorOutput.Inverted = InvertedValue.Clockwise_Positive; m_bottomMotor.getConfigurator().apply(cfg); }
@Override public void periodic() { SmartDashboard.putNumber("Shooter/TopSpeed_rps", m_topMotor.getVelocity().getValueAsDouble()); SmartDashboard.putNumber("Shooter/BottomSpeed_rps", m_bottomMotor.getVelocity().getValueAsDouble()); SmartDashboard.putBoolean("Shooter/AtSpeed", isAtSpeed()); }
/** * Commands both flywheels to target rotational velocities. */ public Command spinShooterCommand(AngularVelocity topSpeed, AngularVelocity bottomSpeed) { return run(() -> { m_targetTopSpeed = topSpeed; m_targetBottomSpeed = bottomSpeed; m_topMotor.setControl(m_topVelocity.withVelocity(topSpeed.in(RotationsPerSecond))); m_bottomMotor.setControl(m_bottomVelocity.withVelocity(bottomSpeed.in(RotationsPerSecond))); }).withName("SpinShooter"); }
/** * Returns true when both flywheels are within 1.5 RPS of target speed. */ public boolean isAtSpeed() { if (m_targetTopSpeed.in(RotationsPerSecond) < 5.0) return false; double topError = Math.abs(m_topMotor.getVelocity().getValueAsDouble() - m_targetTopSpeed.in(RotationsPerSecond)); double bottomError = Math.abs(m_bottomMotor.getVelocity().getValueAsDouble() - m_targetBottomSpeed.in(RotationsPerSecond)); return topError < 1.5 && bottomError < 1.5; }
public Command stopShooterCommand() { return run(() -> { m_topMotor.setControl(m_stop); m_bottomMotor.setControl(m_stop); }).withName("StopShooter"); }}Always Use Coast Mode for High-Speed Flywheels
Setting a 6,000 RPM flywheel to Brake Mode forces the motor controller to absorb rotational kinetic energy instantly when you disable the robot, generating extreme current and violent gear tooth stress.