diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index 3a5ee405f6..255291b933 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -287,11 +287,32 @@ public abstract class Command implements Sendable { * * @param parallel the commands to run in parallel * @return the decorated command + * @deprecated Use {@link deadlineFor} instead. */ + @Deprecated(since = "2025", forRemoval = true) public ParallelDeadlineGroup deadlineWith(Command... parallel) { return new ParallelDeadlineGroup(this, parallel); } + /** + * Decorates this command with a set of commands to run parallel to it, ending when the calling + * command ends and interrupting all the others. Often more convenient/less-verbose than + * constructing a new {@link ParallelDeadlineGroup} explicitly. + * + *

Note: This decorator works by adding this command to a composition. The command the + * decorator was called on cannot be scheduled independently or be added to a different + * composition (namely, decorators), unless it is manually cleared from the list of composed + * commands with {@link CommandScheduler#removeComposedCommand(Command)}. The command composition + * returned from this method can be further decorated without issue. + * + * @param parallel the commands to run in parallel. Note the parallel commands will be interupted + * when the deadline command ends + * @return the decorated command + */ + public ParallelDeadlineGroup deadlineFor(Command... parallel) { + return new ParallelDeadlineGroup(this, parallel); + } + /** * Decorates this command with a set of commands to run parallel to it, ending when the last * command ends. Often more convenient/less-verbose than constructing a new {@link diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 6fa86d3003..4cd0cbee9d 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -174,6 +174,15 @@ CommandPtr CommandPtr::DeadlineWith(CommandPtr&& parallel) && { return std::move(*this); } +CommandPtr CommandPtr::DeadlineFor(CommandPtr&& parallel) && { + AssertValid(); + std::vector> vec; + vec.emplace_back(std::move(parallel).Unwrap()); + m_ptr = + std::make_unique(std::move(m_ptr), std::move(vec)); + return std::move(*this); +} + CommandPtr CommandPtr::AlongWith(CommandPtr&& parallel) && { AssertValid(); std::vector> vec; diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index f4548e4438..e2f534f754 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -191,9 +191,21 @@ class CommandPtr final { * @param parallel the commands to run in parallel * @return the decorated command */ - [[nodiscard]] + [[nodiscard]] [[deprecated("Replace with DeadlineFor")]] CommandPtr DeadlineWith(CommandPtr&& parallel) &&; + /** + * Decorates this command with a set of commands to run parallel to it, ending + * when the calling command ends and interrupting all the others. Often more + * convenient/less-verbose than constructing a new {@link + * ParallelDeadlineGroup} explicitly. + * + * @param parallel the commands to run in parallel. Note the parallel commands + * will be interupted when the deadline command ends + * @return the decorated command + */ + [[nodiscard]] + CommandPtr DeadlineFor(CommandPtr&& parallel) &&; /** * Decorates this command with a set of commands to run parallel to it, ending * when the last command ends. Often more convenient/less-verbose than diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java index 0f66acdef2..582c176596 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java @@ -148,7 +148,7 @@ class CommandDecoratorTest extends CommandTestBase { Command endsBefore = new InstantCommand(); Command endsAfter = new WaitUntilCommand(() -> false); - Command group = dictator.deadlineWith(endsBefore, endsAfter); + Command group = dictator.deadlineFor(endsBefore, endsAfter); scheduler.schedule(group); scheduler.run();