Class AbstractSubsystem<TConfig extends AbstractSubsystemConfig>

java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
frc.robot.shared.subsystems.AbstractSubsystem<TConfig>
All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable, edu.wpi.first.wpilibj2.command.Subsystem
Direct Known Subclasses:
AbstractMotorSubsystem, AprilTagVisionSubsystem, DriveBaseSubsystem, GameplayStateSubsystem, RobotPoseSubsystem

public abstract class AbstractSubsystem<TConfig extends AbstractSubsystemConfig> extends edu.wpi.first.wpilibj2.command.SubsystemBase
Base class for all robot subsystems that centralizes configuration flags, logging, and simulation awareness.

Extend this class to gain a shared logger, access to the loaded configuration, and convenience helpers for checking whether the subsystem should run on real hardware. The enabled flag should gate any device actions in concrete subclasses.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    Cached class name used for logging prefixes.
    protected TConfig
    Subsystem configuration bundle loaded from JSON.
    protected boolean
    True when the subsystem is allowed to run hardware actions.
    protected static double
    Nominal loop period in seconds for controller updates.
    protected Logger
    Logger instance scoped to the subsystem.
    protected boolean
    True when verbose logging is enabled for this subsystem.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a subsystem base with shared configuration and logging support.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the subsystem configuration bundle for command factories and external consumers that need access to subsystem-specific settings.
    protected boolean
    Reports whether the robot is attached to the FMS at call time.
    protected boolean
    Reports whether the code is running in WPILib simulation.
    boolean
    States whether this subsystem is marked as disabled in configuration.
    boolean
    Reports whether verbose telemetry and debug output are enabled for this subsystem.
    boolean
    Reports whether verbose AdvantageKit output should be recorded this cycle.
    protected void
    logDisabled(String methodName)
    Logs a standardized message when a call is skipped due to disable state.
    protected void
    reportWarning(String message, boolean printStackTrace)
    Reports a recoverable warning to the Driver Station console.

    Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase

    addChild, getName, getSubsystem, initSendable, setName, setSubsystem

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem

    defer, getCurrentCommand, getDefaultCommand, idle, periodic, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
  • Field Details

    • kDt

      protected static double kDt
      Nominal loop period in seconds for controller updates.
    • config

      protected TConfig extends AbstractSubsystemConfig config
      Subsystem configuration bundle loaded from JSON.
    • className

      protected String className
      Cached class name used for logging prefixes.
    • verbose

      protected boolean verbose
      True when verbose logging is enabled for this subsystem.
    • log

      protected Logger log
      Logger instance scoped to the subsystem.
    • enabled

      protected boolean enabled
      True when the subsystem is allowed to run hardware actions.
  • Constructor Details

    • AbstractSubsystem

      protected AbstractSubsystem(TConfig config)
      Creates a subsystem base with shared configuration and logging support.
      Parameters:
      config - Configuration object for the subsystem; supplies enable/verbose flags and any hardware identifiers.
  • Method Details

    • getConfig

      public TConfig getConfig()
      Returns the subsystem configuration bundle for command factories and external consumers that need access to subsystem-specific settings.
      Returns:
      subsystem configuration
    • isSubsystemDisabled

      public boolean isSubsystemDisabled()
      States whether this subsystem is marked as disabled in configuration.
      Returns:
      True when the subsystem should not execute any hardware interactions.
    • isVerbose

      public boolean isVerbose()
      Reports whether verbose telemetry and debug output are enabled for this subsystem.

      The value is read from the tunable config each call so it can be toggled at runtime from SmartDashboard without redeploying.

      Returns:
      True when verbose logging is enabled in the subsystem configuration.
    • isVerboseLoggingEnabled

      public boolean isVerboseLoggingEnabled()
      Reports whether verbose AdvantageKit output should be recorded this cycle.

      Combines two checks: the robot must not be attached to the FMS, and the subsystem's verbose config flag must be enabled. Use this to guard expensive pre-computation (array allocations, object construction) before calling log.recordVerboseOutput(...). The logger's own verbose gate handles the actual suppression, but calling this first avoids unnecessary work.

      Returns:
      true when verbose AdvantageKit output is active for this subsystem
    • isSimulation

      protected boolean isSimulation()
      Reports whether the code is running in WPILib simulation.
      Returns:
      True when running in simulation rather than on a real robot.
    • isFMSAttached

      protected boolean isFMSAttached()
      Reports whether the robot is attached to the FMS at call time.

      Uses the per-cycle cached value from RobotEnvironment.refreshCycle().

      Returns:
      True when running on a real robot that is currently FMS attached.
    • reportWarning

      protected void reportWarning(String message, boolean printStackTrace)
      Reports a recoverable warning to the Driver Station console.

      Use this for situations like a missing starting pose or a non-critical fallback.

      Parameters:
      message - warning description
      printStackTrace - true to include a stack trace in the output
    • logDisabled

      protected void logDisabled(String methodName)
      Logs a standardized message when a call is skipped due to disable state.

      Call this from public APIs to make skipped actions visible to operators.

      Parameters:
      methodName - name of the method that was skipped