Command Based Help: Setting a command to non-Interruptible in Java

Hi, I have been using CMD-based programming for a while now and I have come into a roadblock when it comes to setting a command to non-Interruptible in Java. I generally have my system set up in a way where all my CMDs extend the class, “CommandBase”, and then are scheduled by a trigger in the robot container bound to a Xbox controller.

I have looked in the API and have found the “setInterruptible()” method in the “Command” class, but this apparently isn’t applicable to a command established in the “CommandBase” class even though the class implements “Command”.

I want to make sure my elevator commands don’t get interrupted by another command that requires the same subsystem when triggered, so I came here for some help.

First, be careful with this. I have yet to find a good use for non-interruptible commands in several years of usage. Using one can get you stuck if the command starts behaving badly.

That said, it looks like this capability has been moved to the binding of a button to a command. For example, there is an overload of Button.whenPressed that takes a boolean for interruptibility.

2 Likes

You can make it so the command doesn’t require a subsystem. (Just don’t add the addRequirements line) Then it won’t get interrupted when another command is using the same subsystem. That being said, if you need two commands running on the same subsystem at the same time, you can probably split that subsystem up into two smaller subsystems.

Interruptibility is specified when the command is scheduled. The schedule method and all of the button bindings take an optional interruptible boolean.

From https://docs.wpilib.org/en/latest/docs/software/commandbased/command-based-changes.html#changes-to-command

void setInterruptible(boolean interruptible) has been removed; interruptibility is no longer an innate property of commands, and can be set when the command is scheduled.

So, you need to set the command as not interruptible when you schedule the command. Assuming you’re using a Button, you can do that with the following method: https://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj2/command/button/Button.html#whenPressed(edu.wpi.first.wpilibj2.command.Command,boolean)

1 Like

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