Loop commandgroup while button held

Using Java and the new command framework, does anyone have a creative idea for how to repeatedly run a commandgroup while a button is held? We have a sequence of commands we’d like to run, and when they are done running we’d like to run them again, as long as the button is held.

Here’s the command group and button binding. This runs it once:

var pixyHeldCommand = new PixyAssistCommand(driveTrainSubsystem, pixyVision)
        .andThen(new ParallelCommandGroup(
            new RunCommand(intakeSubsystem::intake, intakeSubsystem),
            new RunCommand(() -> driveTrainSubsystem.arcadeDrive(.2, 0, false), driveTrainSubsystem).withTimeout(2)));

new JoystickButton(driverController, XboxController.Button.kX.value)

The .perpetually() decorator was the first thought, but that won’t loop around and run the sequence over again.

Does this work…?

new JoystickButton(driverController, XboxController.Button.kX.value)
1 Like

Oh yes, that should work. I missed that slight distinction between whenHeld and whileHeld. I knew there had to be an easy button!

1 Like

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