Datasheet

Chapter 4: Navigation Tips ยท Page 171
state machines". However, the term "state machine" is commonly used to refer to finite
state machines.
Your SumoBot is without a doubt, a state machine. The last couple of example programs
have used terms like "State = search pattern" and "State = track front left object" in the
comments. The IR object detectors sense conditions, and the SumoBot's embedded
BASIC Stamp executes a program that interprets each new condition and makes the
transition to the correct state. Of course, the SumoBot reads the sensors and transitions
between states because the PBASIC program it runs makes it do that.
This activity examines how PBASIC code can make the SumoBot transition from one
state to the next based on sensor input. This activity also introduces a visual aid for
planning the SumoBot's states and transitions - the state diagram.
A Simple State Diagram and Program
Figure 4-9 shows an example of a simple state diagram. Each circle signifies a state that
the SumoBot can operate in. Both states are labeled,
LED Off and Blink LED. Some of the
arrows curve around and point back to the same state while other arrows point to the
other state. These arrows represent state transitions. Each state transition arrow is
labeled with a condition, like
pbSense = 0 or pbSense = 1. The reset condition is the
arrow with the jagged shaft labeled
Reset, and it indicates that this system will start in the
LED Off state.
Figure 4-9
Simple State
Machine Diagram
The curved arrow that keeps returning to the
LED off state labeled pbSense = 0 indicates
that so long as
pbSense stores zero, the state machine will just keep transitioning back to
the LED off state. The arrow that points from
LED Off to Blink LED shows that when the
condition is
pbSesne = 1, the state machine will transition from the LED off state to the
Blink LED state. The Blink LED state also has two transition arrows, one that keeps it in