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 fromisFinished
.
-
-
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
All Methods Instance Methods Concrete Methods 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 Detail
-
InstantCommand
public InstantCommand()
-
InstantCommand
public InstantCommand(String name)
Creates a newInstantCommand
with the given name.- Parameters:
name
- the name for this command
-
InstantCommand
public InstantCommand(Subsystem subsystem)
Creates a newInstantCommand
with the given requirement.- Parameters:
subsystem
- the subsystem this command requires
-
InstantCommand
public InstantCommand(String name, Subsystem subsystem)
Creates a newInstantCommand
with the given name and requirement.- Parameters:
name
- the name for this commandsubsystem
- the subsystem this command requires
-
InstantCommand
public InstantCommand(Runnable func)
Creates a newInstantCommand
.- Parameters:
func
- the function to run wheninitialize()
is run
-
InstantCommand
public InstantCommand(String name, Runnable func)
Creates a newInstantCommand
.- Parameters:
name
- the name for this commandfunc
- the function to run wheninitialize()
is run
-
InstantCommand
public InstantCommand(Subsystem requirement, Runnable func)
Creates a newInstantCommand
.- Parameters:
requirement
- the subsystem this command requiresfunc
- the function to run wheninitialize()
is run
-
InstantCommand
public InstantCommand(String name, Subsystem requirement, Runnable func)
Creates a newInstantCommand
.- Parameters:
name
- the name for this commandrequirement
- the subsystem this command requiresfunc
- the function to run wheninitialize()
is run
-
-
Method Detail
-
isFinished
protected boolean 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
protected void _initialize()
Trigger the stored function.Called just before this Command runs the first time.
-
-