You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: design-docs/opmodes.md
+9-18Lines changed: 9 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -150,16 +150,8 @@ The `OpModeRobot` class is the base class for the user's `Robot` class. It also
150
150
151
151
```java
152
152
publicabstractclassOpModeRobot {
153
-
publicvoiddisabledStart() {
154
-
// this code is called when the robot enters disabled state (including at startup)
155
-
}
156
-
157
-
publicvoiddisabledPeriodic() {
158
-
// this code is called periodically while the robot is disabled
159
-
}
160
-
161
-
publicvoiddisabledEnd() {
162
-
// this code is called when the robot exits disabled state, prior to a opmode starting
153
+
publicvoidnonePeriodic() {
154
+
// this code is called when no opmode is selected
163
155
}
164
156
165
157
// these functions allow users to add opmodes without annotations
@@ -177,22 +169,24 @@ The full lifecycle of a opmode is as follows:
177
169
- Operator selects opmode on DS -> opmode object is constructed
178
170
- If different opmode is selected -> `opModeClose()` is called (which typically just calls `close()`), object is released to GC
179
171
- While opmode is selected and robot is disabled, `disabledPeriodic()` is called
180
-
- When the robot is enabled in the selected opmode, `opmodeRun()` is called; the result of this is different for different opmode base classes:
172
+
- When the robot is enabled in the selected opmode, `opModeRun()` is called; the result of this is different for different opmode base classes:
181
173
-`start()` is called once (for `PeriodicOpMode`)
182
174
-`run()` is called (for `LinearOpMode`), or `periodic()` is called periodically (for `PeriodicOpMode`)
183
175
- When the robot is disabled, `opModeStop()` is called (which results in `end()` being called for `PeriodicOpMode`), followed by `opModeClose()` (which results in `close()` being called for both `PeriodicOpMode` and `LinearOpMode`), object is released to GC
184
176
185
177
Following `opModeClose()` being called, a *new* opmode object is constructed based on the DS teleop/auto/test/match selector and selected opmode. In teleop/auto/test, the drop-down selection will be the same as before the previous enable, so the same opmode class is constructed again. In match (or when FMS-connected), only the selected auto opmode object is initially constructed; once auto completes, the selected teleop opmode object is constructed. Thus only zero or one opmode objects will ever be "alive" at any given time.
186
178
187
179
For consistency in operation, the library will ensure that `disabledPeriodic()` is always called at least once before `opModeRun()` is called.
188
-
180
+
- When the robot is enabled in the selected opmode, `opModeRun()` is called; the result of this is different for different opmode base classes:
189
181
User implementations of opmode classes may have either a no-parameter constructor or a constructor that accepts the user's `Robot` class type. If available, the library will call the latter and pass the user's `Robot` object to it when constructing the class.
190
182
191
183
The library will use escalating steps to attempt to terminate a opmode if `opModeRun()` does not return within a reasonable timeframe after `opModeStop()` is called, up to and including termination of the robot executable process (which will result in an automatic restart of it at the system level). User code (particularly in `LinearOpMode` derived classes) should check for `isRunning()` returning false and return as quickly as possible to allow the opmode to terminate gracefully.
192
184
193
185
```java
194
186
publicinterfaceOpMode {
195
187
// this function is called periodically while the opmode is selected on the DS (robot is disabled)
188
+
// Note: it may be called once when the robot is enabled to ensure it's always called once before
189
+
// opModeRun() is called
196
190
default voiddisabledPeriodic() {}
197
191
198
192
// this function is called when the opmode starts (robot is enabled)
@@ -225,7 +219,7 @@ public abstract class LinearOpMode implements OpMode {
@@ -235,7 +229,7 @@ public abstract class LinearOpMode implements OpMode {
235
229
}
236
230
237
231
@Override
238
-
publicfinalvoidopModeEnd() {
232
+
publicfinalvoidopModeStop() {
239
233
// pseudo-code
240
234
isRunning =false;
241
235
}
@@ -282,10 +276,6 @@ public abstract class PeriodicOpMode implements OpMode {
282
276
// returns the start time of the current loop in microseconds
283
277
publicfinallonggetLoopStartTime() {...}
284
278
285
-
publicbooleanisRunning() {
286
-
// returns true until opModeEnd() is called
287
-
}
288
-
289
279
// implements OpMode interface
290
280
@Override
291
281
publicfinalvoidopModeRun(longopModeId) {
@@ -487,6 +477,7 @@ Adding the following function enables maintaining the available opmode options l
487
477
488
478
`HAL_OpModeOption` is a structure describing each option:
489
479
-`long id` - unique ID identifying the opmode (robot mode, name) pair. This encodes the robot mode in the upper bits, indicating which robot mode the opmode should be visible for (auto/teleop/test)
480
+
-`string name`
490
481
-`string group`
491
482
-`string description`
492
483
-`int textColor` - optional, used to set the text color for the option in the DS GUI
0 commit comments