@@ -100,13 +100,6 @@ def __init__(self) -> None:
100
100
self ._interruptActions : List [Callable [[Command , Optional [Command ]], None ]] = []
101
101
self ._finishActions : List [Callable [[Command ], None ]] = []
102
102
103
- self ._inRunLoop = False
104
- self ._toSchedule : Dict [Command , None ] = {}
105
- # python: toCancelInterruptors stored in _toCancel dict
106
- self ._toCancel : Dict [Command , Optional [Command ]] = {}
107
- # self._toCancelInterruptors: List[Optional[Command]] = []
108
- self ._endingCommands : Set [Command ] = set ()
109
-
110
103
self ._watchdog = Watchdog (TimedRobot .kDefaultPeriod , lambda : None )
111
104
112
105
hal .report (
@@ -187,10 +180,6 @@ def _schedule(self, command: Optional[Command]) -> None:
187
180
reportWarning ("Tried to schedule a null command!" , True )
188
181
return
189
182
190
- if self ._inRunLoop :
191
- self ._toSchedule [command ] = None
192
- return
193
-
194
183
self .requireNotComposed (command )
195
184
196
185
# Do nothing if the scheduler is disabled, the robot is disabled and the command
@@ -259,11 +248,15 @@ def run(self) -> None:
259
248
loopCache .poll ()
260
249
self ._watchdog .addEpoch ("buttons.run()" )
261
250
262
- self ._inRunLoop = True
263
251
isDisabled = RobotState .isDisabled ()
264
252
265
253
# Run scheduled commands, remove finished commands.
266
254
for command in self ._scheduledCommands .copy ():
255
+ if not self .isScheduled (command ):
256
+ # skip as the normal scheduledCommands was modified
257
+ # and that command was canceled
258
+ continue
259
+
267
260
if isDisabled and not command .runsWhenDisabled ():
268
261
self ._cancel (command , None )
269
262
continue
@@ -273,28 +266,14 @@ def run(self) -> None:
273
266
action (command )
274
267
self ._watchdog .addEpoch (f"{ command .getName ()} .execute()" )
275
268
if command .isFinished ():
276
- self ._endingCommands . add (command )
269
+ self ._scheduledCommands . pop (command )
277
270
command .end (False )
278
271
for action in self ._finishActions :
279
272
action (command )
280
- self ._endingCommands .remove (command )
281
- self ._scheduledCommands .pop (command )
282
273
for requirement in command .getRequirements ():
283
274
self ._requirements .pop (requirement )
284
275
self ._watchdog .addEpoch (f"{ command .getName ()} .end(False)" )
285
276
286
- self ._inRunLoop = False
287
-
288
- # Schedule/cancel commands from queues populated during loop
289
- for command in self ._toSchedule :
290
- self ._schedule (command )
291
-
292
- for command , interruptor in self ._toCancel .items ():
293
- self ._cancel (command , interruptor )
294
-
295
- self ._toSchedule .clear ()
296
- self ._toCancel .clear ()
297
-
298
277
# Add default commands for un-required registered subsystems.
299
278
for subsystem , scommand in self ._subsystems .items ():
300
279
if subsystem not in self ._requirements and scommand is not None :
@@ -425,23 +404,14 @@ def _cancel(self, command: Command, interruptor: Optional[Command]):
425
404
reportWarning ("Tried to cancel a null command" , True )
426
405
return
427
406
428
- if command in self ._endingCommands :
429
- return
430
-
431
- if self ._inRunLoop :
432
- self ._toCancel [command ] = interruptor
433
- return
434
-
435
407
if not self .isScheduled (command ):
436
408
return
437
409
438
- self ._endingCommands . add (command )
410
+ self ._scheduledCommands . pop (command )
439
411
command .end (True )
440
412
for action in self ._interruptActions :
441
413
action (command , interruptor )
442
414
443
- self ._endingCommands .remove (command )
444
- self ._scheduledCommands .pop (command )
445
415
for requirement in command .getRequirements ():
446
416
del self ._requirements [requirement ]
447
417
self ._watchdog .addEpoch (f"{ command .getName ()} .end(true)" )
0 commit comments