RIT VEXU Core API
Toggle main menu visibility
Loading...
Searching...
No Matches
auto_command.h
1
6
7
#pragma once
8
9
#include <atomic>
10
#include <functional>
11
#include <queue>
12
#include <vector>
13
14
#include "vex/vex.h"
15
25
class
Condition
{
26
public
:
27
Condition
* Or(
Condition
* b);
28
Condition
* And(
Condition
* b);
29
virtual
bool
test() = 0;
30
virtual
std::string toString();
31
};
32
33
class
OrCondition :
public
Condition
{
34
public
:
35
OrCondition(
Condition
* A,
Condition
* B);
36
bool
test()
override
;
37
38
private
:
39
Condition
* A;
40
Condition
* B;
41
};
42
43
class
AndCondition :
public
Condition
{
44
public
:
45
AndCondition(Condition* A, Condition* B);
46
bool
test()
override
;
47
48
private
:
49
Condition* A;
50
Condition* B;
51
};
52
53
class
AutoCommand {
54
public
:
55
static
constexpr
double
default_timeout = 10.0;
61
virtual
bool
run();
62
63
virtual
std::string toString();
64
67
virtual
void
on_timeout();
68
AutoCommand* withTimeout(
double
t_seconds);
69
AutoCommand* withCancelCondition(Condition* true_to_end);
81
double
timeout_seconds = default_timeout;
82
Condition* true_to_end =
nullptr
;
83
84
virtual
~AutoCommand() =
default
;
85
};
86
91
class
FunctionCommand :
public
AutoCommand {
92
public
:
93
FunctionCommand(std::function<
bool
(
void
)> f);
94
bool
run()
override
;
95
std::string toString()
override
;
96
97
private
:
98
std::function<bool(
void
)> f;
99
};
100
/*
101
* Times tested 3
102
* Test 1 -> false
103
* Test 2 -> false
104
* Test 3 -> true
105
* Returns false until the Nth time that it is called
106
* This is pretty much only good for implementing RepeatUntil
107
*/
108
class
TimesTestedCondition :
public
Condition
{
109
public
:
110
TimesTestedCondition(
size_t
N);
111
bool
test()
override
;
112
113
private
:
114
size_t
count = 0;
115
size_t
max;
116
};
117
120
class
FunctionCondition :
public
Condition
{
121
public
:
122
FunctionCondition(std::function<
bool
()> cond, std::function<
void
(
void
)> timeout = []() {});
123
bool
test()
override
;
124
125
private
:
126
std::function<bool()> cond;
127
std::function<void(
void
)> timeout;
128
};
129
134
class
IfTimePassed :
public
Condition
{
135
public
:
136
IfTimePassed(
double
time_s);
137
bool
test()
override
;
138
139
private
:
140
double
time_s;
141
vex::timer tmr;
142
};
143
145
class
WaitUntilCondition :
public
AutoCommand {
146
public
:
147
WaitUntilCondition(
Condition
* cond);
148
bool
run()
override
;
149
std::string toString()
override
;
150
151
private
:
152
Condition
* cond;
153
};
154
159
class
InOrder :
public
AutoCommand {
160
public
:
161
InOrder(
const
InOrder& other) =
default
;
162
InOrder(std::queue<AutoCommand*> cmds);
163
InOrder(std::initializer_list<AutoCommand*> cmds);
164
bool
run()
override
;
165
void
on_timeout()
override
;
166
std::string toString()
override
;
167
168
private
:
169
AutoCommand* current_command =
nullptr
;
170
std::queue<AutoCommand*> cmds;
171
vex::timer tmr;
172
};
173
179
class
Parallel :
public
AutoCommand {
180
public
:
181
Parallel(std::initializer_list<AutoCommand*> cmds);
182
bool
run()
override
;
183
void
on_timeout()
override
;
184
std::string toString()
override
;
185
186
private
:
187
std::vector<AutoCommand*> cmds;
188
std::vector<vex::task*> runners;
189
};
190
196
class
Branch :
public
AutoCommand {
197
public
:
198
Branch(
Condition
* cond, AutoCommand* false_choice, AutoCommand* true_choice);
199
~Branch();
200
bool
run()
override
;
201
std::string toString()
override
;
202
void
on_timeout()
override
;
203
204
private
:
205
AutoCommand* false_choice;
206
AutoCommand* true_choice;
207
Condition
* cond;
208
bool
choice =
false
;
209
bool
chosen =
false
;
210
vex::timer tmr;
211
};
212
218
class
Async :
public
AutoCommand {
219
public
:
220
Async(AutoCommand* cmd);
221
bool
run()
override
;
222
std::string toString()
override
;
223
224
private
:
225
AutoCommand* cmd =
nullptr
;
226
};
227
228
class
RepeatUntil :
public
AutoCommand {
229
public
:
235
RepeatUntil(
InOrder
cmds,
size_t
repeats);
241
RepeatUntil(
InOrder
cmds,
Condition
* true_to_end);
242
bool
run()
override
;
243
std::string toString()
override
;
244
void
on_timeout()
override
;
245
246
private
:
247
const
InOrder
cmds;
248
InOrder
* working_cmds;
249
Condition
* cond;
250
};
Condition
Definition
auto_command.h:25
InOrder
InOrder runs its commands sequentially then continues. How to handle timeout in this case....
Definition
auto_command.h:159
include
core
competition
command_structure
auto_command.h
Generated by
1.18.0