-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
408 lines (344 loc) · 10.5 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# pylint: disable=invalid-name
from ydl import header
class YDL_TARGETS():
SHEPHERD = "ydl_target_shepherd"
UI = "ydl_target_ui"
SENSORS = "ydl_target_sensors"
class SHEPHERD_HEADER():
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "button_press")
def BUTTON_PRESS(id):
"""
source: sensors. Notifies that a button has been pressed
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "turn_light_ui")
def TURN_LIGHT_FROM_UI(num, type, on):
"""
source: UI. Asks shepherd to turn a light on or off
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "get_match_info")
def GET_MATCH_INFO():
"""
source: UI. Asks Shepherd what match info is currently cached.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "set_match_number")
def SET_MATCH_NUMBER(match_num):
"""
source: UI. Sets the match number. Shepherd then fetches
information for that match and sends it to the UI.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "set_teams_info")
def SET_TEAMS_INFO(teams):
"""
teams = 4*{team_name, team_num, robot_ip, [starting_position]}
source: Sheet. Sets the match info, which has been fetched from a spreadsheet
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "send_scores")
def SEND_SCORES(scores):
"""
scores = [blue, gold]
source: Sheet.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "setup_match")
def SETUP_MATCH(match_num, teams):
"""
sets up the match given all the match info
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "reset_match")
def RESET_MATCH():
"""
source: UI. Resets the match, moving back to setup.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "get_scores")
def GET_SCORES():
"""
source: UI. Asks Shepherd what the current scores are.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "set_scores")
def SET_SCORES(blue_score=None, gold_score=None):
"""
source: UI. adjusts the current scores to the input scores.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "get_state")
def GET_STATE():
"""
source: UI. Asks Shepherd what the current game state is.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "set_state")
def SET_STATE(state):
"""
source: UI. Sets the game state.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "start_next_stage")
def START_NEXT_STAGE():
"""
starts the next stage
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "reset_current_stage")
def RESET_CURRENT_STAGE():
"""
resets the current stage
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "stage_timer_end")
def STAGE_TIMER_END():
"""
source: Timer. Sent when a stage timer has ended.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "get_connection_status")
def GET_CONNECTION_STATUS():
"""
source: UI. Asks Shepherd to send robot connection statuses to UI.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "set_robot_ip")
def SET_ROBOT_IP(ind, robot_ip):
"""
source: UI. Attempts to connect team to robot with given ip.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "disconnect_robot")
def DISCONNECT_ROBOT(ind):
"""
source: UI. Takes in index and disconnects their robot.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "robot_off")
def ROBOT_OFF(ind):
"""
source: UI. Takes in index and disables their robot.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "robot_on")
def ROBOT_ON(ind):
"""
source: UI. Takes in index and enables their robot.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "sound_blizzard_warning")
def SOUND_BLIZZARD_WARNING():
"""
source: Timer. Plays the blizzard warning sound.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "pause_timer")
def PAUSE_TIMER():
"""
source: UI. Pauses GAME_TIMER in Shepherd; used in the event that the game
needs to be paused and continued from the state it was paused at.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "resume_timer")
def RESUME_TIMER():
"""
source: UI. Resume GAME_TIMER in Shepherd; used to resume the game after it has
been paused using PAUSE_TIMERS.
"""
@staticmethod
@header(YDL_TARGETS.SHEPHERD, "start_whackamole")
def START_WHACKAMOLE():
"""
Starts a new game of whackamole
"""
class UI_HEADER():
"""
These are headers used by Shepherd to send information to the Staff UI.
"""
@staticmethod
@header(YDL_TARGETS.UI, "all_info")
def ALL_INFO():
"""
used for match recovery
"""
@staticmethod
@header(YDL_TARGETS.UI, "teams_info")
def TEAMS_INFO(match_num, teams):
"""
info about teams
"""
@staticmethod
@header(YDL_TARGETS.UI, "scores")
def SCORES(blue_score: int, gold_score: int):
"""
score for each alliance
"""
@staticmethod
@header(YDL_TARGETS.UI, "robot_connection")
def ROBOT_CONNECTION(ind: int, connected: bool, robot_ip: str):
"""
source: runtimeclient. robot connection
"""
@staticmethod
@header(YDL_TARGETS.UI, "runtime_status")
def RUNTIME_STATUS(ind: int, shep_connected: bool, dawn_connected: bool, \
mode, battery: float, version: str):
"""
source: runtimeclient. runtime status
"""
@staticmethod
@header(YDL_TARGETS.UI, "state")
def STATE(state, start_time=None, state_time=None):
"""
tells UI that Shepherd is now in this state
TODO: is this redundant with teams_info?
"""
@staticmethod
@header(YDL_TARGETS.UI, "reset_timers")
def RESET_TIMERS():
"""
reset all timers. (not used anymore)
"""
@staticmethod
@header(YDL_TARGETS.UI, "pause_timer")
def PAUSE_TIMER():
"""
source: Shepherd. Pauses the game timer in scoreboard by clearing the timeout created in runStageTimer;
Used in the event that the game
needs to be paused and continued from the state it was paused at.
"""
@staticmethod
@header(YDL_TARGETS.UI, "resume_timer")
def RESUME_TIMER(end_time, pause_end):
"""
source: Shepherd. Resumes the game timer in scoreboard by setting a new timeout
Used to resume the game after it has
been paused using PAUSE_TIMERS.
"""
@staticmethod
@header(YDL_TARGETS.UI, "scores_for_icons")
def SCORES_FOR_ICONS(blue_score, gold_score):
"""
source: Sheet. Used to update the number score per team as well as
update the icons such as the pioneers/campsites on the scoreboard UI
"""
@staticmethod
@header(YDL_TARGETS.UI, "invalid_write_match")
def INVALID_WRITE_MATCH(match_num, reason=0):
"""
source: Sheet. Used to send an alert message to UI saying why
the request to write to the spreadsheet was invalid.
If reason=1, we don't allow negative numbers because reading/writing -1 from
google sheets gives us a str instead of an int which complicates code
"""
@staticmethod
@header(YDL_TARGETS.UI, "update_player_score")
def UPDATE_PLAYER_SCORE(score):
"""
Updates and displays the current player's whackamole score
on whackamole.html. This should update every instance a
light is turned on.
"""
@staticmethod
@header(YDL_TARGETS.UI, "game_over")
def GAME_OVER():
"""
Tells user that they have lost in the game of whackamole.
"""
class SENSOR_HEADER():
"""
Headers used for Shepherd to send messages to the Sensor Interface.
"""
# @header(YDL_TARGETS.SENSORS, "example_header")
# def EXAMPLE_HEADER():
# """
# example header doc string
# """
@staticmethod
@header(YDL_TARGETS.SENSORS, "turn_on_button_light")
def TURN_ON_BUTTON_LIGHT(id: int):
"""
example header doc string
"""
@staticmethod
@header(YDL_TARGETS.SENSORS, "turn_off_button_light")
def TURN_OFF_BUTTON_LIGHT(id: int):
"""
example header doc string
"""
@staticmethod
@header(YDL_TARGETS.SENSORS, "turn_on_midline")
def TURN_ON_MIDLINE(id: int):
"""
example header doc string
"""
@staticmethod
@header(YDL_TARGETS.SENSORS, "turn_off_midline")
def TURN_OFF_MIDLINE(id: int):
"""
example header doc string
"""
@staticmethod
@header(YDL_TARGETS.SENSORS, "turn_on_lasers")
def TURN_ON_LASERS():
"""
example header doc string
"""
@staticmethod
@header(YDL_TARGETS.SENSORS, "turn_off_lasers")
def TURN_OFF_LASERS():
"""
example header doc string
"""
# A dictionary of pages -> whether page is password protected
# password.html should not be included in this list, since
# server.py will just route to that automatically
# add additional pages here
UI_PAGES = {
"scoreboard.html": False,
"score_adjustment.html": True,
"staff_gui.html": True,
"match_recovery.html": True,
"ref_gui.html": True,
"match_creator.html": True,
"alliance_selection.html": True,
"bracket_ui.html": False,
"whackamole.html": False,
}
class CONSTANTS():
BLIZZARD_WARNING_TIME = 170
CSV_FILE_NAME = "sheets/Shepherd Evergreen Database - Match Database.csv"
SPREADSHEET_ID = "11pJgMl_AXHWyu3QFoM6Rc_-5GkNmOx1UR0HYF1o8KwI"
UI_PASSWORD_HASH = "44590c963be2a79f52c07f7a7572b3907bf5bb180d993bd31aab510d29bbfbd3"
class ALLIANCE_COLOR():
GOLD = "gold"
BLUE = "blue"
class INDICES():
BLUE_1 = 0
BLUE_2 = 1
GOLD_1 = 2
GOLD_2 = 3
class STATE():
SETUP = "setup"
AUTO = "auto"
TELEOP_1 = "teleop_1"
BLIZZARD = "blizzard"
TELEOP_2 = "teleop_2"
ENDGAME = "endgame"
END = "end"
STAGE_TIMES = {
STATE.AUTO: 30,
STATE.TELEOP_1: 180,
STATE.BLIZZARD: 15,
STATE.TELEOP_2: 45,
STATE.ENDGAME: 60
}
class PROTOBUF_TYPES():
RUN_MODE = 0
START_POS = 1
LOG = 2 # text proto
DEVICE_DATA = 3
GAME_STATE = 4