Datasheet
Chapter 4: Navigation Tips · Page 173
Your Turn
Figure 4-10 shows a modified version of the state machine diagram that involves a
variable named
counter. Because of the 100 ms pause between repeats of the
DO...LOOP in PushubttonLed.bs2, the counter variable keeps the LED blink-time less
than or equal to 2 seconds (assuming the
counter starts at 1). It also ensures a 1 second
delay before the LED starts blinking again, even if you keep pressing the button.
Figure 4-10
Modified State
Diagram
√ Save PushbuttonLed.bs2 as PushbuttonLedYourTurn.bs2.
√ Modify the program so that it conforms to the state machine shown in Figure 4-
10. Hint: use loops like
DO UNTIL counter ≥ 10 inside the IF and ELSE
code blocks.
√ Run and test the program, and trouble-shoot code as needed.
Hybrid State Diagrams for SumoBot Code Visual Aids
Here is the Main Routine from FrontIrNavigation.bs2 (See Activity #2 in this chapter). If
you rigidly adhered to the format from Figure 4-9 to make a state diagram for this code
block, it would be pretty complicated. Certainly complicated enough to make it useless
as a visual aid for designing more complex navigation routines.
DO
IF irLF = AND irRF = 1 THEN ' Both?
maneuver = Forward ' State = Lunge forward
GOSUB Servos_And_Sensors
ELSEIF irLF = 1 THEN ' Just left?
counter = 0 ' State = track front left object
DO UNTIL (irLF = AND irRF = 1) OR counter > 15
maneuver = PivotLeft ' Pivot left 15
GOSUB Servos_And_Sensors
counter = counter + 1