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
A command that maintains a subsystem at a goal value (and allows human override).
-
Nested Class Summary
Nested classes/interfaces inherited from class org.wpilib.command2.Command
org.wpilib.command2.Command.InterruptionBehavior -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HumanVsMachineDeciderprotected final org.wpilib.tunable.TunableDoubleprotected final org.wpilib.tunable.TunableDoubleprotected final TimeStableValidatorFields inherited from class BaseCommand
aKitLog, log, monitor, runningAlert -
Constructor Summary
ConstructorsConstructorDescriptionBaseMaintainerCommand(BaseSetpointSubsystem<TargetT, PowerT> subsystemToMaintain, TunableFactory tunableFactory, HumanVsMachineDecider.HumanVsMachineDeciderFactory humanVsMachineDeciderFactory, double defaultErrorTolerance, double defaultTimeStableWindow) Creates a new maintainer command.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. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanMaintainer systems already check for error tolerance and time stability.protected abstract voidThe calibrated machine control action.protected abstract voidThe coast action.voidexecute()protected abstract doubleprotected booleanPerforms a simple difference between goal and target in order to see if we are close.protected abstract PowerTGets the human input to use for the maintain command.protected abstract doubleGets the magnitude of the human input to use for the maintain command, since the generic typePowerTmay not be a number.protected voidThe human control action.voidprotected voidThe initialize machine control action.protected booleanChecks if the subsystem is at its goal.protected voidmaintain()Contains all the logic associated with keeping the subsystem at its goal.protected voidresetDecider(boolean startInAutomaticMode) Resets the decider to the given mode.booleanprotected voidsetErrorTolerance(double tolerance) Sets the error tolerance for the maintain command.protected voidThe uncalibrated machine control action.Methods inherited from class BaseCommand
close, end, getPrefix, publishToTunables, publishToTunables, setRunsWhenDisabledMethods inherited from class org.wpilib.command2.Command
addRequirements, addRequirements, alongWith, andThen, andThen, asProxy, beforeStarting, beforeStarting, cancel, deadlineFor, finallyDo, finallyDo, getInterruptionBehavior, getName, getRequirements, getTelemetryType, getTunableType, handleInterrupt, hasRequirement, ignoringDisable, isFinished, isScheduled, logTo, onlyIf, onlyWhile, publishTunable, raceWith, repeatedly, setName, unless, until, withDeadline, withInterruptBehavior, withName, withTimeout, withTimeoutMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.wpilib.tunable.ComplexTunable
publishChildTunable, publishChildTunable, removeChildTunable, setChildTunableChanged, updateTunable
-
Field Details
-
errorToleranceTunable
protected final org.wpilib.tunable.TunableDouble errorToleranceTunable -
errorTimeStableWindowTunable
protected final org.wpilib.tunable.TunableDouble errorTimeStableWindowTunable -
timeStableValidator
-
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:
runsWhenDisabledin classBaseCommand
-
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:
initializein classBaseCommand
-
execute
public void execute()- Overrides:
executein classorg.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
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 typePowerTmay 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.
-