mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add requirements param to more Command APIs (#2059)
Assorted improvements to the ergonomics of declaring requirements in the new command framework. C++ requirements list parameters have been defaulted to an empty list, some missing C++ requirements list parameters have been added, and both C++ and Java have been given requirements list params in various InstantCommand wrapper methods (#2049), whose value is forwarded to the command.
This commit is contained in:
@@ -48,19 +48,21 @@ ParallelRaceGroup Command::WithInterrupt(std::function<bool()> condition) && {
|
||||
return ParallelRaceGroup(std::move(temp));
|
||||
}
|
||||
|
||||
SequentialCommandGroup Command::BeforeStarting(std::function<void()> toRun) && {
|
||||
SequentialCommandGroup Command::BeforeStarting(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) && {
|
||||
std::vector<std::unique_ptr<Command>> temp;
|
||||
temp.emplace_back(std::make_unique<InstantCommand>(
|
||||
std::move(toRun), std::initializer_list<Subsystem*>{}));
|
||||
std::move(toRun), requirements));
|
||||
temp.emplace_back(std::move(*this).TransferOwnership());
|
||||
return SequentialCommandGroup(std::move(temp));
|
||||
}
|
||||
|
||||
SequentialCommandGroup Command::AndThen(std::function<void()> toRun) && {
|
||||
SequentialCommandGroup Command::AndThen(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) && {
|
||||
std::vector<std::unique_ptr<Command>> temp;
|
||||
temp.emplace_back(std::move(*this).TransferOwnership());
|
||||
temp.emplace_back(std::make_unique<InstantCommand>(
|
||||
std::move(toRun), std::initializer_list<Subsystem*>{}));
|
||||
std::move(toRun), requirements));
|
||||
return SequentialCommandGroup(std::move(temp));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,14 @@ using namespace frc2;
|
||||
FunctionalCommand::FunctionalCommand(std::function<void()> onInit,
|
||||
std::function<void()> onExecute,
|
||||
std::function<void(bool)> onEnd,
|
||||
std::function<bool()> isFinished)
|
||||
std::function<bool()> isFinished,
|
||||
std::initializer_list<Subsystem*> requirements)
|
||||
: m_onInit{std::move(onInit)},
|
||||
m_onExecute{std::move(onExecute)},
|
||||
m_onEnd{std::move(onEnd)},
|
||||
m_isFinished{std::move(isFinished)} {}
|
||||
m_isFinished{std::move(isFinished)} {
|
||||
AddRequirements(requirements);
|
||||
}
|
||||
|
||||
void FunctionalCommand::Initialize() { m_onInit(); }
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@ Button Button::WhenPressed(Command* command, bool interruptible) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhenPressed(std::function<void()> toRun) {
|
||||
WhenActive(std::move(toRun));
|
||||
Button Button::WhenPressed(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
WhenActive(std::move(toRun), requirements);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -26,8 +27,9 @@ Button Button::WhileHeld(Command* command, bool interruptible) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhileHeld(std::function<void()> toRun) {
|
||||
WhileActiveContinous(std::move(toRun));
|
||||
Button Button::WhileHeld(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
WhileActiveContinous(std::move(toRun), requirements);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -41,8 +43,9 @@ Button Button::WhenReleased(Command* command, bool interruptible) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhenReleased(std::function<void()> toRun) {
|
||||
WhenInactive(std::move(toRun));
|
||||
Button Button::WhenReleased(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
WhenInactive(std::move(toRun), requirements);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,9 @@ Trigger Trigger::WhenActive(Command* command, bool interruptible) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Trigger Trigger::WhenActive(std::function<void()> toRun) {
|
||||
return WhenActive(InstantCommand(std::move(toRun), {}));
|
||||
Trigger Trigger::WhenActive(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
return WhenActive(InstantCommand(std::move(toRun), requirements));
|
||||
}
|
||||
|
||||
Trigger Trigger::WhileActiveContinous(Command* command, bool interruptible) {
|
||||
@@ -48,8 +49,9 @@ Trigger Trigger::WhileActiveContinous(Command* command, bool interruptible) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Trigger Trigger::WhileActiveContinous(std::function<void()> toRun) {
|
||||
return WhileActiveContinous(InstantCommand(std::move(toRun), {}));
|
||||
Trigger Trigger::WhileActiveContinous(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
return WhileActiveContinous(InstantCommand(std::move(toRun), requirements));
|
||||
}
|
||||
|
||||
Trigger Trigger::WhileActiveOnce(Command* command, bool interruptible) {
|
||||
@@ -82,8 +84,9 @@ Trigger Trigger::WhenInactive(Command* command, bool interruptible) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Trigger Trigger::WhenInactive(std::function<void()> toRun) {
|
||||
return WhenInactive(InstantCommand(std::move(toRun), {}));
|
||||
Trigger Trigger::WhenInactive(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
return WhenInactive(InstantCommand(std::move(toRun), requirements));
|
||||
}
|
||||
|
||||
Trigger Trigger::ToggleWhenActive(Command* command, bool interruptible) {
|
||||
|
||||
Reference in New Issue
Block a user