Announcement

Collapse
No announcement yet.

Looping Issues

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

  • Looping Issues

    Hello,

    The link below is a picture of some code that my student was working on. He is building a robot that has to stay inside of a ring, but when a sensor is pressed, the "main" loop will be interrupted and then will do a secondary action. When that secondary action is complete the program should loop back to the beginning and then start to "main" loop again while it waits for one of the sensors to be triggered.

    This all works well while we only have one touch sensor wired up in the program. When we wire up the second touch sensor then the program will run that small section of code, but will not loop back to the "main" loop. This also does not work at all when the ultrasonic sensor is hooked up.

    We think we have found a work around for this issue, but we were both curious as to why this did not function the way we thought it would. We figured there was some kind of inherit flaw that we did not know about.

    Please let me know.

    https://www.dropbox.com/s/t9f6prmgel...itled.png?dl=0

  • #2
    A loop waits for all code inside the loop to complete before executing the next cycle. In your code all 4 beams (main beam with the inner loop and all 3 wait branches) need to complete before the loop will run again. This is also how Switch blocks and My Blocks work.

    As written your code implements "Wait for All" You could move the waits outside the loop, placing each in their own loop to implement "Wait for One of Many".
    WaitForMany1.JPG
    Another way to do this is have a single loop that tests for each condition and calls the loop interrupt if any of the conditions exist. This would use the yellow sensor blocks instead of the orange wait blocks. Use the Logic OR block to test for one of many conditions. I prefer this solution.
    WaitForMany2.JPG

    BTW, this question fits better in "Programming" as it a programming question and isn't EV3 specific (NXT works the same way).
    Last edited by Dean Hystad; 04-17-2018, 05:32 PM.

    Comment


    • #3
      Thank you for the answer, and sorry for the placement issue.

      Comment


      • #4
        Don't be sorry, it's just that you get better responses the better you place your post.

        Comment

        Working...
        X