@@ -22,7 +22,7 @@ class IterativeRobotPy(RobotBase):
22
22
def __init__ (self , period : float ):
23
23
super ().__init__ ()
24
24
self ._periodS = period
25
- self ._watchdog = Watchdog (self ._periodS , self .printLoopOverrunMessage )
25
+ self .watchdog = Watchdog (self ._periodS , self .printLoopOverrunMessage )
26
26
self ._networkTableInstanceDefault = NetworkTableInstance .getDefault ()
27
27
self ._mode : IterativeRobotMode = IterativeRobotMode .kNone
28
28
self ._lastMode : IterativeRobotMode = IterativeRobotMode .kNone
@@ -37,9 +37,6 @@ def __init__(self, period: float):
37
37
self ._teleopPeriodicHasRun : bool = False
38
38
self ._testPeriodicHasRun : bool = False
39
39
40
- def printLoopOverrunMessage (self ):
41
- pass
42
-
43
40
def robotInit (self ):
44
41
pass
45
42
@@ -123,7 +120,7 @@ def getPeriod(self) -> float:
123
120
124
121
def loopFunc (self ):
125
122
DriverStation .refreshData ()
126
- self ._watchdog .reset ()
123
+ self .watchdog .reset ()
127
124
128
125
isEnabled , isAutonomous , isTest = self .getControlState ()
129
126
if not isEnabled :
@@ -141,6 +138,20 @@ def loopFunc(self):
141
138
142
139
# If self._mode changed, call self._mode exit and entry functions
143
140
if self ._lastMode is not self ._mode :
141
+
142
+ if self ._lastMode is IterativeRobotMode .kDisabled :
143
+ self .disabledExit ()
144
+ elif self ._lastMode is IterativeRobotMode .kAutonomous :
145
+ self .autonomousExit ()
146
+ elif self ._lastMode is IterativeRobotMode .kTeleop :
147
+ self .teleopExit ()
148
+ elif self ._lastMode is IterativeRobotMode .kTest :
149
+ if self ._lwEnabledInTest :
150
+ LiveWindow .setEnabled (False )
151
+ Shuffleboard .disableActuatorWidgets ()
152
+ self .testExit ()
153
+ """
154
+ todo switch to match statements when we don't build with python 3.9
144
155
match self._lastMode:
145
156
case IterativeRobotMode.kDisabled:
146
157
self.disabledExit()
@@ -153,7 +164,24 @@ def loopFunc(self):
153
164
LiveWindow.setEnabled(False)
154
165
Shuffleboard.disableActuatorWidgets()
155
166
self.testExit()
156
-
167
+ """
168
+
169
+ if self ._mode is IterativeRobotMode .kDisabled :
170
+ self .disabledInit ()
171
+ self .watchdog .addEpoch ("DisabledInit()" )
172
+ elif self ._mode is IterativeRobotMode .kAutonomous :
173
+ self .autonomousInit ()
174
+ self .watchdog .addEpoch ("AutonomousInit()" )
175
+ elif self ._mode is IterativeRobotMode .kTeleop :
176
+ self .teleopInit ()
177
+ self .watchdog .addEpoch ("TeleopInit()" )
178
+ elif self ._mode is IterativeRobotMode .kTest :
179
+ if self ._lwEnabledInTest :
180
+ LiveWindow .setEnabled (True )
181
+ Shuffleboard .enableActuatorWidgets ()
182
+ self .testInit ()
183
+ self .watchdog .addEpoch ("TestInit()" )
184
+ """
157
185
match self._mode:
158
186
case IterativeRobotMode.kDisabled:
159
187
self.disabledInit()
@@ -170,59 +198,61 @@ def loopFunc(self):
170
198
Shuffleboard.enableActuatorWidgets()
171
199
self.testInit()
172
200
self._watchdog.addEpoch("TestInit()")
201
+ """
173
202
self ._lastMode = self ._mode
174
203
175
204
# Call the appropriate function depending upon the current robot mode
176
205
match self ._mode :
177
206
case IterativeRobotMode .kDisabled :
178
207
observeUserProgramDisabled ()
179
208
self .disabledPeriodic ()
180
- self ._watchdog .addEpoch ("DisabledPeriodic()" )
209
+ self .watchdog .addEpoch ("DisabledPeriodic()" )
181
210
case IterativeRobotMode .kAutonomous :
182
211
observeUserProgramAutonomous ()
183
212
self .autonomousPeriodic ()
184
- self ._watchdog .addEpoch ("AutonomousPeriodic()" )
213
+ self .watchdog .addEpoch ("AutonomousPeriodic()" )
185
214
case IterativeRobotMode .kTeleop :
186
215
observeUserProgramTeleop ()
187
216
self .teleopPeriodic ()
188
- self ._watchdog .addEpoch ("TeleopPeriodic()" )
217
+ self .watchdog .addEpoch ("TeleopPeriodic()" )
189
218
case IterativeRobotMode .kTest :
190
219
observeUserProgramTest ()
191
220
self .testPeriodic ()
192
- self ._watchdog .addEpoch ("TestPeriodic()" )
221
+ self .watchdog .addEpoch ("TestPeriodic()" )
193
222
194
223
self .robotPeriodic ()
195
- self ._watchdog .addEpoch ("RobotPeriodic()" )
224
+ self .watchdog .addEpoch ("RobotPeriodic()" )
196
225
197
226
SmartDashboard .updateValues ()
198
- self ._watchdog .addEpoch ("SmartDashboard::UpdateValues()" )
227
+ self .watchdog .addEpoch ("SmartDashboard::UpdateValues()" )
199
228
200
229
LiveWindow .updateValues ()
201
- self ._watchdog .addEpoch ("LiveWindow::UpdateValues()" )
230
+ self .watchdog .addEpoch ("LiveWindow::UpdateValues()" )
202
231
203
232
Shuffleboard .update ()
204
- self ._watchdog .addEpoch ("Shuffleboard::Update()" )
233
+ self .watchdog .addEpoch ("Shuffleboard::Update()" )
205
234
206
235
if self .isSimulation ():
207
236
simPeriodicBefore ()
208
237
self .simulationPeriodic ()
209
238
simPeriodicAfter ()
210
- self ._watchdog .addEpoch ("SimulationPeriodic()" )
239
+ self .watchdog .addEpoch ("SimulationPeriodic()" )
211
240
212
- self ._watchdog .disable ()
241
+ self .watchdog .disable ()
213
242
214
243
# Flush NetworkTables
215
244
if self ._ntFlushEnabled :
216
245
self ._networkTableInstanceDefault .flushLocal ()
217
246
218
247
# Warn on loop time overruns
219
- if self ._watchdog .isExpired ():
220
- self ._watchdog . printEpochs ()
248
+ if self .watchdog .isExpired ():
249
+ self .printWatchdogEpochs ()
221
250
222
- def printLoopOverrunMessages (self ):
251
+ def printLoopOverrunMessage (self ):
223
252
reportWarning (
224
253
f"Loop time of { self ._periodS } s overrun\n " , False
225
254
)
255
+ print ("IN printLoopOverrunMessage\n \n " , flush = True )
226
256
227
257
def printWatchdogEpochs (self ):
228
- self ._watchdog .printEpochs ()
258
+ self .watchdog .printEpochs ()
0 commit comments