Announcement

Collapse
No announcement yet.

Behavior when Autonomous LinearOpMode Times Out

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

  • Behavior when Autonomous LinearOpMode Times Out

    We use a linear opmode for autonomous, which includes a series of calls to navigation methods. Each navigation method has a control loop ( i.e., while(opModeIsActive() {...} ), with a statement immediately after this loop (just before the method ends) that stops all of the drive motors. Occasionally we time out while attempting to park (when we have a four-ring stack). When that happens, the robot behavior becomes unpredictable. It may drive off in an unexpected direction, or may overshoot the park line. I'm wondering why that happens. In an orderly exit (due to opModeIsActive() returning false), I would expect it to just stop immediately.

  • #2
    Want to share your code? (If you have another loop inside that doesn't have opModeIsActive() as a condition to continue then you'll have this problem.).


    As a side note, this is one of many reasons why I prefer teams to use OpMode instead. There is too much "magic" that has to be right. I think it is easier to teach the idea of loop being called regularly and you having to keep track of "state".

    --Alan
    Coach FTC #16072, Quantum Quacks
    Author of Learn Java for FTC - FREE PDF here: https://github.com/alan412/LearnJavaForFTC

    Comment


    • #3
      This gist contains the relevant code: the last part of our op mode (RedAutonomous3ExtraBoth -- from dropping off 2nd wobble through parking), and the superclass of our op mode (MecbotAutonomous, which itself extends LinearOpMode and has our basic driving methods).

      https://gist.github.com/jkenney2/fcf...080c91c1005a7d

      Comment


      • #4
        Originally posted by jkenney View Post
        This gist contains the relevant code: the last part of our op mode (RedAutonomous3ExtraBoth -- from dropping off 2nd wobble through parking), and the superclass of our op mode (MecbotAutonomous, which itself extends LinearOpMode and has our basic driving methods).

        https://gist.github.com/jkenney2/fcf...080c91c1005a7d
        I wonder if this is the problem:
        sleep(300);

        Replace this with something like this:

        ElapsedTime timer = new ElapsedTime();
        timer.reset();
        while(opModeIsActive() && timer.milliseconds() < 300){
        sleep(1); // just to give other threads a chance
        }


        Please let me know if this fixes it!

        --Alan
        Coach FTC #16072, Quantum Quacks

        Comment


        • #5
          Hmm - also what does bot.updateOdometry() look like? I assume it is a quickly returning method. But perhaps not....

          --Alan

          Comment


          • #6
            Thanks, I'll give that a try. We have been using sleep() to wait for servos to open and close, though not within our control loops. I've wondered how much variation there is in the actual "sleep time", but have never tested it.

            I added MecBot.updateOdometry() to the gist. It just checks the drive motor encoders and obtains a heading from the imu, then does a pretty standard odometry calculation--no looping.

            Jim

            Comment

            Working...
            X