-
Notifications
You must be signed in to change notification settings - Fork 6
Command Groups
Joel Gallant edited this page Jun 19, 2013
·
1 revision
###So what's a CommandGroup? Command groups are a Command that encompasses multiple commands strung together. It runs commands sequentially or concurrently in groups, in the order of how they are added. It's difficult to conceptualize without examples, so here is one:
public final class ShootAndRun extends CommandGroup {
public ShootAndRun() {
addSequential(new ChangeRPM(3750));
addSequential(new Shoot());
addSequential(new Shoot());
addSequential(new Shoot());
addConcurrent(new DriveForwards(1520));
addConcurrent(new ChangeRPM(3200));
addConcurrent(new RunGroundPickup());
addSequential(new Shoot());
addSequential(new Shoot());
addSequential(new Shoot());
addSequential(new Shoot());
}
}
So, this command group for a middle 7 disk auto. Simply, this is what it does:
ChangeRPM(3750)
Shoot()
Shoot()
Shoot()
DriveForwards(1520) + ChangeRPM(3200) + RunGroundPickup()
Shoot()
Shoot()
Shoot()
Shoot()
What do the "+" signs mean? The commands are run concurrently, at the same time. In this example, you want to be driving while picking up disks and lowering the shooter RPM for a shorter shot. It would be silly to drive, then pickup, then drive again, then change the RPM.
###Strategies for command groups
- Make everything as concurrent as possible
- Combine repeated commands (use RepeatingCommand)
- Use common commands whenever you can
- If you need a command to run even past the next sequential command, use ThreadedCommand and add it sequentially