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: | ||
== 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 MyCount = 0 TO EndLoop6 | |||
PULSOUT Left, LeftStop + 50 | |||
PULSOUT Right, RightStop – 50 | |||
PAUSE 20 | |||
NEXT | |||
FOR MyCount = 0 TO Turn | |||
PULSOUT Left, LeftStop + 50 | |||
PULSOUT Right, RightStop + 50 | |||
PAUSE 20 | |||
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 Right, RightStop + 50 | |||
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]] | |||