From bccc8e06ab6a8c69d4a65babfec69c881f8b82f0 Mon Sep 17 00:00:00 2001 From: WispySparks Date: Sun, 23 Feb 2025 00:22:05 -0600 Subject: [PATCH 1/3] Add Subsystem.idle() --- .../java/edu/wpi/first/wpilibj2/command/Subsystem.java | 9 +++++++++ .../src/main/native/cpp/frc2/command/Subsystem.cpp | 4 ++++ .../src/main/native/include/frc2/command/Subsystem.h | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java index c0e694774c3..3ab57f1eb34 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java @@ -169,4 +169,13 @@ default Command startRun(Runnable start, Runnable run) { default Command defer(Supplier supplier) { return Commands.defer(supplier, Set.of(this)); } + + /** + * Constructs a command does nothing until interrupted. Requires this subsystem. + * + * @return the command + */ + default Command idle() { + return Commands.idle(this); + } } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp index 876269a1b47..7ad837521da 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp @@ -72,3 +72,7 @@ CommandPtr Subsystem::StartRun(std::function start, CommandPtr Subsystem::Defer(wpi::unique_function supplier) { return cmd::Defer(std::move(supplier), {this}); } + +CommandPtr Subsystem::Idle() { + return cmd::Idle({this}); +} diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h index d62f69ca356..2969d87c360 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h @@ -178,5 +178,14 @@ class Subsystem { */ [[nodiscard]] CommandPtr Defer(wpi::unique_function supplier); + + /** + * Constructs a command does nothing until interrupted. Requires this + * subsystem. + * + * @return the command + */ + [[nodiscard]] + CommandPtr Idle(); }; } // namespace frc2 From 14224659853fc47a1aee2cd2e49f579a1a3c8f0c Mon Sep 17 00:00:00 2001 From: WispySparks Date: Sun, 23 Feb 2025 00:30:46 -0600 Subject: [PATCH 2/3] doc --- .../src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java | 2 +- .../src/main/native/include/frc2/command/Subsystem.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java index 3ab57f1eb34..dc2ca504f28 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java @@ -171,7 +171,7 @@ default Command defer(Supplier supplier) { } /** - * Constructs a command does nothing until interrupted. Requires this subsystem. + * Constructs a command that does nothing until interrupted. Requires this subsystem. * * @return the command */ diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h index 2969d87c360..8db228c3ed7 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h @@ -180,7 +180,7 @@ class Subsystem { CommandPtr Defer(wpi::unique_function supplier); /** - * Constructs a command does nothing until interrupted. Requires this + * Constructs a command that does nothing until interrupted. Requires this * subsystem. * * @return the command From d1291b259bbf1353a8f2e16b23709afc7d62534e Mon Sep 17 00:00:00 2001 From: WispySparks Date: Mon, 3 Mar 2025 19:05:00 -0600 Subject: [PATCH 3/3] Reorganize to match Commands --- .../wpi/first/wpilibj2/command/Subsystem.java | 18 +++++++++--------- .../main/native/cpp/frc2/command/Subsystem.cpp | 8 ++++---- .../native/include/frc2/command/Subsystem.h | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java index dc2ca504f28..4a0c0561491 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java @@ -98,6 +98,15 @@ default void register() { CommandScheduler.getInstance().registerSubsystem(this); } + /** + * Constructs a command that does nothing until interrupted. Requires this subsystem. + * + * @return the command + */ + default Command idle() { + return Commands.idle(this); + } + /** * Constructs a command that runs an action once and finishes. Requires this subsystem. * @@ -169,13 +178,4 @@ default Command startRun(Runnable start, Runnable run) { default Command defer(Supplier supplier) { return Commands.defer(supplier, Set.of(this)); } - - /** - * Constructs a command that does nothing until interrupted. Requires this subsystem. - * - * @return the command - */ - default Command idle() { - return Commands.idle(this); - } } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp index 7ad837521da..8282682b918 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp @@ -46,6 +46,10 @@ void Subsystem::Register() { return CommandScheduler::GetInstance().RegisterSubsystem(this); } +CommandPtr Subsystem::Idle() { + return cmd::Idle({this}); +} + CommandPtr Subsystem::RunOnce(std::function action) { return cmd::RunOnce(std::move(action), {this}); } @@ -72,7 +76,3 @@ CommandPtr Subsystem::StartRun(std::function start, CommandPtr Subsystem::Defer(wpi::unique_function supplier) { return cmd::Defer(std::move(supplier), {this}); } - -CommandPtr Subsystem::Idle() { - return cmd::Idle({this}); -} diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h index 8db228c3ed7..ab6c9321562 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h @@ -121,6 +121,15 @@ class Subsystem { */ void Register(); + /** + * Constructs a command that does nothing until interrupted. Requires this + * subsystem. + * + * @return the command + */ + [[nodiscard]] + CommandPtr Idle(); + /** * Constructs a command that runs an action once and finishes. Requires this * subsystem. @@ -178,14 +187,5 @@ class Subsystem { */ [[nodiscard]] CommandPtr Defer(wpi::unique_function supplier); - - /** - * Constructs a command that does nothing until interrupted. Requires this - * subsystem. - * - * @return the command - */ - [[nodiscard]] - CommandPtr Idle(); }; } // namespace frc2