Skip to content

Don't call preRun when stop is pressed during init phase - #39

Merged
ArushYadlapati merged 1 commit into
FTC-23511:masterfrom
monkbroc:init-then-stop
Aug 10, 2026
Merged

Don't call preRun when stop is pressed during init phase#39
ArushYadlapati merged 1 commit into
FTC-23511:masterfrom
monkbroc:init-then-stop

Conversation

@monkbroc

@monkbroc monkbroc commented Aug 4, 2026

Copy link
Copy Markdown

Pull Requests

Small fix for #34 to only call preRun() if the start button was pressed. When stop is pressed during init, neither preRun() nor run() should be called.

What kind of change does this PR introduce?

  • Fix

Did this PR introduce a breaking change?

  • No

Copilot AI lite review requested due to automatic review settings August 4, 2026 03:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes CommandOpMode’s lifecycle so preRun() (and therefore run()) is only entered when the OpMode actually transitions into the active/running state (i.e., the Start button was pressed), avoiding an unintended preRun() call when Stop is pressed during init.

Changes:

  • Guarded the preRun() + run-loop block with opModeIsActive() so it only executes after Start.
  • Preserved existing init-loop behavior and ensured end()/reset() still run via the existing finally block.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ArushYadlapati

ArushYadlapati commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Ah, that makes sense. However, why does the while loop need to be in the if loop?
From my understanding, because the if statement condition and the while loop condition is active:

if (opModeIsActive()) {
    preRun();
    while (opModeIsActive()) {
        run();
    }
}

should be the same as:

if (opModeIsActive()) {
    preRun();
}    
while (opModeIsActive()) {
    run();
}

@monkbroc

monkbroc commented Aug 6, 2026

Copy link
Copy Markdown
Author

Yes, both are equivalent. I just picked the first pattern because it's what the FTC SDK uses in the samples.

See ConceptAprilTag.java

        if (opModeIsActive()) {
            // put prerun things here
            while (opModeIsActive()) {
                telemetryAprilTag();
                telemetry.update();
                // ...
            }
        }

@ArushYadlapati

Copy link
Copy Markdown
Collaborator

Ah, I see - that makes sense, I will merge this in. Do note that end() will still run if stop is pressed during init.

@ArushYadlapati
ArushYadlapati merged commit d0de86e into FTC-23511:master Aug 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants