@@ -52,6 +52,9 @@ class MagicRobot(wpilib.SampleRobot, metaclass=OrderedClass):
5252 #: uncaught exceptions be reported?
5353 error_report_interval = 0.5
5454
55+ #: If True, teleopPeriodic will be called in autonomous mode
56+ use_teleop_in_autonomous = False
57+
5558 def robotInit (self ):
5659 """
5760 .. warning:: Internal API, don't override; use :meth:`createObjects` instead
@@ -122,6 +125,10 @@ def teleopPeriodic(self):
122125
123126 This code executes before the ``execute`` functions of all
124127 components are called.
128+
129+ .. note:: If you want this function to be called in autonomous
130+ mode, set ``use_teleop_in_autonomous`` to True in your
131+ robot class.
125132 """
126133 func = self .teleopPeriodic .__func__
127134 if not hasattr (func , "firstRun" ):
@@ -290,9 +297,17 @@ def autonomous(self):
290297
291298 self ._on_mode_enable_components ()
292299
300+ auto_functions = (
301+ self ._execute_components ,
302+ self ._update_feedback ,
303+ self .robotPeriodic ,
304+ )
305+ if self .use_teleop_in_autonomous :
306+ auto_functions = (self .teleopPeriodic ,) + auto_functions
307+
293308 self ._automodes .run (
294309 self .control_loop_wait_time ,
295- ( self . _execute_components , self . _update_feedback , self . robotPeriodic ) ,
310+ auto_functions ,
296311 self .onException ,
297312 watchdog = self .watchdog ,
298313 )
0 commit comments