Modified on
12 May 2023 12:11 pm
Skill-Lync
Control logic is a paramount part of a software program that controls the operations of the program. The control logic answers to commands from the user, and it also acts on its own to execute automated tasks that have been structured into the program. It is also known as the controller and is part of the underlying software architecture developed at the same time that the program is designed and coded.
The control logic can be modeled using a state diagram, which is a form of a hierarchical state machine. These state diagrams can also be merged with flow charts to provide a set of computational semantics for describing complex control logic. Control logic is the part of a controller that defines how a reactive system responds to events or conditional changes.
Applications for control logic include:
Common tasks for modeling control logic include:
New programming methods:
A Programmable Logic Controller (PLC) is an industrial process control computer that has been adapted to control the manufacturing process since all manufacturing processes are modernized and automated by adopting this technology.
PLCs from various manufacturers can be programmed in diverse ways. IEC 61131-3 is the international standard for programmable logic controllers.
The most general PLC programming methods used are:
Finite State Machine
Finite State Machine (FSM) is a formulation used to describe the processes during which information or tasks move from one state to another for action according to a set of rules. The system makes a transition from one state to another if the condition defining the change is true. A system where particular inputs cause particular changes in state can be represented using finite state machines. A state transition diagram is a graphical representation of a finite state machine. Hence, a finite state machine is a model of behavior composed of states, transitions, and actions.
For example, we can use a state machine to represent a car's automatic transmission. The transmission has operating states namely: park, reverse, neutral, drive, and low. When the driver shifts from one position to another, the system makes a transition from one state to another, which implies from neutral to drive in this cited example.
Conventionally, designers used truth tables to illustrate relationships among a finite state machine's inputs, outputs, and states. The resulting table describes the logic necessary to control the behavior of the system undergoing study. Another approach is to design an event-driven system to model the behavior of the system by describing it in terms of transitions among states. The occurrence of events under certain conditions determines the state that is active. State-transition charts and bubble charts are graphical representations based on this technique.
The below figure depicts an FSM model for a simple door control in which the door has two states: open and close. These two states can be mutually changed into each other depending upon transition conditions resulting from corresponding events.
Stateflow
'States' and 'transitions' form the basic building blocks of a sequential logic system.
Stateflow provides a graphical language that includes state transition diagrams, flow charts, state transition tables, and truth tables. We can use Stateflow to describe how MATLAB algorithms and Simulink models react to input signals, events, and time-based conditions. A Stateflow chart can utilize MATLAB or C as the action language to implement the control logic. We can also represent stateless flow charts.
Applications:
Stateflow enables us to design and develop supervisory control, task scheduling, fault management, communication protocols, user interfaces, hybrid systems, etc.
Now, let us get familiar with some of the primary terms.
1) States - One of the key concepts in computer programming is the idea of a state that is essentially a snapshot of the measure of various conditions in the system. A state stores information about the past; that is, a state reflects the input changes from the system's start to the present moment.
2) Action - An action is a description of the activity in a control system that is to be performed at a given moment and has an influence on something. In some cases, one action can include several sub-activities.
State actions define what a Stateflow chart does when a state is active. The most common types of state actions are entry, during, and exit actions.
3) Transition - A transition indicates a change between states and is described by a condition that is needed to be fulfilled to enable the transition.
Basically, ‘State’ and ‘transition’ are instructions we write inside or next to a transition to define how a given Stateflow chart will behave during the simulation.
Truth Table
It illustrates logical decision-making behavior using conditions, decisions, and actions.
The Truth Table block is a truth table function that uses MATLAB as the action language. When we want to use truth table logic directly in a Simulink model, use this block. This block requires Stateflow.
When we add a Truth Table block directly to a model instead of calling truth table functions from a Stateflow chart, these advantages apply:
With the aid of the Truth Table Editor, one can implement the following:
One Stateflow object can contain other Stateflow objects.
A Stateflow chart can contain sequential and combinatorial logic in the form of state transition diagrams, flow charts, state transition tables, and truth tables. One can include Stateflow charts as blocks in a Simulink model. The collection of these blocks in a Simulink model is the ‘Stateflow machine.’ Stateflow charts can contain states, boxes, functions, data, events, messages, transitions, junctions, and annotations. States, boxes, and functions can contain other states, boxes, functions, transitions, junctions, annotations, data, events, and messages. The level of nesting can be continued indefinitely.
Now, without further delay, let's discuss how a Stateflow chart is created in Simulink.
The vital components of the Stateflow Editor are the object palette, the chart canvas, and the Symbols pane.
(a) The chart canvas is a drawing area where we will now create a chart by combining states, transitions, and other graphical elements.
(b) On the left side of the canvas, the object palette displays a set of tools for adding graphical elements to our created chart.
(c) On the right side of the canvas, in the Symbols pane, we add new data to the chart and resolve any undefined or unused symbols.
(1) From the object palette, click the State icon and move the pointer to the chart canvas. A state with its default transition appears. To place the state, click a location on the canvas. When the text prompts, enter the state name ‘first’ and the state action, if any.
(2) Add another state. Right-click and drag the ‘first’ state. Blue graphical cues help us to align our states horizontally or vertically. The name of the new state changes to ‘last.’ Click on the state's name to change it now to ‘second.’
(3) Replicate the above step to form the state named ‘third’ and ‘fourth.’
(4) Realign the above states. Blue transition cues indicate several ways in which we can connect the states. To add transitions, click the appropriate cue.
(5) Alternatively, to draw a transition, click and drag from the edge of one state to the edge of the other state.
(6) Double-click each transition and type the appropriate transition condition. The conditions will appear inside the square brackets.
(7) Now, go to the 'Symbols Pane' option under the 'SIMULATION' tab on the tool strip and specify all the variables used in your model as either 'Input' or 'Output' so that the model gets to know the variables which you have employed.
Let us understand the above concept we came across by studying the following example.
Example 1:
Consider the below Stateflow problem. If the input value is less than 10, then the system outputs -30, and if the input is greater than 10, it outputs 20. Let’s get to know how to implement this in a state machine.
Approach:
(1) Open Simulink by going to the MATLAB Toolstrip. Click on New ----> Simulink Model ----> Create Model.
(2) Search for Chart and double-click inside it to go to the chart mode.
(3) Now follow the above-discussed steps to add States and Transitions.
(4) We will validate the input value against the set of conditions. Here we have created two states named ‘Max’ and ‘Min.’ Below, a control logic has been implemented in the chart mode of Simulink.
‘en’ keyword has been used to define the entry. We used an output variable named ‘value’ equal to 20. Similarly, ‘value’ equals -30 in the ‘Min’ state. Appropriate transition conditions have been given beside the arrows.
We created two variables, namely ‘input’ and ‘output’, in the Symbols Pane option under the Simulation tab.
Configuration of the Repeating Sequence block:
Here, we have employed definite output values for the different instant time values. Therefore, this will subsequently generate a repeating sequence of numbers as per the user input. We have added a Scope block to visualize the results of our implemented system.
The complete Simulink block has been depicted below, where we have inculcated the repeating sequence block as an input to the problem to gain a continuous result with respect to time.
Results:
After clicking the ‘Run’ in the Simulink toolbar, the below results are obtained from the scope block.
The red signals depict the values being given as input to our problem, and the blue signals illustrate the output obtained. We can clearly analyze that the plotted data is verified as per our pre-specified conditions.
Hope you got a brief cognizance regarding the implementation and the execution of a Stateflow problem in the MATLAB Simulink software.
Author
Navin Baskar
Author
Skill-Lync
Subscribe to Our Free Newsletter
Continue Reading
Related Blogs
The average vehicle body gives any vehicle its structural integrity, while the electric motor is concerned with the generation of torque or force. The electric motor can be a permanent magnet synchronous motor, brushless dc motor etc.
25 Aug 2022
In industrial control applications, a PID controller is a device that regulates temperature, flow, pressure, speed, and other process variables. PID (proportional integral derivative) controllers, which use a control loop feedback mechanism to control process variables, are the most accurate and trustworthy controllers.
27 Aug 2022
A lithium-ion (Li-ion) battery is a complicated battery technology that uses lithium ions as a key component of its electrochemistry. During a discharge cycle, lithium atoms within the anode are ionized and separated from their electrons.
29 Aug 2022
Dash in your car is your source of information. It basically functions as a control panel that sits in front of the driver and shows numerous controls and instrumentation required for your car to function.
01 Sep 2022
A hybrid vehicle has two power sources for motion within the same vehicle. Basically the hybrid vehicle is split into two types supported the source for propulsion - combustion engine type and Hydrogen power cell.
07 Sep 2022
Author
Skill-Lync
Subscribe to Our Free Newsletter
Continue Reading
Related Blogs
The average vehicle body gives any vehicle its structural integrity, while the electric motor is concerned with the generation of torque or force. The electric motor can be a permanent magnet synchronous motor, brushless dc motor etc.
25 Aug 2022
In industrial control applications, a PID controller is a device that regulates temperature, flow, pressure, speed, and other process variables. PID (proportional integral derivative) controllers, which use a control loop feedback mechanism to control process variables, are the most accurate and trustworthy controllers.
27 Aug 2022
A lithium-ion (Li-ion) battery is a complicated battery technology that uses lithium ions as a key component of its electrochemistry. During a discharge cycle, lithium atoms within the anode are ionized and separated from their electrons.
29 Aug 2022
Dash in your car is your source of information. It basically functions as a control panel that sits in front of the driver and shows numerous controls and instrumentation required for your car to function.
01 Sep 2022
A hybrid vehicle has two power sources for motion within the same vehicle. Basically the hybrid vehicle is split into two types supported the source for propulsion - combustion engine type and Hydrogen power cell.
07 Sep 2022
Related Courses