FIRST-Tech-Challenge / SkyStone

FTC SDK
https://www.firstinspires.org/robotics/ftc/what-is-first-tech-challenge
275 stars 1.04k forks source link

waitForStart missing from example op mode PushbotAutoDriveToLine_Linear.java #106

Closed JohnMMcD closed 4 years ago

JohnMMcD commented 4 years ago

The example op mode starts prematurely (during init) because of a missing waitForStart() command. This problem was noted in this forum posting.

The waitForStart() command should be added after line 92.

92 // Wait for the game to start (driver presses PLAY) 93 waitForStart();

In diff-speak, this can be resolved by:

diff --git a/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/PushbotAutoDriveToLine_Linear.java b/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/PushbotAutoDriveToLine_Linear.java
index 2e174b1..7b07286 100644
--- a/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/PushbotAutoDriveToLine_Linear.java
+++ b/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/PushbotAutoDriveToLine_Linear.java
@@ -90,6 +90,8 @@ public class PushbotAutoDriveToLine_Linear extends LinearOpMode {
         telemetry.update();

         // Wait for the game to start (driver presses PLAY)
+        waitForStart();
+
         // Abort this loop is started or stopped.
         while (!(isStarted() || isStopRequested())) {
gearsincorg commented 4 years ago

Have you tested this to verify there is a problem.?

while (!(isStarted() || isStopRequested())) { ... }; should have the same functionality as waitForStart().

The code in question replaces wairForStart() with a while loop that displays the light level while it waits for the user to press Start.

isStarted() and isStopRequested() will both return false until either start or stop are pressed. So the while will loop.

Phil.

JohnMMcD commented 4 years ago

Phil, I confess that I have not experimentally verified this. I was going by the behavior reported by the forum poster and a code comparison between PushbotAutoDriveToLine_Linear.java and PushbotAutoDriveByTime_Linear.java , and specifically by the fact that both include a comment "Wait for the game to start (driver presses PLAY)", while one includes the waitForStart and the other doesn't. I think my logic was faulty, though, because there is more than one way to make the wait happen. I'm going to close this until I have more evidence. Sorry for the trouble.