diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index 0130905fb4..870feb387c 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -151,6 +151,21 @@ public final class Commands { return new SelectCommand(commands, selector); } + /** + * Constructs a command that schedules the command returned from the supplier when initialized, + * and ends when it is no longer scheduled. The supplier is called when the command is + * initialized. + * + * @param supplier the command supplier + * @return the command + * @see ProxyCommand + */ + public static Command deferredProxy(Supplier supplier) { + return new ProxyCommand(supplier); + } + + // Command Groups + /** * Runs a group of commands in series, one after the other. * @@ -162,8 +177,6 @@ public final class Commands { return new SequentialCommandGroup(commands); } - // Command Groups - /** * Runs a group of commands in series, one after the other. Once the last command ends, the group * is restarted. diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp index 5c847b1d19..b7333f9e34 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp @@ -11,6 +11,7 @@ #include "frc2/command/ParallelDeadlineGroup.h" #include "frc2/command/ParallelRaceGroup.h" #include "frc2/command/PrintCommand.h" +#include "frc2/command/ProxyCommand.h" #include "frc2/command/RunCommand.h" #include "frc2/command/SequentialCommandGroup.h" #include "frc2/command/WaitCommand.h" @@ -58,6 +59,14 @@ CommandPtr cmd::Print(std::string_view msg) { return PrintCommand(msg).ToPtr(); } +CommandPtr cmd::DeferredProxy(wpi::unique_function supplier) { + return ProxyCommand(std::move(supplier)).ToPtr(); +} + +CommandPtr cmd::DeferredProxy(wpi::unique_function supplier) { + return ProxyCommand(std::move(supplier)).ToPtr(); +} + CommandPtr cmd::Wait(units::second_t duration) { return WaitCommand(duration).ToPtr(); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h index 94ae8dce26..7653188dc6 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h @@ -142,6 +142,26 @@ CommandPtr Select(std::function selector, return SelectCommand(std::move(selector), std::move(vec)).ToPtr(); } +/** + * Constructs a command that schedules the command returned from the supplier + * when initialized, and ends when it is no longer scheduled. The supplier is + * called when the command is initialized. + * + * @param supplier the command supplier + */ +[[nodiscard]] +CommandPtr DeferredProxy(wpi::unique_function supplier); + +/** + * Constructs a command that schedules the command returned from the supplier + * when initialized, and ends when it is no longer scheduled. The supplier is + * called when the command is initialized. + * + * @param supplier the command supplier + */ +[[nodiscard]] +CommandPtr DeferredProxy(wpi::unique_function supplier); + // Command Groups namespace impl {