[cmd2] Flatten wpi::cmd::cmd to wpi::cmd (#8764)

Fixes #8763
This commit is contained in:
sciencewhiz
2026-04-13 21:48:13 -07:00
committed by GitHub
parent f89cf297e4
commit 613c86d1d7
36 changed files with 185 additions and 204 deletions

View File

@@ -22,29 +22,28 @@
#include "wpi/commands2/WaitUntilCommand.hpp"
#include "wpi/util/FunctionExtras.hpp"
using namespace wpi::cmd;
namespace wpi::cmd {
// Factories
CommandPtr cmd::None() {
CommandPtr None() {
return InstantCommand().ToPtr();
}
CommandPtr cmd::Idle(Requirements requirements) {
CommandPtr Idle(Requirements requirements) {
return Run([] {}, requirements);
}
CommandPtr cmd::RunOnce(std::function<void()> action,
Requirements requirements) {
CommandPtr RunOnce(std::function<void()> action, Requirements requirements) {
return InstantCommand(std::move(action), requirements).ToPtr();
}
CommandPtr cmd::Run(std::function<void()> action, Requirements requirements) {
CommandPtr Run(std::function<void()> action, Requirements requirements) {
return RunCommand(std::move(action), requirements).ToPtr();
}
CommandPtr cmd::StartEnd(std::function<void()> start, std::function<void()> end,
Requirements requirements) {
CommandPtr StartEnd(std::function<void()> start, std::function<void()> end,
Requirements requirements) {
return FunctionalCommand(
std::move(start), [] {},
[end = std::move(end)](bool interrupted) { end(); },
@@ -52,27 +51,27 @@ CommandPtr cmd::StartEnd(std::function<void()> start, std::function<void()> end,
.ToPtr();
}
CommandPtr cmd::RunEnd(std::function<void()> run, std::function<void()> end,
Requirements requirements) {
CommandPtr RunEnd(std::function<void()> run, std::function<void()> end,
Requirements requirements) {
return FunctionalCommand([] {}, std::move(run),
[end = std::move(end)](bool interrupted) { end(); },
[] { return false; }, requirements)
.ToPtr();
}
CommandPtr cmd::StartRun(std::function<void()> start, std::function<void()> run,
Requirements requirements) {
CommandPtr StartRun(std::function<void()> start, std::function<void()> run,
Requirements requirements) {
return FunctionalCommand(
std::move(start), std::move(run), [](bool interrupted) {},
[] { return false; }, requirements)
.ToPtr();
}
CommandPtr cmd::Print(std::string_view msg) {
CommandPtr Print(std::string_view msg) {
return PrintCommand(msg).ToPtr();
}
CommandPtr cmd::DeferredProxy(wpi::util::unique_function<Command*()> supplier) {
CommandPtr DeferredProxy(wpi::util::unique_function<Command*()> supplier) {
return Defer(
[supplier = std::move(supplier)]() mutable {
// There is no non-owning version of AsProxy(), so use the non-owning
@@ -82,55 +81,55 @@ CommandPtr cmd::DeferredProxy(wpi::util::unique_function<Command*()> supplier) {
{});
}
CommandPtr cmd::DeferredProxy(
wpi::util::unique_function<CommandPtr()> supplier) {
CommandPtr DeferredProxy(wpi::util::unique_function<CommandPtr()> supplier) {
return Defer([supplier = std::move(
supplier)]() mutable { return supplier().AsProxy(); },
{});
}
CommandPtr cmd::Wait(wpi::units::second_t duration) {
CommandPtr Wait(wpi::units::second_t duration) {
return WaitCommand(duration).ToPtr();
}
CommandPtr cmd::WaitUntil(std::function<bool()> condition) {
CommandPtr WaitUntil(std::function<bool()> condition) {
return WaitUntilCommand(condition).ToPtr();
}
CommandPtr cmd::Either(CommandPtr&& onTrue, CommandPtr&& onFalse,
std::function<bool()> selector) {
CommandPtr Either(CommandPtr&& onTrue, CommandPtr&& onFalse,
std::function<bool()> selector) {
return ConditionalCommand(std::move(onTrue).Unwrap(),
std::move(onFalse).Unwrap(), std::move(selector))
.ToPtr();
}
CommandPtr cmd::Defer(wpi::util::unique_function<CommandPtr()> supplier,
Requirements requirements) {
CommandPtr Defer(wpi::util::unique_function<CommandPtr()> supplier,
Requirements requirements) {
return DeferredCommand(std::move(supplier), requirements).ToPtr();
}
CommandPtr cmd::Sequence(std::vector<CommandPtr>&& commands) {
CommandPtr Sequence(std::vector<CommandPtr>&& commands) {
return SequentialCommandGroup(CommandPtr::UnwrapVector(std::move(commands)))
.ToPtr();
}
CommandPtr cmd::RepeatingSequence(std::vector<CommandPtr>&& commands) {
return Sequence(std::move(commands)).Repeatedly();
CommandPtr RepeatingSequence(std::vector<CommandPtr>&& commands) {
return wpi::cmd::Sequence(std::move(commands)).Repeatedly();
}
CommandPtr cmd::Parallel(std::vector<CommandPtr>&& commands) {
CommandPtr Parallel(std::vector<CommandPtr>&& commands) {
return ParallelCommandGroup(CommandPtr::UnwrapVector(std::move(commands)))
.ToPtr();
}
CommandPtr cmd::Race(std::vector<CommandPtr>&& commands) {
CommandPtr Race(std::vector<CommandPtr>&& commands) {
return ParallelRaceGroup(CommandPtr::UnwrapVector(std::move(commands)))
.ToPtr();
}
CommandPtr cmd::Deadline(CommandPtr&& deadline,
std::vector<CommandPtr>&& others) {
CommandPtr Deadline(CommandPtr&& deadline, std::vector<CommandPtr>&& others) {
return ParallelDeadlineGroup(std::move(deadline).Unwrap(),
CommandPtr::UnwrapVector(std::move(others)))
.ToPtr();
}
} // namespace wpi::cmd

View File

@@ -19,11 +19,6 @@
namespace wpi::cmd {
class Subsystem;
/**
* Namespace for command factories.
*/
namespace cmd {
/**
* Constructs a command that does nothing, finishing immediately.
*/
@@ -260,6 +255,4 @@ CommandPtr Deadline(CommandPtr&& deadline, CommandPtrs&&... commands) {
impl::MakeVector(std::forward<CommandPtrs>(commands)...));
}
} // namespace cmd
} // namespace wpi::cmd

View File

@@ -21,7 +21,7 @@ TEST_F(CommandDecoratorTest, WithTimeout) {
wpi::sim::PauseTiming();
auto command = cmd::Idle().WithTimeout(100_ms);
auto command = Idle().WithTimeout(100_ms);
scheduler.Schedule(command);
scheduler.Run();
@@ -42,7 +42,7 @@ TEST_F(CommandDecoratorTest, Until) {
bool finish = false;
auto command = cmd::Idle().Until([&finish] { return finish; });
auto command = Idle().Until([&finish] { return finish; });
scheduler.Schedule(command);
scheduler.Run();
@@ -85,7 +85,7 @@ TEST_F(CommandDecoratorTest, OnlyWhile) {
bool run = true;
auto command = cmd::Idle().OnlyWhile([&run] { return run; });
auto command = Idle().OnlyWhile([&run] { return run; });
scheduler.Schedule(command);
scheduler.Run();
@@ -126,7 +126,7 @@ TEST_F(CommandDecoratorTest, OnlyWhileOrder) {
TEST_F(CommandDecoratorTest, IgnoringDisable) {
CommandScheduler scheduler = GetScheduler();
auto command = cmd::Idle().IgnoringDisable(true);
auto command = Idle().IgnoringDisable(true);
SetDSEnabled(false);
@@ -141,7 +141,7 @@ TEST_F(CommandDecoratorTest, BeforeStarting) {
bool finished = false;
auto command = cmd::None().BeforeStarting([&finished] { finished = true; });
auto command = None().BeforeStarting([&finished] { finished = true; });
scheduler.Schedule(command);
@@ -161,7 +161,7 @@ TEST_F(CommandDecoratorTest, AndThenLambda) {
bool finished = false;
auto command = cmd::None().AndThen([&finished] { finished = true; });
auto command = None().AndThen([&finished] { finished = true; });
scheduler.Schedule(command);
@@ -181,8 +181,8 @@ TEST_F(CommandDecoratorTest, AndThen) {
bool finished = false;
auto command1 = cmd::None();
auto command2 = cmd::RunOnce([&finished] { finished = true; });
auto command1 = None();
auto command2 = RunOnce([&finished] { finished = true; });
auto group = std::move(command1).AndThen(std::move(command2));
scheduler.Schedule(group);
@@ -203,8 +203,8 @@ TEST_F(CommandDecoratorTest, DeadlineFor) {
bool finish = false;
auto dictator = cmd::WaitUntil([&finish] { return finish; });
auto endsAfter = cmd::Idle();
auto dictator = WaitUntil([&finish] { return finish; });
auto endsAfter = Idle();
auto group = std::move(dictator).DeadlineFor(std::move(endsAfter));
@@ -245,8 +245,8 @@ TEST_F(CommandDecoratorTest, AlongWith) {
bool finish = false;
auto command1 = cmd::WaitUntil([&finish] { return finish; });
auto command2 = cmd::None();
auto command1 = WaitUntil([&finish] { return finish; });
auto command2 = None();
auto group = std::move(command1).AlongWith(std::move(command2));
@@ -264,8 +264,8 @@ TEST_F(CommandDecoratorTest, AlongWith) {
TEST_F(CommandDecoratorTest, RaceWith) {
CommandScheduler scheduler = GetScheduler();
auto command1 = cmd::Idle();
auto command2 = cmd::None();
auto command1 = Idle();
auto command2 = None();
auto group = std::move(command1).RaceWith(std::move(command2));
@@ -288,7 +288,7 @@ TEST_F(CommandDecoratorTest, DeadlineForOrder) {
dictatorWasPolled = true;
return true;
});
auto other = cmd::Run([&dictatorHasRun, &dictatorWasPolled] {
auto other = wpi::cmd::Run([&dictatorHasRun, &dictatorWasPolled] {
EXPECT_TRUE(dictatorHasRun);
EXPECT_TRUE(dictatorWasPolled);
});
@@ -341,7 +341,7 @@ TEST_F(CommandDecoratorTest, AlongWithOrder) {
firstWasPolled = true;
return true;
});
auto command2 = cmd::Run([&firstHasRun, &firstWasPolled] {
auto command2 = wpi::cmd::Run([&firstHasRun, &firstWasPolled] {
EXPECT_TRUE(firstHasRun);
EXPECT_TRUE(firstWasPolled);
});
@@ -367,7 +367,7 @@ TEST_F(CommandDecoratorTest, RaceWithOrder) {
firstWasPolled = true;
return true;
});
auto command2 = cmd::Run([&firstHasRun, &firstWasPolled] {
auto command2 = wpi::cmd::Run([&firstHasRun, &firstWasPolled] {
EXPECT_TRUE(firstHasRun);
EXPECT_TRUE(firstWasPolled);
});
@@ -388,7 +388,7 @@ TEST_F(CommandDecoratorTest, Unless) {
bool unlessCondition = true;
auto command =
cmd::RunOnce([&hasRun] { hasRun = true; }, {}).Unless([&unlessCondition] {
RunOnce([&hasRun] { hasRun = true; }, {}).Unless([&unlessCondition] {
return unlessCondition;
});
@@ -409,7 +409,7 @@ TEST_F(CommandDecoratorTest, OnlyIf) {
bool onlyIfCondition = false;
auto command =
cmd::RunOnce([&hasRun] { hasRun = true; }, {}).OnlyIf([&onlyIfCondition] {
RunOnce([&hasRun] { hasRun = true; }, {}).OnlyIf([&onlyIfCondition] {
return onlyIfCondition;
});
@@ -483,7 +483,7 @@ TEST_F(CommandDecoratorTest, HandleInterrupt) {
}
TEST_F(CommandDecoratorTest, WithName) {
auto command = cmd::None();
auto command = None();
std::string name{"Named"};
auto named = std::move(command).WithName(name);
EXPECT_EQ(name, named.get()->GetName());

View File

@@ -19,7 +19,7 @@ TEST_F(CommandPtrTest, MovedFrom) {
int counter = 0;
CommandPtr movedFrom = cmd::Run([&counter] { counter++; });
CommandPtr movedFrom = wpi::cmd::Run([&counter] { counter++; });
CommandPtr movedTo = std::move(movedFrom);
EXPECT_NO_FATAL_FAILURE(scheduler.Schedule(movedTo));

View File

@@ -20,7 +20,7 @@ class CommandSendableButtonTest : public CommandTestBase {
void SetUp() override {
m_schedule = 0;
m_cancel = 0;
m_command = cmd::StartEnd([this] { m_schedule++; }, [this] { m_cancel++; });
m_command = StartEnd([this] { m_schedule++; }, [this] { m_cancel++; });
m_publish = wpi::nt::NetworkTableInstance::GetDefault()
.GetBooleanTopic("/SmartDashboard/command/running")
.Publish();

View File

@@ -57,72 +57,64 @@ TEST_F(ConditionalCommandTest, ConditionalCommandRequirement) {
}
TEST_F(ConditionalCommandTest, AllTrue) {
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(true),
cmd::Idle().IgnoringDisable(true), [] { return true; });
auto command = Either(Idle().IgnoringDisable(true),
Idle().IgnoringDisable(true), [] { return true; });
EXPECT_EQ(true, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, AllFalse) {
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(false),
cmd::Idle().IgnoringDisable(false), [] { return true; });
auto command = Either(Idle().IgnoringDisable(false),
Idle().IgnoringDisable(false), [] { return true; });
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, OneTrueOneFalse) {
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(true),
cmd::Idle().IgnoringDisable(false), [] { return true; });
auto command = Either(Idle().IgnoringDisable(true),
Idle().IgnoringDisable(false), [] { return true; });
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, TwoFalseOneTrue) {
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(false),
cmd::Idle().IgnoringDisable(true), [] { return true; });
auto command = Either(Idle().IgnoringDisable(false),
Idle().IgnoringDisable(true), [] { return true; });
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, AllCancelSelf) {
auto command = cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
[] { return true; });
auto command = Either(
Idle().WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
Idle().WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
[] { return true; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.get()->GetInterruptionBehavior());
}
TEST_F(ConditionalCommandTest, AllCancelIncoming) {
auto command =
cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
auto command = Either(Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelIncoming,
command.get()->GetInterruptionBehavior());
}
TEST_F(ConditionalCommandTest, OneCancelSelfOneIncoming) {
auto command =
cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
auto command = Either(
Idle().WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.get()->GetInterruptionBehavior());
}
TEST_F(ConditionalCommandTest, OneCancelIncomingOneSelf) {
auto command =
cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
[] { return false; });
auto command = Either(
Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
Idle().WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
[] { return false; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.get()->GetInterruptionBehavior());
}

View File

@@ -16,7 +16,7 @@ TEST_F(DefaultCommandTest, DefaultCommandSchedule) {
TestSubsystem subsystem;
auto command = cmd::Idle({&subsystem});
auto command = Idle({&subsystem});
scheduler.SetDefaultCommand(&subsystem, std::move(command));
auto handle = scheduler.GetDefaultCommand(&subsystem);
@@ -30,8 +30,8 @@ TEST_F(DefaultCommandTest, DefaultCommandInterruptResume) {
TestSubsystem subsystem;
auto command1 = cmd::Idle({&subsystem});
auto command2 = cmd::Idle({&subsystem});
auto command1 = Idle({&subsystem});
auto command2 = Idle({&subsystem});
scheduler.SetDefaultCommand(&subsystem, std::move(command1));
auto handle = scheduler.GetDefaultCommand(&subsystem);

View File

@@ -55,7 +55,7 @@ TEST(DeferredCommandTest, DeferredSupplierOnlyCalledDuringInit) {
int count = 0;
DeferredCommand command{[&count] {
count++;
return cmd::None();
return None();
},
{}};
@@ -70,7 +70,7 @@ TEST(DeferredCommandTest, DeferredSupplierOnlyCalledDuringInit) {
TEST(DeferredCommandTest, DeferredRequirements) {
TestSubsystem subsystem;
DeferredCommand command{cmd::None, {&subsystem}};
DeferredCommand command{None, {&subsystem}};
EXPECT_TRUE(command.GetRequirements().contains(&subsystem));
}

View File

@@ -15,7 +15,7 @@ TEST_F(InstantCommandTest, InstantCommandSchedule) {
int counter = 0;
auto command = cmd::RunOnce([&counter] { counter++; });
auto command = RunOnce([&counter] { counter++; });
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -79,7 +79,7 @@ TEST_F(ParallelCommandGroupTest, ParallelGroupInterrupt) {
TEST_F(ParallelCommandGroupTest, ParallelGroupNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
auto group = cmd::Parallel(cmd::None(), cmd::None());
auto group = Parallel(None(), None());
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(group));
}
@@ -89,9 +89,9 @@ TEST_F(ParallelCommandGroupTest, ParallelGroupCopy) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; });
auto command = WaitUntil([&finished] { return finished; });
auto group = cmd::Parallel(std::move(command));
auto group = Parallel(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(group));
@@ -108,11 +108,11 @@ TEST_F(ParallelCommandGroupTest, ParallelGroupRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
auto command1 = RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = RunOnce([] {}, {&requirement3});
auto command3 = RunOnce([] {}, {&requirement3, &requirement4});
auto group = cmd::Parallel(std::move(command1), std::move(command2));
auto group = Parallel(std::move(command1), std::move(command2));
scheduler.Schedule(group);
scheduler.Schedule(command3);

View File

@@ -96,7 +96,7 @@ TEST_F(ParallelDeadlineGroupTest, SequentialGroupInterrupt) {
TEST_F(ParallelDeadlineGroupTest, DeadlineGroupNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
auto group = cmd::Deadline(cmd::None(), cmd::None());
auto group = Deadline(None(), None());
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(group));
}
@@ -106,9 +106,9 @@ TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineCopy) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; });
auto command = WaitUntil([&finished] { return finished; });
auto group = cmd::Deadline(std::move(command));
auto group = Deadline(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(group));
@@ -125,11 +125,11 @@ TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
auto command1 = RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = RunOnce([] {}, {&requirement3});
auto command3 = RunOnce([] {}, {&requirement3, &requirement4});
auto group = cmd::Deadline(std::move(command1), std::move(command2));
auto group = Deadline(std::move(command1), std::move(command2));
scheduler.Schedule(group);
scheduler.Schedule(command3);

View File

@@ -91,7 +91,7 @@ TEST_F(ParallelRaceGroupTest, ParallelRaceInterrupt) {
TEST_F(ParallelRaceGroupTest, ParallelRaceNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
auto group = cmd::Race(cmd::None(), cmd::None());
auto group = Race(None(), None());
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(group));
}
@@ -101,9 +101,9 @@ TEST_F(ParallelRaceGroupTest, ParallelRaceCopy) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; });
auto command = WaitUntil([&finished] { return finished; });
auto group = cmd::Race(std::move(command));
auto group = Race(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(group));
@@ -120,11 +120,11 @@ TEST_F(ParallelRaceGroupTest, RaceGroupRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
auto command1 = RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = RunOnce([] {}, {&requirement3});
auto command3 = RunOnce([] {}, {&requirement3, &requirement4});
auto group = cmd::Race(std::move(command1), std::move(command2));
auto group = Race(std::move(command1), std::move(command2));
scheduler.Schedule(group);
scheduler.Schedule(command3);
@@ -140,12 +140,12 @@ TEST_F(ParallelRaceGroupTest, ParallelRaceOnlyCallsEndOnce) {
bool finished2 = false;
bool finished3 = false;
auto command1 = cmd::WaitUntil([&finished1] { return finished1; });
auto command2 = cmd::WaitUntil([&finished2] { return finished2; });
auto command3 = cmd::WaitUntil([&finished3] { return finished3; });
auto command1 = WaitUntil([&finished1] { return finished1; });
auto command2 = WaitUntil([&finished2] { return finished2; });
auto command3 = WaitUntil([&finished3] { return finished3; });
auto group1 = cmd::Sequence(std::move(command1), std::move(command2));
auto group2 = cmd::Race(std::move(group1), std::move(command3));
auto group1 = Sequence(std::move(command1), std::move(command2));
auto group2 = Race(std::move(group1), std::move(command3));
scheduler.Schedule(group2);
scheduler.Run();

View File

@@ -15,7 +15,7 @@ class PrintCommandTest : public CommandTestBase {};
TEST_F(PrintCommandTest, PrintCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
auto command = cmd::Print("Test!");
auto command = Print("Test!");
testing::internal::CaptureStdout();

View File

@@ -54,7 +54,7 @@ TEST_F(ProxyCommandTest, OwningCommandSchedule) {
bool scheduled = false;
auto command = cmd::RunOnce([&scheduled] { scheduled = true; }).AsProxy();
auto command = RunOnce([&scheduled] { scheduled = true; }).AsProxy();
scheduler.Schedule(command);
scheduler.Run();
@@ -67,7 +67,7 @@ TEST_F(ProxyCommandTest, OwningCommandEnd) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; }).AsProxy();
auto command = WaitUntil([&finished] { return finished; }).AsProxy();
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -15,7 +15,7 @@ TEST_F(RunCommandTest, RunCommandSchedule) {
int counter = 0;
auto command = cmd::Run([&counter] { counter++; });
auto command = wpi::cmd::Run([&counter] { counter++; });
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -16,7 +16,7 @@ class SchedulerTest : public CommandTestBase {};
TEST_F(SchedulerTest, SchedulerLambdaTestNoInterrupt) {
CommandScheduler scheduler = GetScheduler();
auto command = cmd::None();
auto command = None();
int counter = 0;
@@ -33,7 +33,7 @@ TEST_F(SchedulerTest, SchedulerLambdaTestNoInterrupt) {
TEST_F(SchedulerTest, SchedulerLambdaInterrupt) {
CommandScheduler scheduler = GetScheduler();
auto command = cmd::Idle();
auto command = Idle();
int counter = 0;
@@ -57,7 +57,7 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptNoCause) {
counter++;
});
auto command = cmd::Idle();
auto command = Idle();
scheduler.Schedule(command);
scheduler.Cancel(command);
@@ -71,7 +71,7 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptCause) {
int counter = 0;
TestSubsystem subsystem{};
auto command = cmd::Idle({&subsystem});
auto command = Idle({&subsystem});
InstantCommand interruptor([] {}, {&subsystem});
scheduler.OnCommandInterrupt(
@@ -93,11 +93,11 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptCauseInRunLoop) {
int counter = 0;
TestSubsystem subsystem{};
auto command = cmd::Idle({&subsystem});
auto command = Idle({&subsystem});
InstantCommand interruptor([] {}, {&subsystem});
// This command will schedule interruptor in execute() inside the run loop
auto interruptorScheduler =
cmd::RunOnce([&] { scheduler.Schedule(&interruptor); });
RunOnce([&] { scheduler.Schedule(&interruptor); });
scheduler.OnCommandInterrupt(
[&](const Command&, const std::optional<Command*>& cause) {
@@ -143,8 +143,8 @@ TEST_F(SchedulerTest, UnregisterSubsystem) {
TEST_F(SchedulerTest, SchedulerCancelAll) {
CommandScheduler scheduler = GetScheduler();
auto command1 = cmd::Idle();
auto command2 = cmd::Idle();
auto command1 = Idle();
auto command2 = Idle();
int counter = 0;
@@ -167,7 +167,7 @@ TEST_F(SchedulerTest, ScheduleScheduledNoOp) {
int counter = 0;
auto command = cmd::StartEnd([&counter] { counter++; }, [] {});
auto command = StartEnd([&counter] { counter++; }, [] {});
scheduler.Schedule(command);
scheduler.Schedule(command);
@@ -202,9 +202,7 @@ TEST_F(SchedulerTest, ScheduleCommandPtr) {
{
auto commandPtr =
TrackDestroyCommand([&destructionCounter] { destructionCounter++; })
.AlongWith(wpi::cmd::InstantCommand([&runCounter] {
runCounter++;
}).ToPtr())
.AlongWith(InstantCommand([&runCounter] { runCounter++; }).ToPtr())
.Until([&finish] { return finish; });
EXPECT_EQ(destructionCounter, 0) << "Composition should not delete command";

View File

@@ -56,7 +56,8 @@ TEST_P(SchedulingRecursionTest, CancelFromInitialize) {
TestSubsystem requirement;
SelfCancellingCommand selfCancels{&scheduler, counter, &requirement,
GetParam()};
auto other = cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
auto other =
wpi::cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
scheduler.Schedule(&selfCancels);
scheduler.Run();
@@ -79,7 +80,8 @@ TEST_F(SchedulingRecursionTest, CancelFromInitializeAction) {
[&counter](bool) { counter++; },
[] { return false; },
{&requirement}};
auto other = cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
auto other =
wpi::cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
scheduler.OnCommandInitialize([&scheduler, &selfCancels](const Command&) {
scheduler.Cancel(&selfCancels);
});
@@ -102,7 +104,8 @@ TEST_P(SchedulingRecursionTest,
TestSubsystem requirement;
SelfCancellingCommand selfCancels{&scheduler, counter, &requirement,
GetParam()};
auto other = cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
auto other =
wpi::cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
scheduler.SetDefaultCommand(&requirement, std::move(other));
scheduler.Schedule(&selfCancels);
@@ -285,7 +288,7 @@ TEST_P(SchedulingRecursionTest, ScheduleFromEndInterrupt) {
TestSubsystem requirement;
SelfCancellingCommand selfCancels{&scheduler, counter, &requirement,
GetParam()};
auto other = cmd::Idle({&requirement});
auto other = Idle({&requirement});
scheduler.Schedule(&selfCancels);
EXPECT_NO_THROW({ scheduler.Schedule(other); });
@@ -298,8 +301,8 @@ TEST_F(SchedulingRecursionTest, ScheduleFromEndInterruptAction) {
CommandScheduler scheduler = GetScheduler();
int counter = 0;
TestSubsystem requirement;
auto selfCancels = cmd::Idle({&requirement});
auto other = cmd::Idle({&requirement});
auto selfCancels = Idle({&requirement});
auto other = Idle({&requirement});
scheduler.OnCommandInterrupt([&](const Command&) {
counter++;
scheduler.Schedule(other);
@@ -320,7 +323,7 @@ TEST_F(SchedulingRecursionTest, CancelDefaultCommandFromEnd) {
[&counter](bool) { counter++; },
[] { return false; },
{&requirement}};
auto other = cmd::Idle({&requirement});
auto other = Idle({&requirement});
FunctionalCommand cancelDefaultCommand{[] {}, [] {},
[&](bool) {
counter++;
@@ -343,15 +346,15 @@ TEST_F(SchedulingRecursionTest, CancelDefaultCommandFromEnd) {
TEST_F(SchedulingRecursionTest, CancelNextCommandFromCommand) {
CommandScheduler scheduler = GetScheduler();
wpi::cmd::RunCommand* command1Ptr = nullptr;
wpi::cmd::RunCommand* command2Ptr = nullptr;
RunCommand* command1Ptr = nullptr;
RunCommand* command2Ptr = nullptr;
int counter = 0;
auto command1 = wpi::cmd::RunCommand([&counter, &command2Ptr, &scheduler] {
auto command1 = RunCommand([&counter, &command2Ptr, &scheduler] {
scheduler.Cancel(command2Ptr);
counter++;
});
auto command2 = wpi::cmd::RunCommand([&counter, &command1Ptr, &scheduler] {
auto command2 = RunCommand([&counter, &command1Ptr, &scheduler] {
scheduler.Cancel(command1Ptr);
counter++;
});

View File

@@ -49,13 +49,12 @@ TEST_F(SelectCommandTest, SelectCommandRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
auto command1 = RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = RunOnce([] {}, {&requirement3});
auto command3 = RunOnce([] {}, {&requirement3, &requirement4});
auto select =
cmd::Select<int>([] { return 1; }, std::pair(1, std::move(command1)),
std::pair(2, std::move(command2)));
auto select = Select<int>([] { return 1; }, std::pair(1, std::move(command1)),
std::pair(2, std::move(command2)));
scheduler.Schedule(select);
scheduler.Schedule(command3);

View File

@@ -106,9 +106,9 @@ TEST_F(SequentialCommandGroupTest, SequentialGroupCopy) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; });
auto command = WaitUntil([&finished] { return finished; });
auto group = cmd::Sequence(std::move(command));
auto group = Sequence(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(group));
@@ -125,11 +125,11 @@ TEST_F(SequentialCommandGroupTest, SequentialGroupRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
auto command1 = RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = RunOnce([] {}, {&requirement3});
auto command3 = RunOnce([] {}, {&requirement3, &requirement4});
auto group = cmd::Sequence(std::move(command1), std::move(command2));
auto group = Sequence(std::move(command1), std::move(command2));
scheduler.Schedule(group);
scheduler.Schedule(command3);

View File

@@ -15,8 +15,7 @@ TEST_F(StartEndCommandTest, StartEndCommandSchedule) {
int counter = 0;
auto command =
cmd::StartEnd([&counter] { counter++; }, [&counter] { counter++; });
auto command = StartEnd([&counter] { counter++; }, [&counter] { counter++; });
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -17,7 +17,7 @@ TEST_F(WaitCommandTest, WaitCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
auto command = cmd::Wait(100_ms);
auto command = wpi::cmd::Wait(100_ms);
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -15,7 +15,7 @@ TEST_F(WaitUntilCommandTest, WaitUntilCommandSchedule) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; });
auto command = WaitUntil([&finished] { return finished; });
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -109,7 +109,7 @@ TEST_F(TriggerTest, WhileTrueLambdaRun) {
auto& scheduler = CommandScheduler::GetInstance();
int counter = 0;
bool pressed = false;
CommandPtr command = cmd::Run([&counter] { counter++; });
CommandPtr command = wpi::cmd::Run([&counter] { counter++; });
pressed = false;
Trigger([&pressed] { return pressed; }).WhileTrue(std::move(command));
@@ -130,8 +130,8 @@ TEST_F(TriggerTest, WhenTrueOnce) {
int endCounter = 0;
bool pressed = false;
CommandPtr command = cmd::StartEnd([&startCounter] { startCounter++; },
[&endCounter] { endCounter++; });
CommandPtr command = StartEnd([&startCounter] { startCounter++; },
[&endCounter] { endCounter++; });
pressed = false;
Trigger([&pressed] { return pressed; }).WhileTrue(std::move(command));
@@ -154,8 +154,8 @@ TEST_F(TriggerTest, ToggleOnTrue) {
bool pressed = false;
int startCounter = 0;
int endCounter = 0;
CommandPtr command = cmd::StartEnd([&startCounter] { startCounter++; },
[&endCounter] { endCounter++; });
CommandPtr command = StartEnd([&startCounter] { startCounter++; },
[&endCounter] { endCounter++; });
Trigger([&pressed] { return pressed; }).ToggleOnTrue(std::move(command));
scheduler.Run();

View File

@@ -13,7 +13,7 @@ RobotContainer::RobotContainer() {
ConfigureButtonBindings();
// Set up default drive command
m_drive.SetDefaultCommand(wpi::cmd::cmd::Run(
m_drive.SetDefaultCommand(wpi::cmd::Run(
[this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
-m_driverController.GetRightX());
@@ -42,5 +42,5 @@ void RobotContainer::ConfigureButtonBindings() {
wpi::cmd::CommandPtr RobotContainer::GetAutonomousCommand() {
// Runs the chosen command in autonomous
return wpi::cmd::cmd::None();
return wpi::cmd::None();
}

View File

@@ -36,9 +36,9 @@ class RobotContainer {
// RobotContainer-owned commands
wpi::cmd::CommandPtr m_driveHalfVelocity =
wpi::cmd::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {});
wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {});
wpi::cmd::CommandPtr m_driveFullVelocity =
wpi::cmd::cmd::RunOnce([this] { m_drive.SetMaxOutput(1); }, {});
wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(1); }, {});
void ConfigureButtonBindings();
};

View File

@@ -24,7 +24,7 @@ RobotContainer::RobotContainer() {
ConfigureButtonBindings();
// Set up default drive command
m_drive.SetDefaultCommand(wpi::cmd::cmd::Run(
m_drive.SetDefaultCommand(wpi::cmd::Run(
[this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
-m_driverController.GetRightX());
@@ -41,9 +41,8 @@ void RobotContainer::ConfigureButtonBindings() {
m_driverController.WestFace().OnTrue(m_hatch.ReleaseHatchCommand());
// While holding Right Bumper, drive at half velocity
m_driverController.RightBumper()
.OnTrue(wpi::cmd::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {}))
.OnFalse(
wpi::cmd::cmd::RunOnce([this] { m_drive.SetMaxOutput(1.0); }, {}));
.OnTrue(wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {}))
.OnFalse(wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(1.0); }, {}));
}
wpi::cmd::Command* RobotContainer::GetAutonomousCommand() {

View File

@@ -33,7 +33,7 @@ wpi::cmd::CommandPtr autos::SimpleAuto(DriveSubsystem* drive) {
wpi::cmd::CommandPtr autos::ComplexAuto(DriveSubsystem* drive,
HatchSubsystem* hatch) {
return wpi::cmd::cmd::Sequence(
return wpi::cmd::Sequence(
// Drive forward the specified distance
wpi::cmd::FunctionalCommand(
// Reset encoders on command start

View File

@@ -31,7 +31,7 @@ void RapidReactCommandBot::ConfigureBindings() {
// Fire the shooter with the South Face button
m_driverController.SouthFace().OnTrue(
wpi::cmd::cmd::Parallel(
wpi::cmd::Parallel(
m_shooter.ShootCommand(ShooterConstants::kShooterTarget),
m_storage.RunCommand())
// Since we composed this inline we should give it a name

View File

@@ -21,7 +21,7 @@ Shooter::Shooter() {
wpi::cmd::CommandPtr Shooter::ShootCommand(
wpi::units::turns_per_second_t setpoint) {
return wpi::cmd::cmd::Parallel(
return wpi::cmd::Parallel(
// Run the shooter flywheel at the desired setpoint using
// feedforward and feedback
Run([this, setpoint] {
@@ -32,7 +32,7 @@ wpi::cmd::CommandPtr Shooter::ShootCommand(
}),
// Wait until the shooter has reached the setpoint, and then
// run the feeder
wpi::cmd::cmd::WaitUntil([this] {
wpi::cmd::WaitUntil([this] {
return m_shooterFeedback.AtSetpoint();
}).AndThen([this] { m_feederMotor.SetThrottle(1.0); }))
.WithName("Shoot");

View File

@@ -20,8 +20,8 @@ void RobotContainer::ConfigureButtonBindings() {
[this] { return -m_controller.GetRawAxis(2); }));
// Example of how to use the onboard IO
m_onboardButtonA.OnTrue(wpi::cmd::cmd::Print("Button A Pressed"))
.OnFalse(wpi::cmd::cmd::Print("Button A Released"));
m_onboardButtonA.OnTrue(wpi::cmd::Print("Button A Pressed"))
.OnFalse(wpi::cmd::Print("Button A Released"));
// Setup SmartDashboard options.
m_chooser.SetDefaultOption("Auto Routine Distance", &m_autoDistance);

View File

@@ -23,8 +23,8 @@ Drive::Drive() {
wpi::cmd::CommandPtr Drive::ArcadeDriveCommand(std::function<double()> fwd,
std::function<double()> rot) {
return wpi::cmd::cmd::Run(
[this, fwd, rot] { m_drive.ArcadeDrive(fwd(), rot()); }, {this})
return wpi::cmd::Run([this, fwd, rot] { m_drive.ArcadeDrive(fwd(), rot()); },
{this})
.WithName("Arcade Drive");
}

View File

@@ -15,7 +15,7 @@ Shooter::Shooter() {
wpi::cmd::CommandPtr Shooter::RunShooterCommand(
std::function<double()> shooterVelocity) {
return wpi::cmd::cmd::Run(
return wpi::cmd::Run(
[this, shooterVelocity] {
m_shooterMotor.SetVoltage(
wpi::units::volt_t{m_shooterFeedback.Calculate(

View File

@@ -21,16 +21,16 @@ void RobotContainer::ConfigureButtonBindings() {
[this] { return -m_controller.GetRawAxis(2); }));
// Example of how to use the onboard IO
m_userButton.OnTrue(wpi::cmd::cmd::Print("USER Button Pressed"))
.OnFalse(wpi::cmd::cmd::Print("USER Button Released"));
m_userButton.OnTrue(wpi::cmd::Print("USER Button Pressed"))
.OnFalse(wpi::cmd::Print("USER Button Released"));
wpi::cmd::JoystickButton(&m_controller, 1)
.OnTrue(wpi::cmd::cmd::RunOnce([this] { m_arm.SetAngle(45_deg); }, {}))
.OnFalse(wpi::cmd::cmd::RunOnce([this] { m_arm.SetAngle(0_deg); }, {}));
.OnTrue(wpi::cmd::RunOnce([this] { m_arm.SetAngle(45_deg); }, {}))
.OnFalse(wpi::cmd::RunOnce([this] { m_arm.SetAngle(0_deg); }, {}));
wpi::cmd::JoystickButton(&m_controller, 2)
.OnTrue(wpi::cmd::cmd::RunOnce([this] { m_arm.SetAngle(90_deg); }, {}))
.OnFalse(wpi::cmd::cmd::RunOnce([this] { m_arm.SetAngle(0_deg); }, {}));
.OnTrue(wpi::cmd::RunOnce([this] { m_arm.SetAngle(90_deg); }, {}))
.OnFalse(wpi::cmd::RunOnce([this] { m_arm.SetAngle(0_deg); }, {}));
// Setup SmartDashboard options.
m_chooser.SetDefaultOption("Auto Routine Distance", &m_autoDistance);

View File

@@ -36,13 +36,12 @@ class RobotContainer {
// takes a generic type, so the selector does not have to be an enum; it could
// be any desired type (string, integer, boolean, double...)
wpi::cmd::CommandPtr m_exampleSelectCommand =
wpi::cmd::cmd::Select<CommandSelector>(
wpi::cmd::Select<CommandSelector>(
[this] { return m_chooser.GetSelected(); },
// Maps selector values to commands
std::pair{ONE, wpi::cmd::cmd::Print("Command one was selected!")},
std::pair{TWO, wpi::cmd::cmd::Print("Command two was selected!")},
std::pair{THREE,
wpi::cmd::cmd::Print("Command three was selected!")});
std::pair{ONE, wpi::cmd::Print("Command one was selected!")},
std::pair{TWO, wpi::cmd::Print("Command two was selected!")},
std::pair{THREE, wpi::cmd::Print("Command three was selected!")});
void ConfigureButtonBindings();
};

View File

@@ -8,6 +8,6 @@
#include "wpi/commands2/Commands.hpp"
wpi::cmd::CommandPtr autos::ExampleAuto(ExampleSubsystem* subsystem) {
return wpi::cmd::cmd::Sequence(subsystem->ExampleMethodCommand(),
ExampleCommand(subsystem).ToPtr());
return wpi::cmd::Sequence(subsystem->ExampleMethodCommand(),
ExampleCommand(subsystem).ToPtr());
}

View File

@@ -13,5 +13,5 @@ RobotContainer::RobotContainer() {
void RobotContainer::ConfigureBindings() {}
wpi::cmd::CommandPtr RobotContainer::GetAutonomousCommand() {
return wpi::cmd::cmd::Print("No autonomous command configured");
return wpi::cmd::Print("No autonomous command configured");
}