Announcement

Collapse
No announcement yet.

Is it safe to call Thread.sleep() in LinearOpMode

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

  • Is it safe to call Thread.sleep() in LinearOpMode


    To simplify the implementation, we would like to use Thread.sleep() in our subsystems for a short period of time. Is this safe? What's the recommended way to implement wait() without using a loop in the opmode.

  • #2
    Well it won't crash your program, however, if the stop button is pressed on the DS while your code is on a Thread.sleep() call, the RC will force crash your program and restart. Using the SDK's built-in sleep() call fixes that IIRC

    Comment


    • #3
      Is seep() available only in opmode? We want to use sleep in non op class but can

      Comment


      • #4
        Originally posted by FTC12676 View Post
        Is seep() available only in opmode? We want to use sleep in non op class but can
        Yes, it is a method of LinearOpMode. You can pass in your LinearOpMode to another class's constructor or method if you want to call sleep() in that class.

        Comment


        • #5
          Thanks. Will try in next meeting

          Comment


          • #6
            If your program doesn't need the thread open you can use the ElapsedTime object as a timer

            you could also theoretically use this code as it's the same code from the LinearOpMode class for either of those I recommend you make a method
            try { Thread.sleep(milliseconds); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }

            Comment

            Working...
            X