You are on page 1of 12

NAME: DIVYENDU VIMAL

REG. NO.: 21BPS1487


COURSE CODE: BCSE429P
COURSE TITLE: CYBER PHYSICAL SYSTEM LAB
FACULTY NAME: PRIYADARSHINI R

Experiment-10: FSM (Finite State Machine)


Aim:
The aim of this laboratory experiment is to utilize the Ptolemy simulation
environment to explore Finite State Machines (FSM) through the implementation and
analysis of three distinct models: the Capricious Thermostat, Extended FSM, and
Hierarchical FSM. Through this experiment, we aim to deepen our understanding of
FSM principles, their practical applications, and the capabilities of Ptolemy for
modelling complex systems. By simulating each FSM model and examining their
behaviour under varying input conditions, we seek to gain insights into state
transitions, system dynamics, and the comparative advantages of hierarchical FSM
structures. Ultimately, this investigation aims to elucidate the effectiveness and
potential limitations of FSM modelling techniques within the context of Ptolemy
simulations.

Software Required:
Ptolemy

Introduction:
Finite State Machines (FSMs) represent a fundamental concept in computer science
and engineering, offering a formalism for modelling and understanding systems with
discrete states and transitions. FSMs find extensive applications in various fields,
including digital circuit design, control systems, protocol specifications, and software
engineering. At their core, FSMs consist of a finite number of states, transitions
between these states triggered by input events, and associated actions or outputs.
Ptolemy is a versatile simulation environment widely used for modelling and
analysing complex systems, including FSMs. Its graphical interface and extensive
library of modelling components make it a powerful tool for exploring the behaviour
of FSMs in a simulated environment. Ptolemy supports the creation of FSM models
through its intuitive graphical interface, allowing users to define states, transitions,
input events, and output actions in a visual manner.
In this experiment, we aim to leverage the capabilities of Ptolemy for the analysis of
FSMs by implementing and simulating three distinct FSM models: the Capricious
Thermostat, Extended FSM, and Hierarchical FSM. By utilizing Ptolemy, we can
observe and analyse the dynamic behaviour of these models under various input
conditions, gaining insights into their state transitions, system dynamics, and overall
functionality. This experiment serves to deepen our understanding of FSMs and their
practical applications while also exploring the effectiveness of Ptolemy as a
simulation tool for FSM modelling.
Procedure:
1.Launch Ptolemy Software: Begin by opening the Ptolemy software on your
computer system.

2.Open Example Models: Navigate to the "Examples" or "Library" section within


Ptolemy software and locate the pre-built FSM example models. These models may
be organized under different categories, such as "Finite State Machines" or "Control
Systems."

3.Select Capricious Thermostat Model: Choose the Capricious Thermostat example


model from the available options. This model typically demonstrates a simple FSM
representing the behaviour of a thermostat with unpredictable temperature changes.

4.Load the Model: Load the Capricious Thermostat model into the Ptolemy
simulation environment by double-clicking on the model file or selecting it and
clicking "Open."

5.Review Model Components: Familiarize yourself with the components of the


Capricious Thermostat model, including states, transitions, input events, and output
actions. These elements are typically represented graphically within the Ptolemy
interface.

6.Configure Inputs and Parameters: Depending on the specific model, configure


any input parameters or initial conditions required for simulation. These may include
temperature thresholds, timing parameters, or other relevant settings.

7.Run Simulation: Initiate the simulation of the Capricious Thermostat model by


clicking on the "Run" or "Simulate" button within the Ptolemy interface. Observe the
behaviour of the FSM as it transitions between states in response to simulated input
events.
8.Analyze Results: After the simulation completes, analyse the results to understand
the behaviour of the Capricious Thermostat model. Pay attention to state transitions,
output actions, and any observed patterns or anomalies.
1. Capricious Thermo-state:

 Flow Diagram:

 Actor Diagram:
 Sample code:

 Director:
 Output:

2. Extended FSM:
A simple example of an extended state machine. In this example, the FSM has a parameter
called count. The transition from the initial state init to the counting state initializes count to 0
in its set action. The counting state has two outgoing transitions, one that is a self-transition,
and the other that goes to the state called final. The self-transition is taken as long as count is
less than 5. That transition increments the value of count by one in its set actions. In the firing
after the value of count reaches 5, the transition to final is taken. At that firing, the output is
set equal to 5. In subsequent firings, the output will always be 5, as specified by the self-loop
on the final state. This model, therefore, outputs the sequence -1,-2,-3,-4,-5,-6,5,5,5,5.
 Flow Diagram:

 Actor Diagram:
 Sample code:

 Director Inference:
We have used a SDF Director for this FSM model with the parameters as under. It run
for 10 iterations which is very well justified by the output.
 Output:

3. Hierarchical FSM:
 Flow Diagram:
 Actor Diagram:
 Sample code:

 Director:
 Output:

 Inference:
In conclusion, utilizing Ptolemy software for modelling and simulating Finite State Machines
(FSMs) provides valuable insights into system behaviour and dynamics. Through the analysis
of pre-built example models such as the Capricious Thermostat, Extended FSM, and
Hierarchical FSM, we gain a deeper understanding of FSM principles and their practical
applications. Ptolemy's intuitive interface and simulation capabilities enable efficient
exploration of FSM behaviour, allowing for the identification of patterns and differences
between models. This experience underscores the effectiveness of Ptolemy as a tool for FSM
analysis and highlights its potential for studying complex systems in various engineering
domains.

You might also like