@@ -397,10 +397,7 @@ def autonomous(self) -> None:
397
397
except :
398
398
self .onException (forceReport = True )
399
399
400
- auto_functions : Tuple [Callable [[], None ], ...] = (
401
- self ._execute_components ,
402
- self ._update_feedback ,
403
- ) + tuple (p [0 ] for p in self .__periodics )
400
+ auto_functions : Tuple [Callable [[], None ], ...] = (self ._enabled_periodic ,)
404
401
405
402
if self .use_teleop_in_autonomous :
406
403
auto_functions = (self .teleopPeriodic ,) + auto_functions
@@ -456,12 +453,8 @@ def _disabled(self) -> None:
456
453
self .onException ()
457
454
watchdog .addEpoch ("disabledPeriodic()" )
458
455
459
- self ._update_feedback ()
460
- for periodic , name in self .__periodics :
461
- periodic ()
462
- watchdog .addEpoch (name )
456
+ self ._do_periodics ()
463
457
# watchdog.disable()
464
-
465
458
watchdog .printIfExpired ()
466
459
467
460
delay .wait ()
@@ -509,14 +502,8 @@ def _operatorControl(self) -> None:
509
502
self .onException ()
510
503
watchdog .addEpoch ("teleopPeriodic()" )
511
504
512
- self ._execute_components ()
513
-
514
- self ._update_feedback ()
515
- for periodic , name in self .__periodics :
516
- periodic ()
517
- watchdog .addEpoch (name )
505
+ self ._enabled_periodic ()
518
506
# watchdog.disable()
519
-
520
507
watchdog .printIfExpired ()
521
508
522
509
delay .wait ()
@@ -558,12 +545,8 @@ def _test(self) -> None:
558
545
self .onException ()
559
546
watchdog .addEpoch ("testPeriodic()" )
560
547
561
- self ._update_feedback ()
562
- for periodic , name in self .__periodics :
563
- periodic ()
564
- watchdog .addEpoch (name )
548
+ self ._do_periodics ()
565
549
# watchdog.disable()
566
-
567
550
watchdog .printIfExpired ()
568
551
569
552
delay .wait ()
@@ -724,23 +707,36 @@ def _setup_reset_vars(self, component) -> None:
724
707
component .__dict__ .update (reset_dict )
725
708
self ._reset_components .append ((reset_dict , component ))
726
709
727
- def _update_feedback (self ) -> None :
710
+ def _do_periodics (self ) -> None :
711
+ """Run periodic methods which run in every mode."""
712
+ watchdog = self .watchdog
713
+
728
714
for method , entry in self ._feedbacks :
729
715
try :
730
716
value = method ()
731
717
except :
732
718
self .onException ()
733
- continue
734
- entry .setValue (value )
735
- self .watchdog .addEpoch ("@magicbot.feedback" )
719
+ else :
720
+ entry .setValue (value )
721
+
722
+ watchdog .addEpoch ("@magicbot.feedback" )
723
+
724
+ for periodic , name in self .__periodics :
725
+ periodic ()
726
+ watchdog .addEpoch (name )
727
+
728
+ def _enabled_periodic (self ) -> None :
729
+ """Run components and all periodic methods."""
730
+ watchdog = self .watchdog
736
731
737
- def _execute_components (self ) -> None :
738
732
for name , component in self ._components :
739
733
try :
740
734
component .execute ()
741
735
except :
742
736
self .onException ()
743
- self .watchdog .addEpoch (name )
737
+ watchdog .addEpoch (name )
738
+
739
+ self ._do_periodics ()
744
740
745
741
for reset_dict , component in self ._reset_components :
746
742
component .__dict__ .update (reset_dict )
0 commit comments