@@ -52,6 +52,9 @@ class MagicRobot(wpilib.SampleRobot, metaclass=OrderedClass):
52
52
#: uncaught exceptions be reported?
53
53
error_report_interval = 0.5
54
54
55
+ #: If True, teleopPeriodic will be called in autonomous mode
56
+ use_teleop_in_autonomous = False
57
+
55
58
def robotInit (self ):
56
59
"""
57
60
.. warning:: Internal API, don't override; use :meth:`createObjects` instead
@@ -122,6 +125,10 @@ def teleopPeriodic(self):
122
125
123
126
This code executes before the ``execute`` functions of all
124
127
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.
125
132
"""
126
133
func = self .teleopPeriodic .__func__
127
134
if not hasattr (func , "firstRun" ):
@@ -290,9 +297,17 @@ def autonomous(self):
290
297
291
298
self ._on_mode_enable_components ()
292
299
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
+
293
308
self ._automodes .run (
294
309
self .control_loop_wait_time ,
295
- ( self . _execute_components , self . _update_feedback , self . robotPeriodic ) ,
310
+ auto_functions ,
296
311
self .onException ,
297
312
watchdog = self .watchdog ,
298
313
)
0 commit comments