Class CommandGroup
public class CommandGroup extends Command
CommandGroup is a list of commands which are executed in sequence.
Commands in a CommandGroup are added using the addSequential(...) method and are called sequentially.
CommandGroups are themselves commands and can be given to
other CommandGroups.
CommandGroups will carry all of the requirements of their subcommands. Additional requirements can be specified by calling requires(...) normally in the constructor.
CommandGroups can also execute commands in parallel, simply by adding them using addParallel(...).
- See Also:
Command,Subsystem,IllegalUseOfCommandException
-
Constructor Summary
Constructors Constructor Description CommandGroup()Creates a newCommandGroup.CommandGroup(java.lang.String name)Creates a newCommandGroupwith the given name. -
Method Summary
Modifier and Type Method Description voidaddParallel(Command command)Adds a new childCommandto the group.voidaddParallel(Command command, double timeout)Adds a new childCommandto the group with the given timeout.voidaddSequential(Command command)Adds a newCommandto the group.voidaddSequential(Command command, double timeout)Adds a newCommandto the group with a given timeout.booleanisInterruptible()Returns whether or not this group is interruptible.Methods inherited from class edu.wpi.first.wpilibj.command.Command
cancel, doesRequire, isCanceled, isCompleted, isRunning, setRunWhenDisabled, start, timeSinceInitialized, willRunWhenDisabled
-
Constructor Details
-
CommandGroup
public CommandGroup()Creates a newCommandGroup. The name of this command will be set to its class name. -
CommandGroup
public CommandGroup(java.lang.String name)Creates a newCommandGroupwith the given name.- Parameters:
name- the name for this command group- Throws:
java.lang.IllegalArgumentException- if name is null
-
-
Method Details
-
addSequential
Adds a newCommandto the group. TheCommandwill be started after all the previously addedCommands.Note that any requirements the given
Commandhas will be added to the group. For this reason, aCommand'srequirements can not be changed after being added to a group.It is recommended that this method be called in the constructor.
- Parameters:
command- TheCommandto be added- Throws:
java.lang.ExceptionIllegalUseOfCommandException- if the group has been started before or been given to another groupjava.lang.IllegalArgumentException- if command is null
-
addSequential
Adds a newCommandto the group with a given timeout. TheCommandwill be started after all the previously added commands.Once the
Commandis started, it will be run until it finishes or the time expires, whichever is sooner. Note that the givenCommandwill have no knowledge that it is on a timer.Note that any requirements the given
Commandhas will be added to the group. For this reason, aCommand'srequirements can not be changed after being added to a group.It is recommended that this method be called in the constructor.
- Parameters:
command- TheCommandto be addedtimeout- The timeout (in seconds)- Throws:
java.lang.ExceptionIllegalUseOfCommandException- if the group has been started before or been given to another group or if theCommandhas been started before or been given to another groupjava.lang.IllegalArgumentException- if command is null or timeout is negative
-
addParallel
Adds a new childCommandto the group. TheCommandwill be started after all the previously addedCommands.Instead of waiting for the child to finish, a
CommandGroupwill have it run at the same time as the subsequentCommands. The child will run until either it finishes, a new child with conflicting requirements is started, or the main sequence runs aCommandwith 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
Commandhas will be added to the group. For this reason, aCommand'srequirements can not be changed after being added to a group.It is recommended that this method be called in the constructor.
- Parameters:
command- The command to be added- Throws:
java.lang.ExceptionIllegalUseOfCommandException- if the group has been started before or been given to another command groupjava.lang.IllegalArgumentException- if command is null
-
addParallel
Adds a new childCommandto the group with the given timeout. TheCommandwill be started after all the previously addedCommands.Once the
Commandis started, it will run until it finishes, is interrupted, or the time expires, whichever is sooner. Note that the givenCommandwill have no knowledge that it is on a timer.Instead of waiting for the child to finish, a
CommandGroupwill have it run at the same time as the subsequentCommands. The child will run until either it finishes, the timeout expires, a new child with conflicting requirements is started, or the main sequence runs aCommandwith 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
Commandhas will be added to the group. For this reason, aCommand'srequirements can not be changed after being added to a group.It is recommended that this method be called in the constructor.
- Parameters:
command- The command to be addedtimeout- The timeout (in seconds)- Throws:
java.lang.ExceptionIllegalUseOfCommandException- if the group has been started before or been given to another command groupjava.lang.IllegalArgumentException- if command is null
-
isInterruptible
public boolean isInterruptible()Returns whether or not this group is interruptible. A command group will be uninterruptible ifsetInterruptable(false)was called or if it is currently running an uninterruptible command or child.- Overrides:
isInterruptiblein classCommand- Returns:
- whether or not this
CommandGroupis interruptible.
-