Docsity

Finite State Machines: Understanding Mealy and Moore FSMs and Extended State Machines, Diapositivas de Robótica

Vista previa parcial del texto

¡Descarga Finite State Machines: Understanding Mealy and Moore FSMs and Extended State Machines y más Diapositivas en PDF de Robótica solo en Docsity!

Robotics

Finite State Machines

Marco Della Vedova

Wednesday 4th^ November, 2015 15:

http://robot.unipv.it/toolleeo

Models of computation and abstract machines

In computer science, automata theory is the study of mathematical objects called abstract machines or automata and the computational problems that can be solved using them.

Automata comes from the Greek word αὺτόματα = “self-acting”

An abstract machine (a.k.a. abstract computer) is a theoretical model of a computer hardware or software systems. A model of computation is the definition of the set of allowable operations used in computation and their respective costs. It is used for:

  • measuring the complexity of an algorithm in execution time and/or memory space
  • analyze the computational resources required
  • software and hardware design

Turing Machine in complexity theory

Turing machines are not intended as a practical computing technology, but rather as a thought experiment representing a computing machine. It is believed that if a problem can be solved by an algorithm, there exists a Turing machine that solves the problem (Church–Turing thesis). Furthermore, it is known that everything that can be computed on other models of computation known to us today, such as a RAM machine, Conway’s Game of Life, cellular automata or any programming language can be computed on a Turing machine. Since Turing machines are easy to analyze mathematically, and are believed to be as powerful as any other model of computation, the Turing machine is the most commonly used model in complexity theory.

Finite State Machines (FSMs)

A Finite State Machine (a.k.a. finite state automaton) is an abstract device (simpler than a Turing machine), consisting of:

  • a set of states (including a start state),
  • an alphabet of symbols that serves as a set of possible inputs to the machine,
  • and a transition function that maps each state to another state (or to itself) for any given input symbol. The machine operates by being fed a string of symbols, and moves through a series of states according to the transition function.

Output? Different types of FSM are distinguished depending on

if the output is produced and how it is produced: before or after a transition.

Example of FSM: an edge-detector

The function of an edge detector is to detect transitions between two symbols in the input sequence, say 0 and 1. It does this by outputting 0 as long as the most recent input symbol is the same as the previous one. However, when the most recent one differs from the previous one, it outputs a 1. By convention, the edge detector always outputs 0 after reading the very first symbol. Thus we have the following input output sequence pairs for the edge-detector, among an infinite number of possible pairs:

inputs −→ outputs 0 1 1 1 −→ 0 1 0 0 0 1 1 1 1 0 −→ 0 1 0 0 0 1 1 0 1 0 1 0 −→ 0 1 1 1 1 1

Graphical representation of FSM using graphs

Edge-detector example

This graphical representation is knows as state diagram. A state diagram is a direct graph with a special node representing the initial state.

Exercise: math model of edge detector

What (Σ, Γ, S, s 0 , δ) are for the edge-detector FSM?

  • input alphabet Σ = ?{ 0 , 1 }
  • output alphabet Γ = ?{ 0 , 1 }
  • state space S = ?{A, B, C}
  • initial state s 0 = ?A
  • transition function δ =?...

Tabular representation of a FSMs’ transition function

The transition function δ : S × Σ → S × Γ can be represented by a tabular with states on the rows and inputs on the columns. In each cell there is a tuple s, γ indicating the next state and the output. For example, for the edge-detector FSM, the transition table is:

A B,0 C,

B B,0 C,

C B,1 C,

State machines as discrete dynamic system

Transitions between states govern the discrete dynamics of the state machine and the mapping of inputs to outputs. The FSM evolves in a sequence of transitions. We can number these transitions starting from 0 for the initial state. Specifically, let x : N → S to be a function that gives the state of an FSM at transition k ∈ N. Let u : N → Σ and y : N → Γ denote that input and output at each transition. Hence, x(0) ∈ S is the first input and y(0) ∈ Γ the first output. The dynamics of the state machine is given by: { x(0) = s 0 (x(k + 1), y(k)) = δ(x(k), u(k)) The previous system can be rewritten (in accordance to the standard notation for dynamical systems) as: { x(k + 1) = δ′(x(k), u(k)), x(0) = s 0 y(k) = δ′′(x(k), u(k))

When does a transition occur?

Nothing in the definition of a state machine constrains when it reacts. As a discrete system, we do not need to talk explicitly about the amount of time that passes between transitions, since it is actually irrelevant to the behavior of a FSM. Still, a FSM could be:

  • event triggered, in which case it will react whenever an input is provided, or
  • time triggered, meaning that it reacts at regular time intervals. The definition of the FSM does not change in these two cases. It is up to the environment in which an FSM operates when it should react.

Mealy FSM and Moore FSM

  • The distinction between Mealy and Moore machines is subtle but important.
  • Both are discrete systems, and hence their operation consists of a sequence of discrete reactions.
  • For a Moore machine, at each reaction, the output produced is defined by the current state (at the start of the reaction, not at the end).
  • Thus, the output at the time of a reaction does not depend on the input at that same time.
  • The input determines which transition is taken, but not what output is produced by the reaction.

With these assumptions, a Moore machine is strictly causal

Notion of causality

  • a system is causal if its output depends only on current and past output
  • in other words, in casual systems if two possible inputs are identical up to (and including) time τ , the outputs are identical up to (and including) time τ
  • in strictly casual systems if two possible inputs are identical up to (and not including) time τ , the outputs are identical up to (and not including) time τ

strictly causal systems are useful to build feedback systems

  • non-causal (acausal) systems depends also on future inputs (examples: population growth, weather forecasting, planning)
  • anti-causal systems depends only on future inputs

Mealy FSM vs Moore FSM

  • any Moore machine can be converted to an equivalent Mealy machine
  • a Mealy machine can be converted to an almost equivalent Moore machine
  • it differs only in that the output is produced on the next reaction rather than on the current one
  • Mealy machines tends to be more compact (requiring fewer states to represent the same functionality), and are able to produce an output that instantaneously responds to the input
  • Moore machines are used when output is associated with a state of the machine, hence the output is somehow persistent

Exercises

  • Convert the edge-detector Mealy FSM in an almost-equivalent Moore FSM.
  • Convert the CIAO-detector Moore FSM to an equivalent Mealy FSM.