[wpilib] LinearOpMode: wait for mode change to return from OpModeRun (#8477)

We need to wait, or otherwise OpModeRobot will immediately reinstantiate
and re-run the opmode, which is generally undesirable (e.g. for
autonomous).

Fixes #8475.
This commit is contained in:
Peter Johnson
2025-12-13 21:45:22 -08:00
committed by GitHub
parent e2c9af862e
commit f6ef155166
2 changed files with 15 additions and 0 deletions

View File

@@ -67,6 +67,12 @@ public abstract class LinearOpMode implements OpMode {
try (DriverStationModeThread bgThread = new DriverStationModeThread(word)) {
run();
// Wait for opmode to be stopped or disabled, otherwise OpModeRobot will recreate and re-run
// the opmode immediately.
while (isRunning() && DriverStation.isEnabled() && DriverStation.getOpModeId() == opModeId) {
Thread.sleep(20);
}
}
}