mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user