What Is The Meaning Of Finite State Machines (FSM)? How FSM Works With Examples

In the modern era, Finite State Machines (FSMs) are soon going to be foundational models in the field of engineering and computer science. The machines will also play a role in enhancing the functionality and efficiency of several systems. Companies will also think about setting up these machines for industrial automation when the team is busy with firmware development. So, through this article, you will know more about Finite State Machines which is part of Computer Aided Engineering, how they work, and how they are used for different purposes.

What is FSM – Finite State Machine?

A Finite State Machine refers to a model that is used for designing and describing the behavior of systems with distinct steps following one after the other. Such a type of model comprises many states, transitions between the states, and the actions related to every transition. This concept is used in many domains, like engineering, computer science, and more. A person can visualize the model as a graph in which the nodes represent the states and the lines between the nodes represent the transitions. Now, let’s take a look at an example that clearly speaks more about the Finite State Machine.

When you have a robot that operates on a PCB layout design, then the robot will perform an action based on a command. If the robot is idle and it receives a command to clean a certain space, then the FSM will tell the robot to move ahead with the ‘Cleaning’ process. Similarly, if the robot is moving across space and it suddenly comes across an obstacle, then the FSM will lead the robot to avoid the obstacle. In such an instance, the robot will change its path and avoid bumping into the obstacle.

To sum everything up,an FSM will control the overall behavior of the robot through different states, the actions in every state, and how it has to act based on the commands. This is synonymous with a rulebook that guides a certain system to make decisions and respond effectively to different situations. 


What Are the Types of FSM?

What Are the Types of FSM?

While FSMs are used in different domains, there are mainly four types of FSMs. These include the Deterministic Finite State Machine (DFSM), Non Deterministic Finite State Machine (NDFSM), Moore Machine, and the Mealy Machine. Now, let’s check out more about every type of machine with an example. 

DFSM – Deterministic Finite State Machine

In the case of such machines, you will observe at most one transition from one state to another with the command or input the machine receives. Now, let’s know more about the machine’s operation through an example of a vending machine. 

When you use a vending machine, you will observe that the machine has three states: idle, Idle, Selection and Dispense. The transition between the states is based on what command an individual presses. For instance, when an individual chooses a product at the time of the ‘Idle’ state, the machine moves ahead with the ‘Selection’ state. As soon as the individual confirms the selection of the product, the machine moves ahead to the ‘Dispense’ state. At that point in time, the individual receives the product that he or she had earlier selected. This shows that the DFSM transitions from one unique state to another with input taken into account. 

NDFSM – Non Deterministic Finite State Machine

When such machines operate, you will observe that a state is not uniquely determined depending on the command. Moreover, a non-deterministic FSM can also move ahead with numerous states at the same time. Here’s an example that describes the operation of an NDFSM. 

Let’s say you have taken an elevator from the ground floor and want to go to the third floor. When you press the appropriate button inside the elevator, it will first stop for a few seconds on the first floor, then on the second floor, and then go to the third floor. This implies that a NDFSM moves ahead with transitions one after the other for the same command. 

Moore Machine

As soon as you come across Moore machines, the outputs are entirely dependent on the current state and not on the inputs. While the transitions occur based on the inputs, the outputs are related to the states. To understand the operation of the Moore machines, let’s check the working of a doorbell system. 

Usually, a doorbell system works under two states: ‘Idle’ and ‘Ring’. When someone presses the doorbell, the ‘Idle’ state quickly changes to the ‘Ring’ state. Under the ‘Ring’ state, the individual will hear a ringing sound (output) till he or she releases the doorbell. After releasing the button, the system goes back into the ‘Idle’ state. So, through this example, you can observe that the outputs depend on the current state. The system doesn’t deliver an output based on the input. 

Mealy Machine

When you observe Mealy machines, then these define the states as well as transitions and also relate the outputs to every transition. The output, in the end, is dependent on the current state and the command that was initially given. Now, let’s go through the operation of the mealy machines through a turnstile system that operates with the insertion of coins. 

As you’re about to use a turnstile system, you will observe two states: ‘Locked’ and ‘Unlocked’. When the system is in the ‘Locked’ state and you insert a coin, it will move ahead to the ‘Unlocked’ state and will radiate a signal as an output. This signal will indicate that you can pass through the system. In contrast, if you try to pass the system under the ‘Locked’ state without inserting a coin, then the output signal will indicate that access is denied. Hence, with this example, you can clearly understand the behavior of the Mealy Machine because the final output (pass or access denied) is based on the current state and input from your end. 


How Does a Finite State Machine Work?

How Does a Finite State Machine Work?

A Finite State Machine (FSM) runs by moving from one state to the next. The operation is based on the input that an individual gives. Here are the various steps that explain the working of a Finite State Machine. 

01: Define System States

First and foremost, you need to define the states under which the machine can operate. For example, in the case of a washing machine, you will observe the states ‘Idle’, ‘Wash’, ‘Rinse’, and ‘Spin’.

02: Define System Transitions

Next, you have to define the transitions to proceed from one state to the next. These transitions depend on the input given by the individual. For example, when you observe a vending machine, it moves from the ‘Idle’ state to the ‘Selection’ state only when an individual chooses a certain product. 

03: Create a System State table Table Or Diagram

Now, you have to draw a diagram to represent the system state transitions along with the various states and the inputs. This will enable us to visualize how the FSM is actually operating in real-time. A transition table, on the other hand, can also be drawn with the current states in the rows and input events in the columns. Under the cells, you can state the subsequent state or the action. 

04: Initialization of FSM

At this step, you need to switch on the FSM, which is initially in the ‘Idle’ state. 

05: Receive, Process Input Event

Now, the machine has to receive an input or a command. This input will decide how the FSM will move ahead from its initial state. For example, if you select a product from a vending machine by pressing a suitable button, then the event is considered an input. 

06: Current State And Input Event

At this juncture, you have to determine the current state and the input. This data will confirm what action the FSM will take ahead. 

07: Refer State Transition

Afterward, you have to go through the table to check out the suitable transition depending on the current state and the input. The table will represent the action that the FSM has to take with the current state and input taken into account. 

08: Execute Actions

At this point in time, the machine acts according to the determined transition. For instance, if the vendor machine is in its ‘Idle’ state and you have pressed a button for selecting a product, then the FSM moves ahead with the ‘Selection’ state and makes it ready for dispensing the product. 

 09: Update FSM Current State

Now, the state is set to make the FSM move to the next state. This prepares the machine for the subsequent input event. 

#10 Continue The Process

During this step, you have to eventually continue the process by following the fifth step to the ninth step till you observe the desired behavior from the machine.

Now, let’s go through how the model of the FSM machine is used in different domains. 


Few Examples of FSM – Finite State Machines

Even when you may not interact with actual FSMs, these are widely used within various systems. The steps that we have explained above enable us to manage and control the system effectively. 


Elevator control system

The overall operation of an elevator can be represented through an FSM. When you stand in the elevator, you will notice the states ‘Idle’, ‘Moving Up’, ‘Moving Down’, and ‘Halt’. The transition from one state to another occurs when an individual presses the buttons and the elevator reaches a certain floor. The FSM ensures that the elevator moves in an upward direction to the desired floors. Besides, the machine also ensures the opening and closing of doors in certain instances. 


Home automation

With the prevalence of home automation and IoT, FSMs are employed in SMART home systems. Such machines help to control the operation of devices like security systems, thermostats, and electronic appliances. But, when FSMs are integrated seamlessly with hardware & electrical design taken into consideration, these help to automate tasks, improve energy efficiency, and adjust the settings based on the user’s preferences. 


Robotics and autonomous systems

FSMs play a vital role in controlling the operation of many robots. Once the model is incorporated into robots and autonomous systems, it can control navigation and other tasks depending on certain rules and the inputs of the sensor. Owing to this, such machines are widely used in many processes observed in the manufacturing sector. Besides controlling complex workflows, these help to gain control over the production process and the robotic systems. By streamlining the various operational activities, FSMs can help to allocate resources effectively, synchronize several processes, and detect faults. 

Finally, FSMs are going to evolve in the future with technological advancements. These will offer a structured approach while controlling many systems and helping to govern the tasks in many industrial segments. While these machines will guide the flow of control, they will ensure a smooth user experience. In addition, Finite State Machines will play a crucial role in presenting control logic in the case of embedded systems.

Leave a Reply

Your email address will not be published. Required fields are marked *