9#include "core/utils/formatting.h"
29 virtual bool test() = 0;
30 virtual std::string toString();
35 static constexpr double default_timeout = 10.0;
41 virtual bool run() {
return true; }
43 virtual std::string toString() {
return "AutoCommand"; }
47 virtual void on_timeout() {}
48 AutoCommand *withTimeout(
double t_seconds) {
49 if (this->timeout_seconds < 0) {
53 this->timeout_seconds = t_seconds;
56 AutoCommand *withCancelCondition(Condition *true_to_end) {
57 this->true_to_end = true_to_end;
69 double timeout_seconds = default_timeout;
70 Condition *true_to_end =
nullptr;
77class FunctionCommand :
public AutoCommand {
79 FunctionCommand(std::function<
bool(
void)> f) : f(f) {}
80 bool run() {
return f(); }
81 std::string toString()
override {
return "Function Command"; }
84 std::function<bool(
void)> f;
93class TimesTestedCondition :
public Condition {
95 TimesTestedCondition(
size_t N) : max(N) {}
96 bool test()
override {
113 std::function<
bool()> cond, std::function<
void(
void)> timeout = []() {}
115 : cond(cond), timeout(timeout) {}
116 bool test()
override;
119 std::function<bool()> cond;
120 std::function<void(
void)> timeout;
127 IfTimePassed(
double time_s);
128 bool test()
override;
136class WaitUntilCondition :
public AutoCommand {
138 WaitUntilCondition(
Condition *cond) : cond(cond) {}
139 bool run()
override {
return cond->test(); }
140 std::string toString()
override {
return "waiting until " + cond->toString(); }
151class InOrder :
public AutoCommand {
153 InOrder(
const InOrder &other) =
default;
154 InOrder(std::queue<AutoCommand *> cmds);
155 InOrder(std::initializer_list<AutoCommand *> cmds);
157 void on_timeout()
override;
158 std::string toString()
override;
161 AutoCommand *current_command =
nullptr;
162 std::queue<AutoCommand *> cmds;
168class Parallel :
public AutoCommand {
170 Parallel(std::initializer_list<AutoCommand *> cmds);
172 void on_timeout()
override;
173 std::string toString()
override;
176 std::vector<AutoCommand *> cmds;
177 std::vector<vex::task *> runners;
183class Branch :
public AutoCommand {
185 Branch(
Condition *cond, AutoCommand *false_choice, AutoCommand *true_choice);
188 std::string toString()
override;
189 void on_timeout()
override;
192 AutoCommand *false_choice;
193 AutoCommand *true_choice;
203class Async :
public AutoCommand {
205 Async(AutoCommand *cmd) : cmd(cmd) {}
207 std::string toString()
override;
210 AutoCommand *cmd =
nullptr;
213class RepeatUntil :
public AutoCommand {
218 RepeatUntil(
InOrder cmds,
size_t repeats);
224 std::string toString()
override;
225 void on_timeout()
override;
Definition auto_command.h:25
InOrder runs its commands sequentially then continues. How to handle timeout in this case....
Definition auto_command.h:151