Skip to content

Commit 3e8b34d

Browse files
committed
magicbot: Add testInit and testPeriodic methods
1 parent e22306b commit 3e8b34d

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

magicbot/magicrobot.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,23 @@ def disabledPeriodic(self):
152152
self.logger.warning("Default MagicRobot.disabledPeriodic() method... Overload me!")
153153
func.firstRun = False
154154

155+
def testInit(self):
156+
"""Initialization code for test mode should go here.
157+
158+
Users should override this method for initialization code which will be
159+
called each time the robot enters disabled mode.
160+
"""
161+
pass
162+
163+
def testPeriodic(self):
164+
"""Periodic code for test mode should go here."""
165+
pass
166+
155167
def robotPeriodic(self):
156168
"""
157169
Periodic code for all modes should go here.
158170
159-
` Users must override this method to utilize it
171+
Users must override this method to utilize it
160172
but it is not required.
161173
162174
This function gets called last in each mode.
@@ -352,8 +364,18 @@ def test(self):
352364
self.__nt.putString('mode', 'test')
353365
self.__nt.putBoolean('is_ds_attached', self.ds.isDSAttached())
354366
wpilib.LiveWindow.setEnabled(True)
367+
368+
try:
369+
self.testInit()
370+
except:
371+
self.onException(forceReport=True)
355372

356373
while self.isTest() and self.isEnabled():
374+
try:
375+
self.testPeriodic()
376+
except:
377+
self.onException()
378+
357379
self._update_feedback()
358380
self.robotPeriodic()
359381
wpilib.Timer.delay(self.control_loop_wait_time)

0 commit comments

Comments
 (0)