A state machine is really a simple concept. Lets say you wanted to design a state machine to, oh lets just pick some random example, find a tetrahedron and place it on a bigger one. I know this seems like a farfetched example, but it's all I can think of right now. So in order to create a state machine you break this task up into various parts:
- Determine location of tetrahedron
- Place robot within grabbing range of tetrahedron
- Grab tetrahedron
- Move within capping range of goal
- Put arm in proper location for capping
- Cap!
This seems obvious right. But when you are programming a robot you can't just write out a long program of actions and run it straight through, you need to do things every cycle. This is where state machines come in. One way you could do this is to have a global variable containing the current state of the robot, and then a big switch statement with different actions for each state. Somewhere in the code for each state we have code that advances the state if a certain condition is met. Example: A sensor in your gripper has detected that the tetrahedron has been grabbed, so you want to move on to the next state. Simple concept right? State machines can do very complex things, and states don't nessicarily have to go in order. There are whole feilds of mathematics dedicated to state machine analysis.