Skip to content

Commit 95d33dd

Browse files
authored
Merge branch 'mike-2025-05-27-broke-tests' into mike-2025-05-28-passes-again
2 parents e35a0b5 + f37b198 commit 95d33dd

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

subprojects/robotpy-wpilib/tests/test_timedrobot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def _robotThread(self, robot: TimedRobotPy) -> None:
109109
robot._TestRobot__robotInitStarted = self._onRobotInitStarted
110110

111111
try:
112+
print("about to:robot.startCompetition()",flush=True)
112113
robot.startCompetition()
113114
print("after robot.startCompetition()",flush=True)
114115
self._startCompetitionReturned = True

subprojects/robotpy-wpilib/wpilib/timedrobotpy.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,23 @@ def __contains__(self, item) -> bool:
179179
def __repr__(self) -> str:
180180
return str(sorted(self._data))
181181

182+
# Hooks to use timeit to evaluate configurations of TimedRobotPy
183+
_OrderedList = _OrderedListSort
184+
_initializeNotifier = initializeNotifier
185+
_setNotifierName = setNotifierName
186+
_observeUserProgramStarting = observeUserProgramStarting
187+
_updateNotifierAlarm = updateNotifierAlarm
188+
_waitForNotifierAlarm = waitForNotifierAlarm
189+
_stopNotifier = stopNotifier
190+
_report = report
191+
_IterativeRobotPy = IterativeRobotPy
192+
if '_IterativeRobotPyIsObject' in argv:
193+
print("_IterativeRobotPyIsObject")
194+
_IterativeRobotPy = object
195+
182196

183197
# todo what should the name of this class be?
184-
class TimedRobotPy(IterativeRobotPy):
198+
class TimedRobotPy(_IterativeRobotPy):
185199
"""
186200
TimedRobotPy implements the IterativeRobotBase robot program framework.
187201
@@ -202,26 +216,30 @@ def __init__(self, period: wpimath.units.seconds = kDefaultPeriod) -> None:
202216
203217
:param period: period of the main robot periodic loop in seconds.
204218
"""
205-
super().__init__(period)
219+
if "_IterativeRobotPyIsObject" in argv:
220+
super().__init__()
221+
self._periodS = period
222+
else:
223+
super().__init__(period)
206224

207225
# All periodic functions created by addPeriodic are relative
208226
# to this self._startTimeUs
209227
self._startTimeUs = _getFPGATime()
210-
self._callbacks = _OrderedListSort()
228+
self._callbacks = _OrderedList()
211229
self._loopStartTimeUs = 0
212230
self.addPeriodic(self._loopFunc, period=self._periodS)
213231

214-
self._notifier, status = initializeNotifier()
232+
self._notifier, status = _initializeNotifier()
215233
if status != 0:
216234
raise RuntimeError(
217235
f"initializeNotifier() returned {self._notifier}, {status}"
218236
)
219237

220-
status = setNotifierName(self._notifier, "TimedRobotPy")
238+
status = _setNotifierName(self._notifier, "TimedRobotPy")
221239
if status != 0:
222240
raise RuntimeError(f"setNotifierName() returned {status}")
223241

224-
report(_kResourceType_Framework, _kFramework_Timed)
242+
_report(_kResourceType_Framework, _kFramework_Timed)
225243

226244
def startCompetition(self) -> None:
227245
"""
@@ -235,14 +253,12 @@ def startCompetition(self) -> None:
235253

236254
# Tell the DS that the robot is ready to be enabled
237255
print("********** Robot program startup complete **********", flush=True)
238-
observeUserProgramStarting()
256+
_observeUserProgramStarting()
239257

240258
# Loop forever, calling the appropriate mode-dependent function
241259
# (really not forever, there is a check for a stop)
242260
while self._bodyOfMainLoop():
243261
pass
244-
print("Reached after while self._bodyOfMainLoop(): ", flush=True)
245-
246262
finally:
247263
print("Reached after finally: self._stopNotifier(): ", flush=True)
248264
# pytests hang on PC when we don't force a call to self._stopNotifier()
@@ -254,11 +270,11 @@ def _bodyOfMainLoop(self) -> bool:
254270
# there's always at least one (the constructor adds one).
255271
callback = self._callbacks.peek()
256272

257-
status = updateNotifierAlarm(self._notifier, callback.expirationUs)
273+
status = _updateNotifierAlarm(self._notifier, callback.expirationUs)
258274
if status != 0:
259275
raise RuntimeError(f"updateNotifierAlarm() returned {status}")
260276

261-
self._loopStartTimeUs, status = waitForNotifierAlarm(self._notifier)
277+
self._loopStartTimeUs, status = _waitForNotifierAlarm(self._notifier)
262278

263279
# The C++ code that this was based upon used the following line to establish
264280
# the loopStart time. Uncomment it and
@@ -324,7 +340,7 @@ def _runCallbackAtHeadOfListAndReschedule(self, callback) -> None:
324340
self._callbacks.reorderListAfterAChangeInTheFirstElement()
325341

326342
def _stopNotifier(self):
327-
stopNotifier(self._notifier)
343+
_stopNotifier(self._notifier)
328344

329345
def endCompetition(self) -> None:
330346
"""

0 commit comments

Comments
 (0)