Skip to content

Commit 4b0eeca

Browse files
authored
[commands] Subsystem: Add default command removal method (#5064)
1 parent edf4ded commit 4b0eeca

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ default void setDefaultCommand(Command defaultCommand) {
5050
CommandScheduler.getInstance().setDefaultCommand(this, defaultCommand);
5151
}
5252

53+
/**
54+
* Removes the default command for the subsystem. This will not cancel the default command if it
55+
* is currently running.
56+
*/
57+
default void removeDefaultCommand() {
58+
CommandScheduler.getInstance().removeDefaultCommand(this);
59+
}
60+
5361
/**
5462
* Gets the default command for this subsystem. Returns null if no default command is currently
5563
* associated with the subsystem.

wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ void Subsystem::SetDefaultCommand(CommandPtr&& defaultCommand) {
2121
std::move(defaultCommand));
2222
}
2323

24+
void Subsystem::RemoveDefaultCommand() {
25+
CommandScheduler::GetInstance().RemoveDefaultCommand(this);
26+
}
27+
2428
Command* Subsystem::GetDefaultCommand() const {
2529
return CommandScheduler::GetInstance().GetDefaultCommand(this);
2630
}

wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ class Subsystem {
8383
*/
8484
void SetDefaultCommand(CommandPtr&& defaultCommand);
8585

86+
/**
87+
* Removes the default command for the subsystem. This will not cancel the
88+
* default command if it is currently running.
89+
*/
90+
void RemoveDefaultCommand();
91+
8692
/**
8793
* Gets the default command for this subsystem. Returns null if no default
8894
* command is currently associated with the subsystem.

0 commit comments

Comments
 (0)