Package xbot.common.command
Class BaseMaintainerCommand<TargetT,PowerT>
java.lang.Object
edu.wpi.first.wpilibj2.command.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:
Sendable,IPropertySupport
- 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 edu.wpi.first.wpilibj2.command.Command
Command.InterruptionBehavior -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HumanVsMachineDeciderprotected final DoublePropertyprotected final DoublePropertyprotected final TimeStableValidatorFields inherited from class xbot.common.command.BaseCommand
aKitLog, log, monitor, runningAlert -
Constructor Summary
ConstructorsConstructorDescriptionBaseMaintainerCommand(BaseSetpointSubsystem<TargetT, PowerT> subsystemToMaintain, PropertyFactory pf, HumanVsMachineDecider.HumanVsMachineDeciderFactory humanVsMachineDeciderFactory, double defaultErrorTolerance, double defaultTimeStableWindow) Creates a new maintainer command. -
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 xbot.common.command.BaseCommand
end, getPrefix, includeOnSmartDashboard, includeOnSmartDashboard, requires, setRunsWhenDisabledMethods inherited from class edu.wpi.first.wpilibj2.command.Command
addRequirements, addRequirements, alongWith, andThen, andThen, asProxy, beforeStarting, beforeStarting, cancel, deadlineFor, deadlineWith, 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<TargetT, PowerT> 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
-
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() -
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.
-