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 2 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
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 @@ -200,7 +200,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 @@ -34,7 +34,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 @@ -19,7 +19,7 @@ Trigger Trigger::OnChange(Command* command) {
bool current = condition();

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

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

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

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

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

previous = current;
Expand Down Expand Up @@ -103,7 +103,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 Down Expand Up @@ -135,7 +135,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 Down Expand Up @@ -170,7 +170,7 @@ Trigger Trigger::ToggleOnTrue(Command* command) {
if (command->IsScheduled()) {
command->Cancel();
} else {
command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(command);
}
}

Expand Down Expand Up @@ -206,7 +206,7 @@ Trigger Trigger::ToggleOnFalse(Command* 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 @@ -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, trueAndScheduledNoOp) {
// Scheduled and true -> no-op
m_command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(m_command);

Check failure on line 52 in wpilibNewCommands/src/test/native/cpp/frc2/command/CommandSendableButtonTest.cpp

View workflow job for this annotation

GitHub Actions / Build - Windows

'frc2::CommandScheduler::Schedule': no overloaded function could convert all the argument types
Gold856 marked this conversation as resolved.
Show resolved Hide resolved
GetScheduler().Run();
frc::SmartDashboard::UpdateValues();
EXPECT_TRUE(m_command->IsScheduled());
Expand Down Expand Up @@ -82,7 +82,7 @@

TEST_F(CommandSendableButtonTest, falseAndScheduledCancel) {
// Scheduled and false -> cancel
m_command->Schedule();
frc2::CommandScheduler::GetInstance().Schedule(m_command);

Check failure on line 85 in wpilibNewCommands/src/test/native/cpp/frc2/command/CommandSendableButtonTest.cpp

View workflow job for this annotation

GitHub Actions / Build - Windows

'frc2::CommandScheduler::Schedule': no overloaded function could convert all the argument types
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);
}
}

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 @@ -38,7 +38,7 @@ void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand();

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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 @@ -38,7 +38,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 @@ -38,7 +38,7 @@ void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand();

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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 @@ -37,7 +37,7 @@ void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand();

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void autonomousInit() {

// schedule the autonomous command (example)
if (m_autonomousCommand != null) {
m_autonomousCommand.schedule();
CommandScheduler.getInstance().schedule(m_autonomousCommand);
}
}

Expand Down
Loading
Loading