Class BaseMaintainerCommand<TargetT,PowerT>

java.lang.Object
org.wpilib.command2.Command
xbot.common.command.BaseCommand
xbot.common.command.BaseMaintainerCommand<TargetT,PowerT>
Type Parameters:
TargetT - The type of the setpoint being maintained.
PowerT - The type of the power being applied to the subsystem. 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:
AutoCloseable, org.wpilib.telemetry.TelemetryLoggable, org.wpilib.tunable.ComplexTunable, TunablePrefixProvider
Direct Known Subclasses:
BaseSimpleMaintainerCommand

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

    • errorToleranceTunable

      protected final org.wpilib.tunable.TunableDouble errorToleranceTunable
    • errorTimeStableWindowTunable

      protected final org.wpilib.tunable.TunableDouble errorTimeStableWindowTunable
    • timeStableValidator

      protected final TimeStableValidator timeStableValidator
    • decider

      protected final HumanVsMachineDecider decider
  • Constructor Details

    • BaseMaintainerCommand

      public BaseMaintainerCommand(BaseSetpointSubsystem<TargetT,PowerT> subsystemToMaintain, TunableFactory tunableFactory, HumanVsMachineDecider.HumanVsMachineDeciderFactory humanVsMachineDeciderFactory, double defaultErrorTolerance, double defaultTimeStableWindow)
      Creates a new maintainer command.
      Parameters:
      subsystemToMaintain - The subsystem to maintain.
      tunableFactory - The tunable factory to use for creating configuration values.
      humanVsMachineDeciderFactory - The decider factory to use for creating the decider.
      defaultErrorTolerance - The default error tolerance.
      defaultTimeStableWindow - The default time stable window.
    • BaseMaintainerCommand

      public BaseMaintainerCommand(BaseSetpointSubsystem<TargetT,PowerT> subsystemToMaintain, TunableFactory tunableFactory, HumanVsMachineDecider.HumanVsMachineDeciderFactory humanVsMachineDeciderFactory, double defaultErrorTolerance, double defaultTimeStableWindow, String tunablePrefix)
      Creates a maintainer with an optional prefix before its command tunable path.
      Parameters:
      subsystemToMaintain - The subsystem to maintain.
      tunableFactory - The factory for configuration values.
      humanVsMachineDeciderFactory - The factory for the decider.
      defaultErrorTolerance - The default error tolerance.
      defaultTimeStableWindow - The default time stable window.
      tunablePrefix - Additional prefix, or an empty string for the default command path.
  • Method Details

    • runsWhenDisabled

      public boolean runsWhenDisabled()
      Overrides:
      runsWhenDisabled in class BaseCommand
    • 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.
    • initialize

      public void initialize()
      Overrides:
      initialize in class BaseCommand
    • execute

      public void execute()
      Overrides:
      execute in class org.wpilib.command2.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 PowerT 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 PowerT 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.