Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IdleCommand to wpilibJ2 command framework #5555

Merged
merged 10 commits into from
Aug 29, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ public static Command deadline(Command deadline, Command... commands) {
return new ParallelDeadlineGroup(deadline, commands);
}

/**
* Constructs a command that does nothing until interrupted
*
* @param requirements subsystems the action requires
* @return the command
* @see IdleCommand
*/
public static Command idle(Subsystem... requirements) {
return new IdleCommand(requirements);
}


private Commands() {
throw new UnsupportedOperationException("This is a utility class");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package edu.wpi.first.wpilibj2.command;

import java.util.function.BooleanSupplier;

/**
* A command that runs nothing. Has no end condition as-is; either subclass it or
* use {@link Command#withTimeout(double)} or {@link Command#until(BooleanSupplier)} to give it one.
* Used mainly for making a {@link Subsystem#setDefaultCommand(Command)} only run once
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class IdleCommand extends RunCommand {
/**
* Creates a new IdleCommand. The IdleCommand will run until interrupted without doing any action.
* Useful for making a continuously scheduled command only run once.
*
* @param requirements the subsystems to require
*/
public IdleCommand(Subsystem... requirements){
super(()-> {}, requirements);
}
}