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 @@ -514,7 +514,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 @@ -591,7 +596,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 @@ -66,7 +66,7 @@ public void run() {
boolean pressed = m_condition.getAsBoolean();

if (m_pressedLast != pressed) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
}

m_pressedLast = pressed;
Expand All @@ -92,7 +92,7 @@ public void run() {
boolean pressed = m_condition.getAsBoolean();

if (!m_pressedLast && pressed) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
}

m_pressedLast = pressed;
Expand All @@ -118,7 +118,7 @@ public void run() {
boolean pressed = m_condition.getAsBoolean();

if (m_pressedLast && !pressed) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
}

m_pressedLast = pressed;
Expand Down Expand Up @@ -148,7 +148,7 @@ public void run() {
boolean pressed = m_condition.getAsBoolean();

if (!m_pressedLast && pressed) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
} else if (m_pressedLast && !pressed) {
command.cancel();
}
Expand Down Expand Up @@ -180,7 +180,7 @@ public void run() {
boolean pressed = m_condition.getAsBoolean();

if (m_pressedLast && !pressed) {
command.schedule();
CommandScheduler.getInstance().schedule(command);
} else if (!m_pressedLast && pressed) {
command.cancel();
}
Expand Down Expand Up @@ -211,7 +211,7 @@ public void run() {
if (command.isScheduled()) {
command.cancel();
} else {
command.schedule();
CommandScheduler.getInstance().schedule(command);
}
}

Expand Down Expand Up @@ -241,7 +241,7 @@ public void run() {
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 @@ -193,7 +193,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 @@ -21,7 +21,7 @@ Trigger Trigger::OnChange(Command* command) {
bool current = condition();

if (previous != current) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}

previous = current;
Expand All @@ -35,7 +35,7 @@ Trigger Trigger::OnChange(CommandPtr&& command) {
bool current = condition();

if (previous != current) {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}

previous = current;
Expand All @@ -49,7 +49,7 @@ Trigger Trigger::OnTrue(Command* command) {
bool current = condition();

if (!previous && current) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}

previous = current;
Expand All @@ -63,7 +63,7 @@ Trigger Trigger::OnTrue(CommandPtr&& command) {
bool current = condition();

if (!previous && current) {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}

previous = current;
Expand All @@ -77,7 +77,7 @@ Trigger Trigger::OnFalse(Command* command) {
bool current = condition();

if (previous && !current) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}

previous = current;
Expand All @@ -91,7 +91,7 @@ Trigger Trigger::OnFalse(CommandPtr&& command) {
bool current = condition();

if (previous && !current) {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}

previous = current;
Expand All @@ -105,7 +105,7 @@ Trigger Trigger::WhileTrue(Command* command) {
bool current = condition();

if (!previous && current) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
} else if (previous && !current) {
command->Cancel();
}
Expand All @@ -121,7 +121,7 @@ Trigger Trigger::WhileTrue(CommandPtr&& command) {
bool current = condition();

if (!previous && current) {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
} else if (previous && !current) {
command.Cancel();
}
Expand All @@ -137,7 +137,7 @@ Trigger Trigger::WhileFalse(Command* command) {
bool current = condition();

if (previous && !current) {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
} else if (!previous && current) {
command->Cancel();
}
Expand All @@ -153,7 +153,7 @@ Trigger Trigger::WhileFalse(CommandPtr&& command) {
bool current = condition();

if (!previous && current) {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
} else if (previous && !current) {
command.Cancel();
}
Expand All @@ -172,7 +172,7 @@ Trigger Trigger::ToggleOnTrue(Command* command) {
if (command->IsScheduled()) {
command->Cancel();
} else {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
}

Expand All @@ -190,7 +190,7 @@ Trigger Trigger::ToggleOnTrue(CommandPtr&& command) {
if (command.IsScheduled()) {
command.Cancel();
} else {
command.Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
}

Expand All @@ -208,7 +208,7 @@ Trigger Trigger::ToggleOnFalse(Command* command) {
if (command->IsScheduled()) {
command->Cancel();
} else {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
}

Expand All @@ -226,7 +226,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 @@ -406,7 +406,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 @@ -286,7 +286,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