Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Pressing the stop button starts the program #677

Open
chexbox opened this issue Jan 5, 2019 · 4 comments
Open

Pressing the stop button starts the program #677

chexbox opened this issue Jan 5, 2019 · 4 comments

Comments

@chexbox
Copy link

chexbox commented Jan 5, 2019

After initializing the program, one member of my team decided to cancel it. When he pressed stop, the program started. It seems to act this way consistently.

@gearsincorg
Copy link
Collaborator

Was this an Auto program, written using LinearOpMode ?

If you have a waitForStart(), followed by some autonomous driving, and you don't have a check to see if the user pressed start or stop before running your auto code, it may drive for up to 2 seconds before the failsafe kicks in.

The problem is, if the user presses stop, waitForStart() will return, but it's up to your code to actually abort the autonomous sequence.

In all our auto opmodes, after the waitForStart() call, we always put our driving code inside a big IF..

waitForStart();
if (opModeIsActive()) {
// Autonomous driving code goes here...
}

This way, if the driver presses stop, before play, waitForStart() will return, and then the code will check to see if the opmode is really active, or whether it needs to exit immediately.

@David10238
Copy link

We don't do the if(opModeIsActive). We just have all loops include && opModeIsActive. We may have the bot twitch, but other than that nothing.

@chexbox
Copy link
Author

chexbox commented Jan 7, 2019

Interesting solution, but it is probably not a good solution from a UX point of view. I'll have to try it anyway.

@gearsincorg
Copy link
Collaborator

Another way to do it is to put a test just after the waitForStart() that returns immediately if stop has been pressed instead of play

waitForStart();
if (isStopRequested())
return;

I personally don't like this approach because back in the day, when I was learning to program, it was frowned on to have more than one exit point from a function or method.

I also prefer the big if() because it ensure no further movement, and it provides the opportunity to do any shutdown after the if() to clean up anything that was started (like vision processing) before the waitForStart().

It's just a sign of more thoughtful programming to prevent your auto code running when the user decides to abort before hitting play.

If you just let the program run, and hope for the while loops to terminate quickly, it won't stop other things like servo movement which might unlatch an arm or winch, which then may need to be reset.

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

3 participants