Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

A while loop in a task will continue running even after disabling and reenabling? #6

Open
sylvia43 opened this issue Mar 6, 2017 · 0 comments

Comments

@sylvia43
Copy link
Contributor

sylvia43 commented Mar 6, 2017

We had a bug on Saturday. What happened is if we disabled in the middle of our autonomous code and then reenabled, the motors would sometimes continue at the same values they had before and would not accept input. I found a tricky infinite loop and fixed it, and from then on we didn't see the issue again:

581d9e3#diff-2094e283bb3890e841571da6ac09c6b1R133

Here's my attempt at figuring out what the issue is.

Consider the following TaskRunner and example task:

new TaskRunner(
    new ExampleTask(),
    new UpdateMotorsTask()
);
public class ExampleTask extends Task {
    public void run() {
        while (true) {
            Robot.motors.allDrive.set(1.0);
            wait.forFrame();
        }
    }
}

If you enable the robot, this task will run and work fine. However, if you make the logic slightly more insidious:

public class ExampleTask extends Task {
    public void run() {
        while (true) {
            if (condition) {
                continue;
            }
            Robot.motors.allDrive.set(1.0);
            wait.forFrame();
        }
    }
}

If condition is true, then this task will get caught in an infinite loop and will not ever wait, and thus will not ever terminate. This loop will continue to run as long as condition is true...

Actually, I can't seem to get something that'd replicate the issue we saw on Saturday.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant