Package edu.wpi.first.wpilibj.command
Class InstantCommand
java.lang.Object
edu.wpi.first.wpilibj.command.Command
edu.wpi.first.wpilibj.command.InstantCommand
- All Implemented Interfaces:
Sendable
,AutoCloseable
- Direct Known Subclasses:
PrintCommand
,StartCommand
public class InstantCommand extends Command
This command will execute once, then finish immediately afterward.
Subclassing InstantCommand
is shorthand for returning true from isFinished
.
-
Constructor Summary
Constructors Constructor Description InstantCommand()
InstantCommand(Subsystem subsystem)
Creates a newInstantCommand
with the given requirement.InstantCommand(Subsystem requirement, Runnable func)
Creates a newInstantCommand
.InstantCommand(Runnable func)
Creates a newInstantCommand
.InstantCommand(String name)
Creates a newInstantCommand
with the given name.InstantCommand(String name, Subsystem subsystem)
Creates a newInstantCommand
with the given name and requirement.InstantCommand(String name, Subsystem requirement, Runnable func)
Creates a newInstantCommand
.InstantCommand(String name, Runnable func)
Creates a newInstantCommand
. -
Method Summary
Modifier and Type Method Description protected void
_initialize()
Trigger the stored function.protected boolean
isFinished()
Returns whether this command is finished.Methods inherited from class edu.wpi.first.wpilibj.command.Command
cancel, clearRequirements, close, doesRequire, end, execute, getGroup, getName, getSubsystem, initialize, initSendable, interrupted, isCanceled, isCompleted, isInterruptible, isRunning, isTimedOut, requires, setInterruptible, setName, setRunWhenDisabled, setSubsystem, setTimeout, start, timeSinceInitialized, toString, willRunWhenDisabled
-
Constructor Details
-
InstantCommand
public InstantCommand() -
InstantCommand
Creates a newInstantCommand
with the given name.- Parameters:
name
- the name for this command
-
InstantCommand
Creates a newInstantCommand
with the given requirement.- Parameters:
subsystem
- the subsystem this command requires
-
InstantCommand
Creates a newInstantCommand
with the given name and requirement.- Parameters:
name
- the name for this commandsubsystem
- the subsystem this command requires
-
InstantCommand
Creates a newInstantCommand
.- Parameters:
func
- the function to run wheninitialize()
is run
-
InstantCommand
Creates a newInstantCommand
.- Parameters:
name
- the name for this commandfunc
- the function to run wheninitialize()
is run
-
InstantCommand
Creates a newInstantCommand
.- Parameters:
requirement
- the subsystem this command requiresfunc
- the function to run wheninitialize()
is run
-
InstantCommand
Creates a newInstantCommand
.- Parameters:
name
- the name for this commandrequirement
- the subsystem this command requiresfunc
- the function to run wheninitialize()
is run
-
-
Method Details
-
isFinished
Description copied from class:Command
Returns whether this command is finished. If it is, then the command will be removed andend()
will be called.It may be useful for a team to reference the
isTimedOut()
method for time-sensitive commands.Returning false will result in the command never ending automatically. It may still be canceled manually or interrupted by another command. Returning true will result in the command executing once and finishing immediately. We recommend using
InstantCommand
for this.- Specified by:
isFinished
in classCommand
- Returns:
- whether this command is finished.
- See Also:
isTimedOut()
-
_initialize
Trigger the stored function.Called just before this Command runs the first time.
-