Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Deprecate Command.schedule() #7072

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,12 @@ public WrapperCommand handleInterrupt(Runnable handler) {
});
}

/** Schedules this command. */
/**
* Schedules this command.
*
* @deprecated Use CommandScheduler.getInstance().schedule(Command...) instead
*/
@Deprecated(since = "2025", forRemoval = true)
public void schedule() {
CommandScheduler.getInstance().schedule(this);
}
Expand Down Expand Up @@ -610,7 +615,7 @@ public void initSendable(SendableBuilder builder) {
value -> {
if (value) {
if (!isScheduled()) {
schedule();
CommandScheduler.getInstance().schedule(this);
}
} else {
if (isScheduled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ProxyCommand(Command command) {
@Override
public void initialize() {
m_command = m_supplier.get();
m_command.schedule();
CommandScheduler.getInstance().schedule(m_command);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ScheduleCommand(Command... toSchedule) {
@Override
public void initialize() {
for (Command command : m_toSchedule) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Trigger onChange(Command command) {
addBinding(
(previous, current) -> {
if (previous != current) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
}
});
return this;
Expand All @@ -110,7 +110,7 @@ public Trigger onTrue(Command command) {
addBinding(
(previous, current) -> {
if (!previous && current) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
}
});
return this;
Expand All @@ -127,7 +127,7 @@ public Trigger onFalse(Command command) {
addBinding(
(previous, current) -> {
if (previous && !current) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
}
});
return this;
Expand All @@ -148,7 +148,7 @@ public Trigger whileTrue(Command command) {
addBinding(
(previous, current) -> {
if (!previous && current) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
} else if (previous && !current) {
command.cancel();
}
Expand All @@ -171,7 +171,7 @@ public Trigger whileFalse(Command command) {
addBinding(
(previous, current) -> {
if (previous && !current) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
} else if (!previous && current) {
command.cancel();
}
Expand All @@ -193,7 +193,7 @@ public Trigger toggleOnTrue(Command command) {
if (command.isScheduled()) {
command.cancel();
} else {
command.schedule();
CommandScheduler.getInstance().schedule(command);
}
}
});
Expand All @@ -214,7 +214,7 @@ public Trigger toggleOnFalse(Command command) {
if (command.isScheduled()) {
command.cancel();
} else {
command.schedule();
CommandScheduler.getInstance().schedule(command);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void Command::InitSendable(wpi::SendableBuilder& builder) {
[this](bool value) {
bool isScheduled = IsScheduled();
if (value && !isScheduled) {
Schedule();
CommandScheduler::GetInstance().Schedule(this);
} else if (!value && isScheduled) {
Cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ProxyCommand::ProxyCommand(std::unique_ptr<Command> command) {

void ProxyCommand::Initialize() {
m_command = m_supplier();
m_command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(m_command);
}

void ProxyCommand::End(bool interrupted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ScheduleCommand::ScheduleCommand(Command* toSchedule) {

void ScheduleCommand::Initialize() {
for (auto command : m_toSchedule) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void Trigger::AddBinding(wpi::unique_function<void(bool, bool)>&& body) {
Trigger Trigger::OnChange(Command* command) {
AddBinding([command](bool previous, bool current) {
if (previous != current) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
});
return *this;
Expand All @@ -38,7 +38,7 @@ Trigger Trigger::OnChange(Command* command) {
Trigger Trigger::OnChange(CommandPtr&& command) {
AddBinding([command = std::move(command)](bool previous, bool current) {
if (previous != current) {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
});
return *this;
Expand All @@ -47,7 +47,7 @@ Trigger Trigger::OnChange(CommandPtr&& command) {
Trigger Trigger::OnTrue(Command* command) {
AddBinding([command](bool previous, bool current) {
if (!previous && current) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
});
return *this;
Expand All @@ -56,7 +56,7 @@ Trigger Trigger::OnTrue(Command* command) {
Trigger Trigger::OnTrue(CommandPtr&& command) {
AddBinding([command = std::move(command)](bool previous, bool current) {
if (!previous && current) {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
});
return *this;
Expand All @@ -65,7 +65,7 @@ Trigger Trigger::OnTrue(CommandPtr&& command) {
Trigger Trigger::OnFalse(Command* command) {
AddBinding([command](bool previous, bool current) {
if (previous && !current) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
});
return *this;
Expand All @@ -74,7 +74,7 @@ Trigger Trigger::OnFalse(Command* command) {
Trigger Trigger::OnFalse(CommandPtr&& command) {
AddBinding([command = std::move(command)](bool previous, bool current) {
if (previous && !current) {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
});
return *this;
Expand All @@ -83,7 +83,7 @@ Trigger Trigger::OnFalse(CommandPtr&& command) {
Trigger Trigger::WhileTrue(Command* command) {
AddBinding([command](bool previous, bool current) {
if (!previous && current) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
} else if (previous && !current) {
command->Cancel();
}
Expand All @@ -94,7 +94,7 @@ Trigger Trigger::WhileTrue(Command* command) {
Trigger Trigger::WhileTrue(CommandPtr&& command) {
AddBinding([command = std::move(command)](bool previous, bool current) {
if (!previous && current) {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
} else if (previous && !current) {
command.Cancel();
}
Expand All @@ -105,7 +105,7 @@ Trigger Trigger::WhileTrue(CommandPtr&& command) {
Trigger Trigger::WhileFalse(Command* command) {
AddBinding([command](bool previous, bool current) {
if (previous && !current) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
} else if (!previous && current) {
command->Cancel();
}
Expand All @@ -116,7 +116,7 @@ Trigger Trigger::WhileFalse(Command* command) {
Trigger Trigger::WhileFalse(CommandPtr&& command) {
AddBinding([command = std::move(command)](bool previous, bool current) {
if (!previous && current) {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
} else if (previous && !current) {
command.Cancel();
}
Expand All @@ -130,7 +130,7 @@ Trigger Trigger::ToggleOnTrue(Command* command) {
if (command->IsScheduled()) {
command->Cancel();
} else {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
}
});
Expand All @@ -143,7 +143,7 @@ Trigger Trigger::ToggleOnTrue(CommandPtr&& command) {
if (command.IsScheduled()) {
command.Cancel();
} else {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
}
});
Expand All @@ -156,7 +156,7 @@ Trigger Trigger::ToggleOnFalse(Command* command) {
if (command->IsScheduled()) {
command->Cancel();
} else {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
}
});
Expand All @@ -169,7 +169,7 @@ Trigger Trigger::ToggleOnFalse(CommandPtr&& command) {
if (command.IsScheduled()) {
command.Cancel();
} else {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ class Command : public wpi::Sendable, public wpi::SendableHelper<Command> {

/**
* Schedules this command.
*
* @deprecated Use CommandScheduler::GetInstance().Schedule() instead
*/
[[deprecated("Use CommandScheduler::GetInstance().Schedule() instead.")]]
void Schedule();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ class CommandPtr final {

/**
* Schedules this command.
*
* @deprecated Use CommandScheduler::GetInstance().Schedule() instead
*/
[[deprecated("Use CommandScheduler::GetInstance().Schedule() instead.")]]
void Schedule() const&;

// Prevent calls on a temporary, as the returned pointer would be invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void trueAndNotScheduledSchedules() {
@Test
void trueAndScheduledNoOp() {
// Scheduled and true -> no-op
m_command.schedule();
CommandScheduler.getInstance().schedule(m_command);
CommandScheduler.getInstance().run();
SmartDashboard.updateValues();
assertTrue(m_command.isScheduled());
Expand Down Expand Up @@ -90,7 +90,7 @@ void falseAndNotScheduledNoOp() {
@Test
void falseAndScheduledCancel() {
// Scheduled and false -> cancel
m_command.schedule();
CommandScheduler.getInstance().schedule(m_command);
CommandScheduler.getInstance().run();
SmartDashboard.updateValues();
assertTrue(m_command.isScheduled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void proxyCommandScheduleTest() {

scheduler.schedule(scheduleCommand);

verify(command1).schedule();
verify(command1).initialize();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ void scheduleCommandScheduleTest() {

scheduler.schedule(scheduleCommand);

verify(command1).schedule();
verify(command2).schedule();
verify(command1).initialize();
verify(command2).initialize();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ void setNetworkButtonTest() {
pub.set(false);
button.onTrue(command);
scheduler.run();
verify(command, never()).schedule();
verify(command, never()).initialize();
pub.set(true);
scheduler.run();
scheduler.run();
verify(command).schedule();
verify(command).initialize();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void cancelWhenActiveTest() {
.until(button);

button.setPressed(false);
command1.schedule();
scheduler.schedule(command1);
scheduler.run();
assertEquals(1, startCounter.get());
assertEquals(0, endCounter.get());
Expand Down Expand Up @@ -258,13 +258,13 @@ void debounceTest() {

button.setPressed(true);
scheduler.run();
verify(command, never()).schedule();
verify(command, never()).initialize();

SimHooks.stepTiming(0.3);

button.setPressed(true);
scheduler.run();
verify(command).schedule();
verify(command).initialize();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TEST_F(CommandSendableButtonTest, trueAndNotScheduledSchedules) {

TEST_F(CommandSendableButtonTest, trueAndScheduledNoOp) {
// Scheduled and true -> no-op
m_command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(m_command.value());
GetScheduler().Run();
frc::SmartDashboard::UpdateValues();
EXPECT_TRUE(m_command->IsScheduled());
Expand Down Expand Up @@ -82,7 +82,7 @@ TEST_F(CommandSendableButtonTest, falseAndNotScheduledNoOp) {

TEST_F(CommandSendableButtonTest, falseAndScheduledCancel) {
// Scheduled and false -> cancel
m_command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(m_command.value());
GetScheduler().Run();
frc::SmartDashboard::UpdateValues();
EXPECT_TRUE(m_command->IsScheduled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand();

if (m_autonomousCommand) {
m_autonomousCommand->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(m_autonomousCommand.value());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand();

if (m_autonomousCommand != nullptr) {
m_autonomousCommand->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(m_autonomousCommand);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand();

if (m_autonomousCommand != nullptr) {
m_autonomousCommand->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(m_autonomousCommand);
}
}

Expand Down
Loading
Loading