Announcement

Collapse
No announcement yet.

Can you block in the newest beta?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can you block in the newest beta?

    The 3/9 beta has this feature listed
    - loop() (for an OpMode) is now decoupled from the system's hardware read/write thread.

    Does this mean you can use while loops now?

  • #2
    Blocking in loop() is still not recommended; that's better done in a LinearOpMode.

    The thread that calls loop() also sends the telemetry, handles driver-station heartbeat connection monitoring, does USB detachment & reattachment, etc. If you block inside of loop(), none of that gets done.

    The need for one’s loop() implementation to run in sub-~5ms (in order that the modern controllers got serviced in a timely manner) is now gone, but I wouldn’t recommend never returning from a loop() method: that’s a coding approach that’s better suited for a LinearOpMode

    Comment


    • #3
      With the new beta (v1.7), is coding in Linear Op Mode going to be identical to coding in RobotC, or are there still some other things that have to be done?
      Programmer for Team 4997 Masquerade -- 2012 World Champions, 2014 - 2016 Division Finalists
      Founding Member of Team 6433 Neutrinos -- 2015 World Champions

      Check out my intro video to the new tech platform
      Check out my team's Robot Reveal for Res-Q

      Comment


      • #4
        Originally posted by Varun Singh View Post
        With the new beta (v1.7), is coding in Linear Op Mode going to be identical to coding in RobotC, or are there still some other things that have to be done?
        Hi Varun,

        With the new beta (1.7) software, coding in the LinearOpMode class is very similar to coding in RobotC. For instance, you can block (for example, sleep()) in your LinearOpMode and also not have to worry about using the waitOneFullHardwareCycle method.

        You can also reset the encoders and not have to wait an arbitrary amount of time to wait for the change to take effect. Once the control is returned to your op mode, the task should be already complete.

        Also, when the command statements in the OpMode are done running, the Op Mode should auto stop. The driver does not have to push the stop button to stop the op mode if all of its commands have been executed.

        One key difference for the LinearOpMode class that is different from RobotC, is that you should still only do interruptible loops. For example, you should use the opModeIsActive() method as the test condition for a while loop:

        while (opModeIsActive()) {

        ...

        }

        You want to use an interruptible method rather than do something like "while (true)" so that the op mode will stop properly when the user pushes the stop button on the driver station. If you have an uninterruptible thread running in your op mode, if the user pushes the stop button, but the thread is not interruptible, the app will eventually log an error (indicating a potential runaway process) and then crash the Robot Controller app to stop the thread. This is not ideal because once the Robot Controller app has crashed, you lose communication with the robot (unless someone restarts the app or power cycles the robot).

        Tom

        Comment


        • #5
          Originally posted by Tom Eng View Post
          Hi Varun,

          One key difference for the LinearOpMode class that is different from RobotC, is that you should still only do interruptible loops. For example, you should use the opModeIsActive() method as the test condition for a while loop:

          while (opModeIsActive()) {

          ...

          }

          Tom
          Just to clarify here, the example will loop until your opmode is stopped.

          More typically, you'd want to loop until some criteria is satisfied or your opmode is stopped
          which would look more like this.

          Code:
          while (someCriteriaNotSatisfied() && opModeIsActive()) {
          ...
          }

          Comment

          Working...
          X