Introduction to Robotics/Control Flow/Lab/Students: Difference between revisions

wikademia>Whiteknight
No edit summary
wikademia>Eme
No edit summary
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Introduction to Robotics/Nav|Control Flow}}
== Note ==
== Note ==


Line 9: Line 7:
To move our BoeBot in a square, we could write a nested FOR / NEXT loop. Remember to define your constants from the previous lab!
To move our BoeBot in a square, we could write a nested FOR / NEXT loop. Remember to define your constants from the previous lab!


FOR MyTurns = 0 TO 4
FOR MyTurns = 0 TO 4
FOR MyCount = 0 TO EndLoop6
    FOR MyCount = 0 TO EndLoop6
PULSOUT Left, LeftStop + 50
        PULSOUT Left, LeftStop + 50
PULSOUT Right, RightStop – 50
        PULSOUT Right, RightStop – 50
PAUSE 20
        PAUSE 20
NEXT
    NEXT
FOR MyCount = 0 TO Turn
    FOR MyCount = 0 TO Turn
PULSOUT Left, LeftStop + 50
        PULSOUT Left, LeftStop + 50
PULSOUT Right, RightStop + 50
        PULSOUT Right, RightStop + 50
PAUSE 20
        PAUSE 20
NEXT
    NEXT
NEXT
NEXT


This code uses a loop to move the BoeBot forward, and a loop to turn the BoeBot to the right. The outer loop repeats this process 4 times. When nesting loops, you must use different counter variables.  
This code uses a loop to move the BoeBot forward, and a loop to turn the BoeBot to the right. The outer loop repeats this process 4 times. When nesting loops, you must use different counter variables.  
Line 61: Line 59:


  FOR MyCount = 0 TO EndLoop12 * 12
  FOR MyCount = 0 TO EndLoop12 * 12
PULSOUT Left, LeftStop + 65
    PULSOUT Left, LeftStop + 65
PULSOUT Right, RightStop + 50
    PULSOUT Right, RightStop + 50
PAUSE 20
    PAUSE 20
  NEXT
  NEXT
  RETURN
  RETURN
Line 70: Line 68:


Demonstrate this for your instructor. The instructor may want to check your code to ensure that you have not changed or deleted any of the above code.
Demonstrate this for your instructor. The instructor may want to check your code to ensure that you have not changed or deleted any of the above code.
__NOTOC__
[[Category:Introduction to Robotics]]