Software FSM

Software FSM
Beyond the Stepper Motor!
Motivation
• Allows standard implementation of complex
SW that depends heavily upon past history
(state)
• Easily supports non-blocking operation with
slower environment (event inputs)
• Can be structured in various ways. What’s the
best? Least code, easiest to understand
State-Centric
“Hidden” State Transitions
• Separate transitions
from FSM outputs
• More encapsulation,
fewer dependencies
• Before, each state must
“know” the appropriate
next state
• Instead, use a dedicated
next-state function
• Less clutter?
Event-Centric
State Pattern (OOP!)
Table-Driven
Table of Function Pointers
Table of Function Pointers
Sample State Function
Full Code