public abstract class Command extends java.lang.Object implements NamedSendable
| Modifier and Type | Field and Description |
|---|---|
private ITableListener |
listener |
private boolean |
m_canceled
The m_canceled.
|
private boolean |
m_cancelOnModeSwitched
The m_cancel on mode switched
|
private boolean |
m_initialized
The m_initialized.
|
private boolean |
m_interruptible
The m_interruptible.
|
protected boolean |
m_locked
The m_locked.
|
private java.lang.String |
m_name
The m_name.
|
protected Command |
m_nextCommand |
private CommandGroup |
m_parent
The m_parent.
|
protected Command |
m_previousCommand |
private java.util.List<Subsystem> |
m_requirements
The m_requirements.
|
protected boolean |
m_running
The m_running.
|
private boolean |
m_runWhenDisabled
The m_run when disabled.
|
private double |
m_startTime
The m_start time.
|
protected byte |
m_state |
private ITable |
m_table
The m_table.
|
private double |
m_timeout
The m_timeout.
|
| Constructor and Description |
|---|
Command()
Instantiates a new command.
|
Command(double timeout)
Instantiates a new command.
|
Command(java.lang.String name)
Instantiates a new command.
|
Command(java.lang.String name,
double timeout)
Instantiates a new command.
|
Command(Subsystem system) |
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
_cancel()
Cancel_impl.
|
(package private) void |
_end()
End_impl.
|
(package private) void |
_execute()
Execute_impl.
|
(package private) void |
_initialize()
Initialize_impl.
|
(package private) void |
_interrupted()
Interrupted_impl.
|
void |
cancel()
Cancel.
|
boolean |
doesRequire(Subsystem system)
Does require.
|
protected abstract void |
end()
Called when the command ended peacefully.
|
protected abstract void |
execute()
The execute method is called repeatedly until this Command either finishes
or is canceled.
|
CommandGroup |
getGroup()
Returns the
CommandGroup that this command is a part of. |
java.lang.String |
getName()
Gets the name.
|
(package private) java.util.List<Subsystem> |
getRequirements()
Gets the requirements.
|
java.lang.String |
getSmartDashboardType() |
ITable |
getTable() |
protected abstract void |
initialize()
The initialize method is called the first time this Command is run after
being started.
|
void |
initTable(ITable table) |
protected abstract void |
interrupted()
Called when the command ends because somebody called
cancel()
or another command shared the same requirements as this one, and booted
it out. |
boolean |
isCanceled()
Checks if is canceled.
|
protected abstract boolean |
isFinished()
Returns whether this command is finished.
|
boolean |
isInterruptible()
Checks if is interruptible.
|
boolean |
isRunning()
Checks if is running.
|
protected boolean |
isTimedOut()
Checks if is timed out.
|
(package private) void |
removed()
Removed.
|
protected void |
requires(Subsystem subsys)
Requires.
|
(package private) boolean |
run()
Run.
|
void |
setCancelOnModeSwitch(boolean cancel)
Sets whether or not this
Command should continue running when the robot switches mode. |
void |
setInterruptible(boolean interruptible)
Sets the interruptible.
|
(package private) void |
setParent(CommandGroup parent)
Sets the parent.
|
void |
setRunWhenDisabled(boolean run)
Sets whether or not this
Command should run when the robot is disabled. |
protected void |
setTimeout(double timeout)
Sets the timeout.
|
void |
start()
Start.
|
(package private) void |
startRunning()
Start running.
|
private void |
startTiming()
Start timing.
|
double |
timeSinceInitialized()
Time since initialized.
|
java.lang.String |
toString()
The string representation for a
Command is by default its name. |
boolean |
willCancelOnModeSwitch()
Returns whether or not this
Command will cancel when the robot switches modes. |
boolean |
willRunWhenDisabled()
Returns whether or not this
Command will run when the robot is disabled, or if it will cancel itself. |
private java.lang.String m_name
private double m_startTime
private double m_timeout
private boolean m_initialized
private java.util.List<Subsystem> m_requirements
protected boolean m_running
private boolean m_interruptible
private boolean m_canceled
protected boolean m_locked
private boolean m_runWhenDisabled
private boolean m_cancelOnModeSwitched
protected Command m_previousCommand
protected Command m_nextCommand
private CommandGroup m_parent
private ITable m_table
protected byte m_state
private ITableListener listener
public Command()
public Command(Subsystem system)
public Command(java.lang.String name)
name - the namepublic Command(double timeout)
timeout - the timeoutpublic Command(java.lang.String name,
double timeout)
name - the nametimeout - the timeoutpublic java.lang.String getName()
getName in interface NamedSendableprotected final void setTimeout(double timeout)
timeout - the new timeoutpublic final double timeSinceInitialized()
protected void requires(Subsystem subsys)
subsys - the subsysvoid removed()
boolean run()
protected abstract void initialize()
void _initialize()
protected abstract void execute()
void _execute()
protected abstract boolean isFinished()
end() will be called.
It may be useful for a team to reference the isTimedOut() method
for time-sensitive commands.
isTimedOut()protected abstract void end()
void _end()
protected abstract void interrupted()
cancel()
or another command shared the same requirements as this one, and booted
it out.
This is where you may want to wrap up loose ends, like shutting off a motor that was being used in the command.
Generally, it is useful to simply call the end() method
within this method
void _interrupted()
private void startTiming()
protected boolean isTimedOut()
java.util.List<Subsystem> getRequirements()
void setParent(CommandGroup parent)
parent - the new parentpublic void start()
void startRunning()
public boolean isRunning()
public void cancel()
void _cancel()
public boolean isCanceled()
public boolean isInterruptible()
public void setInterruptible(boolean interruptible)
interruptible - the new interruptiblepublic boolean doesRequire(Subsystem system)
system - the systempublic CommandGroup getGroup()
CommandGroup that this command is a part of.
Will return null if this Command is not in a group.CommandGroup that this command is a part of (or null if not in group)public void setRunWhenDisabled(boolean run)
Command should run when the robot is disabled.
By default a command will not run when the robot is disabled, and will in fact be canceled.
run - whether or not this command should run when the robot is disabledpublic boolean willRunWhenDisabled()
Command will run when the robot is disabled, or if it will cancel itself.Command will run when the robot is disabled, or if it will cancel itselfpublic void setCancelOnModeSwitch(boolean cancel)
Command should continue running when the robot switches mode.
By default a command will cancel when the mode is switched
cancel - whether or not this command should cancel when the robot switches mode.public boolean willCancelOnModeSwitch()
Command will cancel when the robot switches modes.Command will cancel when the robot switches modes.public java.lang.String toString()
Command is by default its name.toString in class java.lang.Objectpublic java.lang.String getSmartDashboardType()
getSmartDashboardType in interface Sendable