Skip to content

Commit 49e82ed

Browse files
committed
Add endCompetition to AutonomousModeSelector
- without this the sim will crash on exit in autonomous
1 parent 2a86d5a commit 49e82ed

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

magicbot/magicrobot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ def startCompetition(self) -> None:
377377

378378
def endCompetition(self) -> None:
379379
self.__done = True
380+
self._automodes.endCompetition()
380381

381382
def autonomous(self) -> None:
382383
"""

robotpy_ext/autonomous/selector.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def __init__(self, autonomous_pkgname, *args, **kwargs):
8080

8181
self.modes = {}
8282
self.active_mode = None
83+
self.robot_exit = False
8384

8485
logger.info("Begin initializing autonomous mode switcher")
8586

@@ -210,6 +211,10 @@ def __init__(self, autonomous_pkgname, *args, **kwargs):
210211

211212
logger.info("Autonomous switcher initialized")
212213

214+
def endCompetition(self):
215+
"""Call this function when your robot's endCompetition function is called"""
216+
self.robot_exit = True
217+
213218
def run(
214219
self,
215220
control_loop_wait_time: float = 0.020,
@@ -276,7 +281,7 @@ def watchdog_check_expired():
276281
isAutonomousEnabled = wpilib.DriverStation.isAutonomousEnabled
277282

278283
with NotifierDelay(control_loop_wait_time) as delay:
279-
while True:
284+
while not self.robot_exit:
280285
refreshData()
281286
if not isAutonomousEnabled():
282287
break

0 commit comments

Comments
 (0)