Skip to content

Commit 0f04ac4

Browse files
committed
Add DS loop timing telemetry to magicbot
IterativeRobotBase does this, so it might be useful to do this too.
1 parent 377a3af commit 0f04ac4

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

magicbot/magicrobot.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import inspect
33
import logging
44

5+
import hal
56
import wpilib
67

78
from networktables import NetworkTables
89
from wpilib.shuffleboard import Shuffleboard
910

10-
from robotpy_ext.misc import NotifierDelay
1111
from robotpy_ext.autonomous import AutonomousModeSelector
12-
12+
from robotpy_ext.misc import NotifierDelay
1313
from robotpy_ext.misc.orderedclass import OrderedClass
1414
from robotpy_ext.misc.annotations import get_class_annotations
1515

@@ -318,6 +318,7 @@ def disabled(self):
318318
ds_attached = not ds_attached
319319
self.__nt.putBoolean("is_ds_attached", ds_attached)
320320

321+
hal.observeUserProgramDisabled()
321322
try:
322323
self.disabledPeriodic()
323324
except:
@@ -352,6 +353,7 @@ def operatorControl(self):
352353

353354
with NotifierDelay(self.control_loop_wait_time) as delay:
354355
while self.isOperatorControl() and self.isEnabled():
356+
hal.observeUserProgramTeleop()
355357
try:
356358
self.teleopPeriodic()
357359
except:
@@ -379,6 +381,7 @@ def test(self):
379381

380382
with NotifierDelay(self.control_loop_wait_time) as delay:
381383
while self.isTest() and self.isEnabled():
384+
hal.observeUserProgramTest()
382385
try:
383386
self.testPeriodic()
384387
except:

robotpy_ext/autonomous/selector.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
from glob import glob
21
import importlib
32
import inspect
4-
import os
5-
63
import logging
4+
import os
5+
from glob import glob
76

8-
logger = logging.getLogger("autonomous")
7+
import hal
8+
import wpilib
99

1010
from ..misc.precise_delay import NotifierDelay
1111

12-
import wpilib
12+
logger = logging.getLogger("autonomous")
1313

1414

1515
class AutonomousModeSelector:
@@ -240,6 +240,7 @@ def run(self, control_loop_wait_time=0.020, iter_fn=None, on_exception=None):
240240

241241
with NotifierDelay(control_loop_wait_time) as delay:
242242
while self.ds.isAutonomous() and self.ds.isEnabled():
243+
hal.observeUserProgramAutonomous()
243244
try:
244245
self._on_iteration(timer.get())
245246
except:

0 commit comments

Comments
 (0)