[commands] Add unless() decorator (#4244)

This commit is contained in:
ohowe
2022-05-24 10:22:19 -06:00
committed by GitHub
parent ef3714223b
commit b193b318c1
5 changed files with 77 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
#include "frc2/command/Command.h"
#include "frc2/command/CommandScheduler.h"
#include "frc2/command/ConditionalCommand.h"
#include "frc2/command/EndlessCommand.h"
#include "frc2/command/InstantCommand.h"
#include "frc2/command/ParallelCommandGroup.h"
@@ -101,6 +102,12 @@ ProxyScheduleCommand Command::AsProxy() {
return ProxyScheduleCommand(this);
}
ConditionalCommand Command::Unless(std::function<bool()> condition) && {
return ConditionalCommand(std::make_unique<InstantCommand>(),
std::move(*this).TransferOwnership(),
std::move(condition));
}
void Command::Schedule(bool interruptible) {
CommandScheduler::GetInstance().Schedule(interruptible, this);
}