public class CommandGroup extends Command
| Modifier and Type | Field and Description |
|---|---|
private static byte |
BRANCH_CHILD
The Constant BRANCH_CHILD.
|
private static byte |
BRANCH_PEER
The Constant BRANCH_PEER.
|
private static byte |
IN_SEQUENCE
The Constant IN_SEQUENCE.
|
(package private) java.util.Vector<Command> |
m_children
The m_children.
|
(package private) java.util.List<Command> |
m_commands
The m_commands.
|
(package private) int |
m_currentCommandIndex
The m_current command index.
|
m_locked, m_nextCommand, m_previousCommand, m_running, m_state| Constructor and Description |
|---|
CommandGroup()
Instantiates a new command group.
|
CommandGroup(java.lang.String name)
Instantiates a new command group.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
_end()
End_impl.
|
(package private) void |
_execute()
Execute_impl.
|
(package private) void |
_initialize()
Initialize_impl.
|
(package private) void |
_interrupted()
Interrupted_impl.
|
private void |
addCommand(Command command,
byte state,
double timeout)
Adds the command.
|
void |
addParallel(Command command)
Adds a new child
Command to the group. |
void |
addParallel(Command command,
double timeout)
Adds a new child
Command to the group with the given timeout. |
void |
addSequential(Command command)
Adds a new
Command to the group. |
void |
addSequential(Command command,
double timeout)
Adds a new
Command to the group with a given timeout. |
private void |
cancelConflicts(Command command)
Cancel conflicts.
|
protected void |
end()
Called when the command ended peacefully.
|
protected void |
execute()
The execute method is called repeatedly until this Command either finishes
or is canceled.
|
protected void |
initialize()
The initialize method is called the first time this Command is run after
being started.
|
protected 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. |
protected boolean |
isFinished()
Returns whether this command is finished.
|
boolean |
isInterruptible()
Checks if is interruptible.
|
protected static Command |
Wait(double timeout) |
_cancel, cancel, doesRequire, getGroup, getName, getRequirements, getSmartDashboardType, getTable, initTable, isCanceled, isRunning, isTimedOut, removed, requires, run, setCancelOnModeSwitch, setInterruptible, setParent, setRunWhenDisabled, setTimeout, start, startRunning, timeSinceInitialized, toString, willCancelOnModeSwitch, willRunWhenDisabledprivate static final byte IN_SEQUENCE
private static final byte BRANCH_PEER
private static final byte BRANCH_CHILD
final java.util.List<Command> m_commands
final java.util.Vector<Command> m_children
int m_currentCommandIndex
public CommandGroup()
public CommandGroup(java.lang.String name)
name - the namepublic final void addSequential(Command command)
Command to the group. The Command will be started after
all the previously added Commands.
Note that any requirements the given Command has will be added to the
group. For this reason, a Command's requirements can not be changed after
being added to a group.
It is recommended that this method be called in the constructor.
command - The Command to be addedpublic final void addSequential(Command command, double timeout)
Command to the group with a given timeout.
The Command will be started after all the previously added commands.
A timeout of -1 means it will not time out. This is the same a omitting the timeout value.
Once the Command is started, it will be run until it finishes or the time
expires, whichever is sooner. Note that the given Command will have no
knowledge that it is on a timer.
Note that any requirements the given Command has will be added to the
group. For this reason, a Command's requirements can not be changed after
being added to a group.
It is recommended that this method be called in the constructor.
command - The Command to be addedtimeout - The timeout (in seconds)public final void addParallel(Command command)
Command to the group. The Command will be started after
all the previously added Commands.
Instead of waiting for the child to finish, a CommandGroup will have it
run at the same time as the subsequent Commands. The child will run until either
it finishes, a new child with conflicting requirements is started, or
the main sequence runs a Command with conflicting requirements. In the latter
two cases, the child will be canceled even if it says it can't be
interrupted.
Note that any requirements the given Command has will be added to the
group. For this reason, a Command's requirements can not be changed after
being added to a group.
It is recommended that this method be called in the constructor.
command - The command to be addedpublic final void addParallel(Command command, double timeout)
Command to the group with the given timeout. The Command will be started after
all the previously added Commands.
A timeout of -1 means it will not time out. This is the same a omitting the timeout value.
Once the Command is started, it will run until it finishes, is interrupted,
or the time expires, whichever is sooner. Note that the given Command will have no
knowledge that it is on a timer.
Instead of waiting for the child to finish, a CommandGroup will have it
run at the same time as the subsequent Commands. The child will run until either
it finishes, the timeout expires, a new child with conflicting requirements is started, or
the main sequence runs a Command with conflicting requirements. In the latter
two cases, the child will be canceled even if it says it can't be
interrupted.
Note that any requirements the given Command has will be added to the
group. For this reason, a Command's requirements can not be changed after
being added to a group.
It is recommended that this method be called in the constructor.
command - The command to be addedtimeout - The timeout (in seconds)private final void addCommand(Command command, byte state, double timeout)
command - the commandstate - the statetimeout - the timeoutfinal void _initialize()
_initialize in class Commandfinal void _interrupted()
_interrupted in class Commandprotected final boolean isFinished()
end() will be called.
It may be useful for a team to reference the isTimedOut() method
for time-sensitive commands.
isFinished in class CommandisTimedOut()protected final void initialize()
initialize in class Commandprotected final void execute()
protected final void end()
protected final 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
interrupted in class Commandpublic final boolean isInterruptible()
isInterruptible in class Commandprotected static final Command Wait(double timeout)
private final void cancelConflicts(Command command)
command - the command