Package xbot.common.command
Class BaseMaintainerCommand<T>
java.lang.Object
edu.wpi.first.wpilibj2.command.Command
xbot.common.command.BaseCommand
xbot.common.command.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
A command that maintains a subsystem at a goal value (and allows human override).
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.wpi.first.wpilibj2.command.Command
Command.InterruptionBehavior
-
Field Summary
Modifier and TypeFieldDescriptionprotected final HumanVsMachineDecider
protected final DoubleProperty
protected final DoubleProperty
protected final TimeStableValidator
Fields inherited from class xbot.common.command.BaseCommand
aKitLog, log, monitor
-
Constructor Summary
ConstructorDescriptionBaseMaintainerCommand
(BaseSetpointSubsystem<T> subsystemToMaintain, PropertyFactory pf, HumanVsMachineDecider.HumanVsMachineDeciderFactory humanVsMachineDeciderFactory, double defaultErrorTolerance, double defaultTimeStableWindow) Creates a new maintainer command. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Maintainer systems already check for error tolerance and time stability.protected abstract void
The calibrated machine control action.protected abstract void
The coast action.void
execute()
protected abstract double
protected boolean
Performs a simple difference between goal and target in order to see if we are close.protected abstract double
Gets the human input to use for the maintain command.protected abstract double
Gets the magnitude of the human input to use for the maintain command, since the generic type T may not be a number.protected void
The human control action.protected void
The initialize machine control action.protected boolean
Checks if the subsystem is at its goal.protected void
maintain()
Contains all the logic associated with keeping the subsystem at its goal.protected void
resetDecider
(boolean startInAutomaticMode) Resets the decider to the given mode.protected void
setErrorTolerance
(double tolerance) Sets the error tolerance for the maintain command.protected void
The uncalibrated machine control action.Methods inherited from class xbot.common.command.BaseCommand
getPrefix, includeOnSmartDashboard, includeOnSmartDashboard, initialize, requires, runsWhenDisabled, setRunsWhenDisabled
Methods inherited from class edu.wpi.first.wpilibj2.command.Command
addRequirements, addRequirements, alongWith, andThen, andThen, asProxy, beforeStarting, beforeStarting, cancel, deadlineFor, deadlineWith, end, finallyDo, finallyDo, getInterruptionBehavior, getName, getRequirements, getSubsystem, handleInterrupt, hasRequirement, ignoringDisable, initSendable, isFinished, isScheduled, onlyIf, onlyWhile, raceWith, repeatedly, schedule, setName, setSubsystem, unless, until, withDeadline, withInterruptBehavior, withName, withTimeout, withTimeout
-
Field Details
-
errorToleranceProp
-
errorTimeStableWindowProp
-
timeStableValidator
-
decider
-
-
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() -
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.
-