Class ShooterSubsystem

All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable, edu.wpi.first.wpilibj2.command.Subsystem

public class ShooterSubsystem extends AbstractVelocitySubsystem<ShooterSubsystemConfig>
Shooter subsystem that spins a flywheel to launch Fuel into the scoring hub.

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.

  • Constructor Details

    • ShooterSubsystem

      public ShooterSubsystem(ShooterSubsystemConfig config)
      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 CompositeMotor so the subsystem hierarchy sees a single Motor. 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:
      setTargetVelocityRpm in class AbstractVelocitySubsystem<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