Class BaseMaintainerCommand<T>

Type Parameters:
T - The type of the setpoint being maintained. It runs a state machine to decide if the subsystem should be in human control, machine control, or coasting:
    flowchart TD
        C[Coast]
        HC[HumanControl]
        IMC[InitializeMachineControl]
        HPI{Is Human providing input?}
        R{Has Human Recently\nProvided Input?}
        MC[MachineControl]
        HPI-- Yes -->HC
        HPI-- No -->R
        R-- Yes -->C
        R-- No -->IMC
        IMC-->MC
 
All Implemented Interfaces:
Sendable, IPropertySupport
Direct Known Subclasses:
SwerveDriveMaintainerCommand, SwerveSteeringMaintainerCommand

public abstract class BaseMaintainerCommand<T> extends BaseCommand
A command that maintains a subsystem at a goal value (and allows human override).
  • Field Details

  • Constructor Details

    • BaseMaintainerCommand

      public BaseMaintainerCommand(BaseSetpointSubsystem<T> subsystemToMaintain, PropertyFactory pf, HumanVsMachineDecider.HumanVsMachineDeciderFactory humanVsMachineDeciderFactory, double defaultErrorTolerance, double defaultTimeStableWindow)
      Creates a new maintainer command.
      Parameters:
      subsystemToMaintain - The subsystem to maintain.
      pf - The property factory to use for creating properties.
      humanVsMachineDeciderFactory - The decider factory to use for creating the decider.
      defaultErrorTolerance - The default error tolerance.
      defaultTimeStableWindow - The default time stable window.
  • Method Details

    • resetDecider

      protected void resetDecider(boolean startInAutomaticMode)
      Resets the decider to the given mode.
      Parameters:
      startInAutomaticMode - True to start in automatic mode, false to start in human control mode.
    • execute

      public void execute()
      Overrides:
      execute in class Command
    • maintain

      protected void maintain()
      Contains all the logic associated with keeping the subsystem at its goal.
    • coastAction

      protected abstract void coastAction()
      The coast action. Typically, this does nothing.
    • humanControlAction

      protected void humanControlAction()
      The human control action. Typically, this simply assigns the human input to the subsystem.
    • initializeMachineControlAction

      protected void initializeMachineControlAction()
      The initialize machine control action. Typically, this sets the goal to the current position to avoid sudden changes.
    • calibratedMachineControlAction

      protected abstract void calibratedMachineControlAction()
      The calibrated machine control action.
    • uncalibratedMachineControlAction

      protected void uncalibratedMachineControlAction()
      The uncalibrated machine control action. Typically, this defaults to human control, although this is a good candidate for being overridden with an auto-calibration sequence.
    • isMaintainerAtGoal

      protected boolean isMaintainerAtGoal()
      Checks if the subsystem is at its goal.
      Returns:
      True if the subsystem is at its goal.
    • additionalAtGoalChecks

      protected boolean additionalAtGoalChecks()
      Maintainer systems already check for error tolerance and time stability. If there are any other checks that should be made, override this method and place them here.
      Returns:
      true by default, can be overridden by child classes.
    • getErrorWithinTolerance

      protected boolean getErrorWithinTolerance()
      Performs a simple difference between goal and target in order to see if we are close. if your subsystem needs to do something more complicated (for example, if you needed to compute difference via a ContiguousDouble) then override this method with a better computation.
    • getErrorMagnitude

      protected abstract double getErrorMagnitude()
    • getHumanInput

      protected abstract double getHumanInput()
      Gets the human input to use for the maintain command.
      Returns:
      The human input.
    • getHumanInputMagnitude

      protected abstract double getHumanInputMagnitude()
      Gets the magnitude of the human input to use for the maintain command, since the generic type T may not be a number.
      Returns:
      The magnitude of the human input.
    • setErrorTolerance

      protected void setErrorTolerance(double tolerance)
      Sets the error tolerance for the maintain command.
      Parameters:
      tolerance - The error tolerance.