Using Sequential Command Groups

Hello,
My team has run into an issue with running out of buttons to use when using our robot as it would be unreasonable for a driver to press a multitude of buttons to work a mechanism. This is why we are trying to use sequential command groups and making it so when we press one button, it would execute a variety of commands. My issue is, I do not know if I am using CommandGroups correctly as I am not sure as to how to make a command execute for a given time or until the command is completed before it moves to the next command.

Here is our code for the IntakeCommandGroup so our intake can tilt to a position and suck up the power cells when a button is pressed

1 Like

In the new command based framework, you generally don’t need to extend from anything except Command. If you want to run one command after another, use andThen

For example, you could use this in configureButtonBindings in your RobotContainer class:

myButton.whenPressed(new CannonIntakeMode(cannonTiltSubsystem).andThen(new IntakeCommand(intakeSubsystem));

You can also peruse the WPILib docs here: https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html#andthen-java-only

2 Likes

You can also inline command groups now. So for a sequential command group, you could do something like
myButton.whenPressed(new SequentialCommandGroup(new CannonIntakeMode(cannonTiltSubsystem), new IntakeCommand(intakeSubsystem));

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.