Skip to content

Commit 2a86d5a

Browse files
committed
Update magicbot for new DriverStation threading model
1 parent ab6f21d commit 2a86d5a

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

magicbot/magicrobot.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,17 @@ def _disabled(self) -> None:
434434
self.onException(forceReport=True)
435435
watchdog.addEpoch("disabledInit()")
436436

437+
refreshData = wpilib.DriverStation.refreshData
438+
DSControlWord = wpilib.DSControlWord
439+
437440
with NotifierDelay(self.control_loop_wait_time) as delay:
438-
while not self.__done and self.isDisabled():
439-
if ds_attached != self.__is_ds_attached():
441+
while not self.__done:
442+
refreshData()
443+
cw = DSControlWord()
444+
if cw.isEnabled():
445+
break
446+
447+
if ds_attached != cw.isDSAttached():
440448
ds_attached = not ds_attached
441449
self.__nt_put_is_ds_attached(ds_attached)
442450

@@ -484,9 +492,15 @@ def _operatorControl(self) -> None:
484492
watchdog.addEpoch("teleopInit()")
485493

486494
observe = hal.observeUserProgramTeleop
495+
refreshData = wpilib.DriverStation.refreshData
496+
isTeleopEnabled = wpilib.DriverStation.isTeleopEnabled
487497

488498
with NotifierDelay(self.control_loop_wait_time) as delay:
489-
while not self.__done and self.isTeleopEnabled():
499+
while not self.__done:
500+
refreshData()
501+
if not isTeleopEnabled():
502+
break
503+
490504
observe()
491505
try:
492506
self.teleopPeriodic()
@@ -526,8 +540,16 @@ def _test(self) -> None:
526540
self.onException(forceReport=True)
527541
watchdog.addEpoch("testInit()")
528542

543+
refreshData = wpilib.DriverStation.refreshData
544+
DSControlWord = wpilib.DSControlWord
545+
529546
with NotifierDelay(self.control_loop_wait_time) as delay:
530-
while not self.__done and self.isTest() and self.isEnabled():
547+
while not self.__done:
548+
refreshData()
549+
cw = DSControlWord()
550+
if not (cw.isTest() and cw.isEnabled()):
551+
break
552+
531553
hal.observeUserProgramTest()
532554
try:
533555
self.testPeriodic()

robotpy_ext/autonomous/selector.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,15 @@ def watchdog_check_expired():
272272
#
273273

274274
observe = hal.observeUserProgramAutonomous
275+
refreshData = wpilib.DriverStation.refreshData
275276
isAutonomousEnabled = wpilib.DriverStation.isAutonomousEnabled
276277

277278
with NotifierDelay(control_loop_wait_time) as delay:
278-
while isAutonomousEnabled():
279+
while True:
280+
refreshData()
281+
if not isAutonomousEnabled():
282+
break
283+
279284
observe()
280285
try:
281286
self._on_iteration(timer.get())

0 commit comments

Comments
 (0)