GMU:StateMachine

From Medien Wiki

How can we tell a machine how to react to different situations and stimuli ?

Introduction

The state machine is an important concept in theoretical Computer Science. The following article explains how this concept can be used to program and organize different actions of simple robots.


Apparently there are:

  • different reactions (outputs)

—> a robot can for instance move forward and backward, it can turn right or left and it can stand still.

  • different stimuli (inputs)

—> a robot can for instance sense an obstacle (a wall), a human, …

  • different situations (states)

—> a robot can for instance be looking for a power plug, it can be running away from an opponent or it can be in resting mode.


We can imagine that only one possible output (action) is not enough to react to a diversity of inputs (stimuli) - It might be a good idea to move towards the closest wall if we are looking for a power plug. At the same time this would be rather bad if we are being chased by a prosecutor. We can also imagine that a suitable program can easily get quite complex and messy. Furthermore there is a good chance that some important relations between situations and reactions get lost in the programming process.

So how can we make the whole thing a bit clearer?


Structure

A good way to deal with the possible complexity of such a program is to draw a corresponding diagram.

There is another useful concept in theoretical Computer Science that can help us doing that: It says that it is enough to conduct only one predefined action (output) in reaction to the current situation (state) and to then look at the input data in order to analyze and decide the next situation (and so forth..). This kind of action pattern (Moore Machine) can be used in order to disassemble, restructure and consequently simplify similar sequences of much higher complexity (Mealy Machine).

And how can we use this strategy for our diagram?


We simply need to write down and structure the following things:


  • every possible situation (state)

—> hungry, looking for food, eating, ..

  • the particular conditions in which the situation (state) is changed

—> if sleeping and getting hungry -> looking for food, if looking for food and food has been found -> eating, ..

- a list that includes every situation (state) in connection to one specific action (output) that is carried out as soon as the corresponding state arrives —> looking for food / move around, eating / stop, ..