mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
[cmd3] Change Command.noRequirements to accept a command implementation (#8783)
This is more ergonomic than `Command.noRequirements().executing(...)`
This commit is contained in:
@@ -85,7 +85,7 @@ import org.wpilib.units.measure.Time;
|
||||
* // to run when not in use. Interrupting one of the inner commands while it's
|
||||
* // running will cancel the entire sequence.
|
||||
* private Command advancedScoringSequence() {
|
||||
* return Command.noRequirements().executing(coroutine -> {
|
||||
* return Command.noRequirements(coroutine -> {
|
||||
* coroutine.await(drivetrain.driveToScoringLocation());
|
||||
* coroutine.await(elevator.moveToScoringHeight());
|
||||
* coroutine.await(gripper.release());
|
||||
@@ -226,15 +226,17 @@ public interface Command {
|
||||
* Creates a command that does not require any hardware; that is, it does not affect the state of
|
||||
* any physical objects. This is useful for commands that do some cleanup or state management,
|
||||
* such as resetting odometry or sensors, that you don't want to interrupt a command that's
|
||||
* controlling the mechanisms it affects.
|
||||
* controlling the mechanisms it affects, or for a command composition that you don't want to
|
||||
* inherit the requirements of its child commands.
|
||||
*
|
||||
* <p>More configuration options are needed after calling this function before the command can be
|
||||
* created. See {@link StagedCommandBuilder} for details.
|
||||
*
|
||||
* @param body The command's body. Cannot be null.
|
||||
* @return a builder that can be used to configure the resulting command
|
||||
*/
|
||||
static NeedsExecutionBuilderStage noRequirements() {
|
||||
return new StagedCommandBuilder().noRequirements();
|
||||
static NeedsNameBuilderStage noRequirements(Consumer<Coroutine> body) {
|
||||
return new StagedCommandBuilder().noRequirements().executing(body);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,7 +328,7 @@ public interface Command {
|
||||
static NeedsNameBuilderStage waitUntil(BooleanSupplier condition) {
|
||||
requireNonNullParam(condition, "condition", "Command.waitUntil");
|
||||
|
||||
return noRequirements().executing(coroutine -> coroutine.waitUntil(condition));
|
||||
return noRequirements(coroutine -> coroutine.waitUntil(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -339,7 +341,7 @@ public interface Command {
|
||||
static NeedsNameBuilderStage waitFor(Time duration) {
|
||||
requireNonNullParam(duration, "duration", "Command.waitFor");
|
||||
|
||||
return noRequirements().executing(coroutine -> coroutine.wait(duration));
|
||||
return noRequirements(coroutine -> coroutine.wait(duration));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,7 +79,7 @@ public final class Coroutine {
|
||||
*
|
||||
* <pre>{@code
|
||||
* Command example() {
|
||||
* return Command.noRequirements().executing(coroutine -> {
|
||||
* return Command.noRequirements(coroutine -> {
|
||||
* Command child = ...;
|
||||
* coroutine.fork(child);
|
||||
* // ... do more things
|
||||
@@ -121,7 +121,7 @@ public final class Coroutine {
|
||||
*
|
||||
* <pre>{@code
|
||||
* Command example() {
|
||||
* return Command.noRequirements().executing(coroutine -> {
|
||||
* return Command.noRequirements(coroutine -> {
|
||||
* Collection<Command> innerCommands = ...;
|
||||
* coroutine.fork(innerCommands);
|
||||
* // ... do more things
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.wpilib.units.measure.Time;
|
||||
* canceled when the enclosing command exits.
|
||||
*
|
||||
* <pre>{@code
|
||||
* Command shootWhileAiming = Command.noRequirements().executing(co -> {
|
||||
* Command shootWhileAiming = Command.noRequirements(co -> {
|
||||
* turret.atTarget.onTrue(shooter.shootOnce());
|
||||
* co.await(turret.lockOnGoal());
|
||||
* }).named("Shoot While Aiming");
|
||||
|
||||
Reference in New Issue
Block a user