Class ShooterSubsystem
- All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable,edu.wpi.first.wpilibj2.command.Subsystem
The competition robot uses two mechanically coupled motors: a primary and a follower. The follower can be independently inverted and
current-limited via its own config block. On robots with only one shooter motor (e.g., the test robot), set
followerEnabled = false and the subsystem operates with a single motor transparently.
All RPM values in the public API represent flywheel (mechanism) speed after gear reduction, not motor shaft speed. The gear ratio is applied at the motor encoder conversion layer, so callers never deal with motor-side rotations.
The subsystem uses a feedforward model to estimate the voltage needed for a target velocity and a PID controller to correct for disturbances (such as when a piece enters the shooter and momentarily slows the flywheel). An optional trapezoidal velocity ramp provides smooth spin-up when configured.
-
Nested Class Summary
Nested classes/interfaces inherited from class frc.robot.shared.subsystems.AbstractVelocitySubsystem
AbstractVelocitySubsystem.TriFunction<A,B, C, R> -
Field Summary
Fields inherited from class frc.robot.shared.subsystems.AbstractVelocitySubsystem
controllerFields inherited from class frc.robot.shared.subsystems.AbstractMotorSubsystem
feedforward, motor, motorInputs -
Constructor Summary
ConstructorsConstructorDescriptionBuilds the shooter subsystem with a primary motor and an optional follower motor. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculateRpmFromDistanceMeters(double distanceMeters) Computes the target flywheel RPM for a given distance using the configured interpolation table.doubleReturns the current operator RPM offset.doublegetTimeOfFlightSeconds(double distanceMeters) Returns the estimated time of flight for a ball to reach a target at the given distance.booleanReports whether the flywheel is spinning at a meaningful shooting velocity and is within tolerance of its current target.voidsetRpmOffset(double offsetRpm) Sets the operator RPM offset applied on top of every target velocity.voidsetTargetVelocityRpm(double targetRpm) Sets a new target velocity, applies the operator RPM offset, and clamps to forward-only rotation.Methods inherited from class frc.robot.shared.subsystems.AbstractVelocitySubsystem
buildVelocityMotor, getIdleVelocityRpm, getMeasuredVelocityRpm, getTargetVelocityRpm, isAtTargetVelocity, isReady, isWithinTolerance, periodic, seekVelocity, stopMethods inherited from class frc.robot.shared.subsystems.AbstractMotorSubsystem
applyVoltage, getMeasuredPositionRadians, getMeasuredVelocityRadiansPerSecond, getSysIdRoutine, logSysIdEnd, logSysIdInterrupted, logSysIdStart, refreshFeedforward, updateAndLogMotorInputsMethods inherited from class frc.robot.shared.subsystems.AbstractSubsystem
getConfig, isFMSAttached, isSimulation, isSubsystemDisabled, isVerbose, isVerboseLoggingEnabled, logDisabled, reportWarningMethods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Constructor Details
-
ShooterSubsystem
Builds the shooter subsystem with a primary motor and an optional follower motor.When the follower motor config is enabled, both motors are wrapped in a
CompositeMotorso the subsystem hierarchy sees a singleMotor. When the follower is disabled, only the primary motor is used.- Parameters:
config- shooter configuration bundle loaded from JSON; velocities are expressed in RPM
-
-
Method Details
-
setRpmOffset
public void setRpmOffset(double offsetRpm) Sets the operator RPM offset applied on top of every target velocity.Positive values boost flywheel speed; negative values cut it. Set to zero to clear the adjustment. The offset is added to the raw target inside
setTargetVelocityRpm(double)before the forward-only clamp, so it takes effect immediately on the next control cycle.- Parameters:
offsetRpm- RPM to add to the calculated target (positive = boost, negative = cut)
-
getRpmOffset
public double getRpmOffset()Returns the current operator RPM offset.- Returns:
- RPM offset currently applied (positive = boost, negative = cut, zero = none)
-
setTargetVelocityRpm
public void setTargetVelocityRpm(double targetRpm) Sets a new target velocity, applies the operator RPM offset, and clamps to forward-only rotation.The operator offset is added before clamping so boost and cut adjustments take effect for all shooting modes (distance-based, fixed RPM, continuous). Flywheels should never reverse through the velocity controller, so the result is clamped to zero at the low end.
- Overrides:
setTargetVelocityRpmin classAbstractVelocitySubsystem<ShooterSubsystemConfig>- Parameters:
targetRpm- desired flywheel velocity in RPM (0 to stop, positive to spin forward)
-
calculateRpmFromDistanceMeters
public double calculateRpmFromDistanceMeters(double distanceMeters) Computes the target flywheel RPM for a given distance using the configured interpolation table.The raw interpolated value is scaled by the tunable multiplier and then clamped to the configured maximum velocity. Returns the idle RPM when the interpolation table is empty.
- Parameters:
distanceMeters- distance from the robot to the target in meters- Returns:
- target flywheel RPM, scaled and clamped to the configured maximum
-
getTimeOfFlightSeconds
public double getTimeOfFlightSeconds(double distanceMeters) Returns the estimated time of flight for a ball to reach a target at the given distance.The value is interpolated from the configured distance-RPM-TOF lookup table. When no TOF data is configured, returns a conservative linear estimate based on distance. The shoot-on-the-move solver uses this to determine how far the ball drifts during flight.
- Parameters:
distanceMeters- distance from the launcher to the target in meters- Returns:
- estimated time of flight in seconds
-
isAtShootingVelocity
public boolean isAtShootingVelocity()Reports whether the flywheel is spinning at a meaningful shooting velocity and is within tolerance of its current target.Delegates to the base class
AbstractVelocitySubsystem.isWithinTolerance()for the velocity error check and additionally verifies that the current target is above idle speed. This prevents false positives when the shooter is still at idle speed.- Returns:
- true when the flywheel is within tolerance and the target is above idle velocity
-