Class GameplayStateSubsystem

java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
frc.robot.shared.subsystems.AbstractSubsystem<GameplayStateSubsystemConfig>
frc.robot.subsystems.gameplaystate.GameplayStateSubsystem
All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable, edu.wpi.first.wpilibj2.command.Subsystem

public class GameplayStateSubsystem extends AbstractSubsystem<GameplayStateSubsystemConfig>
Tracks the robot's high-level operating mode and publishes the current gameplay state for command factories and telemetry.

This subsystem does not own hardware or directly schedule commands on other subsystems. It maintains the current GameplayState and exposes it so the companion GameplayStateCommandFactory can compose the appropriate parallel command groups. Automatic transitions based on FMS match phase and endgame timer are evaluated each cycle when enabled in configuration.

  • Constructor Details

    • GameplayStateSubsystem

      public GameplayStateSubsystem(GameplayStateSubsystemConfig config, Supplier<Double> distanceToTargetMetersSupplier, Supplier<String> activeTargetNameSupplier)
      Creates the Gameplay State subsystem with targeting telemetry suppliers.
      Parameters:
      config - configuration values for auto-transition behavior and endgame thresholds
      distanceToTargetMetersSupplier - supplier returning the distance from the robot to the active field target in meters
      activeTargetNameSupplier - supplier returning the human-readable name of the active field target
  • Method Details

    • periodic

      public void periodic()
      Evaluates automatic state transitions and logs telemetry each robot loop.
    • requestState

      public void requestState(GameplayState state, String source)
      Requests a transition to the specified gameplay state.

      The state change takes effect immediately. The transition source is recorded for telemetry so operators can see what triggered each change.

      Parameters:
      state - desired gameplay state
      source - description of what triggered this transition (e.g., "operator", "fms", "auto", "timer")
    • getCurrentState

      public GameplayState getCurrentState()
      Returns the current gameplay state.
      Returns:
      active gameplay state
    • isEndgameSuggested

      public boolean isEndgameSuggested()
      Returns true when the endgame threshold has been reached.

      Use this as a dashboard indicator or driver alert.

      Returns:
      true when match time is below the configured endgame threshold during teleop