@@ -179,9 +179,23 @@ def __contains__(self, item) -> bool:
179
179
def __repr__ (self ) -> str :
180
180
return str (sorted (self ._data ))
181
181
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
+
182
196
183
197
# todo what should the name of this class be?
184
- class TimedRobotPy (IterativeRobotPy ):
198
+ class TimedRobotPy (_IterativeRobotPy ):
185
199
"""
186
200
TimedRobotPy implements the IterativeRobotBase robot program framework.
187
201
@@ -202,26 +216,30 @@ def __init__(self, period: wpimath.units.seconds = kDefaultPeriod) -> None:
202
216
203
217
:param period: period of the main robot periodic loop in seconds.
204
218
"""
205
- super ().__init__ (period )
219
+ if "_IterativeRobotPyIsObject" in argv :
220
+ super ().__init__ ()
221
+ self ._periodS = period
222
+ else :
223
+ super ().__init__ (period )
206
224
207
225
# All periodic functions created by addPeriodic are relative
208
226
# to this self._startTimeUs
209
227
self ._startTimeUs = _getFPGATime ()
210
- self ._callbacks = _OrderedListSort ()
228
+ self ._callbacks = _OrderedList ()
211
229
self ._loopStartTimeUs = 0
212
230
self .addPeriodic (self ._loopFunc , period = self ._periodS )
213
231
214
- self ._notifier , status = initializeNotifier ()
232
+ self ._notifier , status = _initializeNotifier ()
215
233
if status != 0 :
216
234
raise RuntimeError (
217
235
f"initializeNotifier() returned { self ._notifier } , { status } "
218
236
)
219
237
220
- status = setNotifierName (self ._notifier , "TimedRobotPy" )
238
+ status = _setNotifierName (self ._notifier , "TimedRobotPy" )
221
239
if status != 0 :
222
240
raise RuntimeError (f"setNotifierName() returned { status } " )
223
241
224
- report (_kResourceType_Framework , _kFramework_Timed )
242
+ _report (_kResourceType_Framework , _kFramework_Timed )
225
243
226
244
def startCompetition (self ) -> None :
227
245
"""
@@ -235,14 +253,12 @@ def startCompetition(self) -> None:
235
253
236
254
# Tell the DS that the robot is ready to be enabled
237
255
print ("********** Robot program startup complete **********" , flush = True )
238
- observeUserProgramStarting ()
256
+ _observeUserProgramStarting ()
239
257
240
258
# Loop forever, calling the appropriate mode-dependent function
241
259
# (really not forever, there is a check for a stop)
242
260
while self ._bodyOfMainLoop ():
243
261
pass
244
- print ("Reached after while self._bodyOfMainLoop(): " , flush = True )
245
-
246
262
finally :
247
263
print ("Reached after finally: self._stopNotifier(): " , flush = True )
248
264
# pytests hang on PC when we don't force a call to self._stopNotifier()
@@ -254,11 +270,11 @@ def _bodyOfMainLoop(self) -> bool:
254
270
# there's always at least one (the constructor adds one).
255
271
callback = self ._callbacks .peek ()
256
272
257
- status = updateNotifierAlarm (self ._notifier , callback .expirationUs )
273
+ status = _updateNotifierAlarm (self ._notifier , callback .expirationUs )
258
274
if status != 0 :
259
275
raise RuntimeError (f"updateNotifierAlarm() returned { status } " )
260
276
261
- self ._loopStartTimeUs , status = waitForNotifierAlarm (self ._notifier )
277
+ self ._loopStartTimeUs , status = _waitForNotifierAlarm (self ._notifier )
262
278
263
279
# The C++ code that this was based upon used the following line to establish
264
280
# the loopStart time. Uncomment it and
@@ -324,7 +340,7 @@ def _runCallbackAtHeadOfListAndReschedule(self, callback) -> None:
324
340
self ._callbacks .reorderListAfterAChangeInTheFirstElement ()
325
341
326
342
def _stopNotifier (self ):
327
- stopNotifier (self ._notifier )
343
+ _stopNotifier (self ._notifier )
328
344
329
345
def endCompetition (self ) -> None :
330
346
"""
0 commit comments