Pause a command group if a button is released, and resume where it left off when it's pressed again?

So I’m trying to set up climb automation, and I need a way to pause the climb when the button is released to compensate for swing and then resume where it left off when the button is pressed again. I am using command groups with our climber-related subsystems to handle the order. Is there a way to do this with command groups?

I guess you can use WaitUntilCommands to stall the command.

2 Likes

I’m not aware of an easy way to do this. Part of the problem is what it means to pause a command. What if one command leaves motors running?

If I were attempting this, I would think about writing a version of SequentialCommandGroup that takes a “pause” BooleanSupplier so that the execute method does not initialize a new command while paused.

Regardless, when programming an AutoClimb, I would ensure that the drive team is trained in how to interrupt it.

1 Like

We wanted to do the same thing. The technique we used involved keeping the “state” of the command in variables that were NOT initialized in the command’s initialize() or end() methods. We arranged that they were initialized at command object creation and also created a method that could be called to explicitly re-initialize them.
Make sure that the end() method stops the motors. Bind the command to a button.whenHeld. Releasing the button causes the command to end, stopping the motion. When the button is pressed again the command will resume where it left off.
We made the choice to make the state variables static so that if we inadvertantly created multiple instances they would share state. Whether to do that is your choice.

3 Likes

I realize you specifically asked about command groups. What I laid out doesn’t use a command group – you’d have to build a variant of SequentialCommandGroup that was itself resumable and then make all the commands within it resumable. So it didn’t seem worth it.

That’s exactly how I’d do it if I had to - in this situation, I’d avoid command groups unless you’ve got time for a really deep dive to make a resumable command group - I’d be hard pressed to come up with something that would warrant that much effort.

There are times when you take a problem and look for a solution and others where you redefine the problem to fit existing solutions. It’s just how it goes IMO and being able to tell when you should do one or the other comes down to experience and budget.

1 Like

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