You are on page 1of 4

Design of a Neural Network Function Block for

Insertion into the Function Block Library of a


Programmable Logic Controller
Armando Fermín-Pérez Enrique Sebastián Jesús Sullcarayme
Facultad de Ingeniería Facultad de Ingeniería Facultad de Ingeniería
Universidad Tecnológica del Perú Universidad Tecnológica del Perú Universidad Tecnológica del Perú
Lima, Perú Lima, Perú Lima, Perú
2022 IEEE Engineering International Research Conference (EIRCON) | 978-1-6654-5082-9/22/$31.00 ©2022 IEEE | DOI: 10.1109/EIRCON56026.2022.9934103

https://orcid.org/0000-0001-5606-7309 1622941@utp.edu.pe U17209410@utp.edu.pe

Abstract— This paper shows the design of a function block II. METHODOLOGY
containing a neural network to be inserted into a function block
library of a programmable logic controller to be used in an The process of designing a function block containing a
industrial process control application. First, the neural network neural network for use in industrial control applications with
was designed and trained based on the previous behavior of a programmable logic controllers is based on a generic
proportional, integral and derivative controller; then it was methodology as follows:
implemented in a function block, and inserted into the function
block library of a programmable logic controller; finally the
- Choose a plant to control.
behavior of a proportional, integral and derivative controller - Determine the mathematical model of the chosen plant.
was compared with another based on a neural network.
- Implement a closed loop controller with a PID function
Keywords—Programmable logic controller, neural network, block in the PLC.
multi-layer perceptron, function block.
- Design and train a neural network model based on the
I. INTRODUCTION behavior of the PID algorithm.
With the advent of Industry 4.0, the improvement of - Implement a closed-loop controller with a neural network
hardware and software technology used in all types of function block in the PLC.
applications, especially in the automation of industrial
A. Choose a plant to control
processes, is ostensible [1][2][3]. Industrial and
manufacturing processes are vital in the world economy and A water level tank plant model [11][12][13] was chosen
in the development of society, seeking a series of basic from the plant models predesigned by Factory I/O© [14]
products for daily work, health care, food with processed simulation software as shown in Fig. 1.
products, among other activities [4][5].
There has always been a desire to adequately control the
various industrial and manufacturing processes in which the
design of automatic control systems is strategic for the
business. The development of new control strategies and their
application are made possible by technological advances;
although a control strategy such as the classic proportional,
integral, derivative (PID) controller is still the most widely
used, as it is still sufficient to control processes, based on data
collected by sensors and set points established by the user. Fig. 1. Chosen plant.
One of these control strategies used when it is difficult to have
a good process control with PID algorithms, is to use artificial The plant has a level sensor, two control valves (loading
intelligence algorithms, such as the widely known fuzzy logic and unloading), for both cases the system is 0-10V analog
algorithm, and those based on neural networks, which are control, and the simulation works as an integer from 0 - 27648,
increasingly used as better industrial controllers. [6][7][8][9]. but to avoid any confusion within the programming it was
chosen to work in percentage ranges 0 - 100%.
In the industry, the use of PLCs is standard because it is a
device specially designed for industrial environments, it is B. Determine the mathematical model of the chosen plant
robust, it works in real-time, its hardware is highly reliable, The tank level control system [15] consists of an inlet
the software applications make use of a standard programming valve, an outlet valve and a tank, where the objective is to
model. IEC 61131-3 [10] states that programming model for control the height of the liquid in the tank as shown in Fig. 2.
PLCs can be implemented with (1) structured text, (2)
instruction list, (3) ladder diagram, (4) function block
diagram, (5) sequential function chart.
Thus, this research focuses on the design of a function
block containing a neural network to be used instead of the
classical PID function block when it is more difficult to
achieve adequate control of a process, usually in the case of
nonlinear systems. Fig. 2. Water level tank

978-1-6654-5082-9/22/$31.00 ©2022 IEEE

Authorized licensed use limited to: RENACyT Perú. Downloaded on December 19,2022 at 20:06:22 UTC from IEEE Xplore. Restrictions apply.
Considering that: Where X1: Input 1, X2: Input 2, Y1: Output of neural
.
network, V: Input weight, W: Output weight.
1 , ,
Considering Tangent-Sigmoid as the activation function,
Where F1(t) is inlet flow in (m3/s), F2(t) is outlet flow in we have the following equations:
(m3/s). A is tank area (m2), H is height in (m). So, system First stage. Input - Hidden layer.
transfer function is:
!
2
1 2 1 !

And transfer function of valve is: # # # ! #

0.133 $ $ $ ! $

3 1 !
C. Implement a closed loop controller with a PID function !
% % % %
block in the PLC
& & & ! &
The PID controller was designed using Simulink© [16], as
shown in Fig. 3 and Fig. 4. ' ' ' ! '

( ( ( ! (

!
Second stage. Hidden layer. Neurons.
)1 * 1 2/ 1 ,- 1
)2 * 2 2/ 1 ,- 1
Fig. 3. PID controller. )3 * 3 2/ 1 , - #
1
The PID function block was configured using the TIA )4 * 4 2/ 1 , - $
1
Portal© [17] from Siemens© [18] as shown in Fig. 4.
)5 * 5 2/ 1 ,- 1
- %
)6 * 6 2/ 1 , 1
- &
)7 * 7 2/ 1 , 1
)8 * 8 2/ 1 ,- '
1
- (
)9 * 9 2/ 1 , 1
-
)10 * 10 2/ 1 , 1
Third stage. Hidden layer – Output
4 ) 5 ) 5 )# 5 # )$ 5 $ ) 5 )% 5 %
)& 5 & )' 5 ' )( 5 ( ) 5
!
Fig. 4. PID function block.
Fourth stage. Output
D. Design and train a neural network model based on the
2
behavior of the PID algorithm 61 * 41 1
1 , -7
A multilayer perceptron neural network was designed with
2 inputs, a hidden layer with 10 neurons and 1 output. For training:
error: desired output – MLP output
8 ,99:9 , 8 ; ;7
Weight updating with delta rules:
8 ; ;7 , <: learning E:,**FEF,)
H I I K I
G G , L
J J J K

Matrices are made from Simulink© [16]:


Input matrix 2x796 and output matrix 1x796
where:
Fig. 5. Multi-layer Perceptron. Input: Set Point – Error, Output: PID output.

Authorized licensed use limited to: RENACyT Perú. Downloaded on December 19,2022 at 20:06:22 UTC from IEEE Xplore. Restrictions apply.
Once the matrices were available, the MLP neural network
was designed with the nntool© [19] from Matlab© [20]. Once
the inputs, outputs and the structure of the neural network
structure were configured as shown in Fig. 6. The MLP neural
network was trained using the nntraintool© [21] from
Matlab© [20].

Fig. 6. Input-Output neural network structure.

E. Implement a closed-loop controller with a neural


network function block in the PLC
The MLP neural network function block was created using
TIA Portal© [17] from Siemens© [18] as shown in Fig. 7.

Fig. 9. Multi-layer Perceptron training dispersion.


The simulation was performed in Factory I/O©, operating
the left tank with a PID controller and the right tank with a
MLP neural network controller, as shown in Fig. 10.

Fig. 7. MLP neural network function block.

The creation of the internal segments of MLP neural


network function block uses the TIA Portal© functions
CALCULATE, NEG, EXP, NORM_X and SCALE_X to
generate and normalize the mathematical function of the
“Valve_opening” output in relation to the sensor inputs, taking
into account the Tangent-Sigmoid activation function.
The process of inserting the neural network function block
into the function block library of the programmable logic
controller makes use of Libraries tool of TIA Portal©. After
opening the Libraries tool, the Global Libraries option is Fig. 10. MLP left tank vs. PID right tank.
selected to create a new global library, and then the new Results shown that MLP controller is quicker than PID
function block is saved in the master copy folder within this controller to get settling time so, it is a better controller for this
new global library, ready to be used. study case as shown in Table I and Fig. 11.
III. RESULTS TABLE I. PID AND MLP CONTROLLERS
The multilayer perceptron training results show good Parameters PID MLP
dispersion behavior and small errors for 1000 epochs, as Settling time 6 min 28 sec. 4 min. 15 sec.
shown in Fig. 8 and Fig. 9. Tank level 99.87 % 100.0 %
Input valve opening 57.20 % 59.32 %

Fig.8. Multi-layer Perceptron MSE Error. Fig.11. PID and MLP controllers: Response times and input valve openings.

Authorized licensed use limited to: RENACyT Perú. Downloaded on December 19,2022 at 20:06:22 UTC from IEEE Xplore. Restrictions apply.
IV. CONCLUSIONS Comput. Theor. Nanosci., vol. 12, no. 7, pp. 1292–1299, Jul. 2015,
The use of a function block with a PID algorithm remains, doi: 10.1166/jctn.2015.3889.
by default, a good choice for automatic control applications [9] H. Huan, H. Tian, Z. Yan, and Z. Yao, “Group control elevator
due to its ease of use, in addition to being included as a dispatching system based on S7-1200 PLC,” in 2019 Chinese
function block already programmed in all programmable logic Automation Congress (CAC), Nov. 2019, pp. 3853–3857, doi:
controller programming environments; in contrast, a function 10.1109/CAC48633.2019.8996971.
block containing a neural network is not included in the
[10] K. Thramboulidis, “IEC 61499 vs. 61131: A Comparison Based on
function block library of a programmable logic controller.
Misperceptions,” J. Softw. Eng. Appl., vol. 6, no. 8, pp. 405–415,
A neural network function block can be used instead of a 2013.
function block with a classical PID algorithm in situations
[11] H. Mamur, I. Atacak, F. Korkmaz, and B. M.R.A., “Modelling and
where a fast response time is desired, for example, but taking
into account that one must have adequate knowledge of the Application of a Computer-Controlled Liquid Level Tank System,”
design, training and operation of a neural network, as well as in Computer Science & Information Technology (CS & IT), Jan.
having technological tools to do so. 2017, vol. 2003, pp. 97–106, doi: 10.5121/csit.2017.70210.
[12] A. R. Pérez R., A. A. De Conno C., and A. D. Enriquez P.,
From the experiment it is observed that, for this case study,
a neural network as implemented with a multilayer perceptron “Desarrollo de un sistema de control adaptativo tipo programador de
had an establishment time of the closed-loop control system ganancia para la regulación del nivel en un tanque esférico,” Rev.
approximately 35% faster than with a PID algorithm, and that Ing. UC, vol. 16, no. 3, pp. 34–44, 2009.
in both the steady-state errors were similar. It was also [13] M. Balaji and K. Porkumaran, “An online BPN gain adapter for PID
observed that in the control system with PID algorithm, the through PLC on a conical tank system,” in 2016 IEEE Region 10
opening and closing of fluid inlet valve fluctuated Conference (TENCON), Nov. 2016, pp. 2971–2975, doi:
permanently around the final value reached, but in the case of 10.1109/TENCON.2016.7848590.
the control system with the multilayer perceptron the opening
and closing of the inlet valve had a much smaller frequency [14] Real Games, “Next-Gen PLC Training. 3D Factory simulation,”
fluctuation, resulting in a longer actuator lifetime. 2022. https://factoryio.com/ (accessed Aug. 18, 2022).
[15] L. Zhao, “Single tank liquid level control based on improved BP
Future work consists of performing more experiments
with tanks of other dimensions and other neural network neural network PID control algorithm,” in 2013 IEEE Third
architectures, to compare their advantages and difficulties in International Conference on Information Science and Technology
closed-loop control systems, taking advantage of the fact that (ICIST), Dec. 2013, pp. 230–232, doi: 10.1109/ICIST.2013.6747541.
modern PLCs have greater computing power, in addition to [16] The MathWorks Inc., “Simulink. Design. Simulate. Deploy.,” 2022.
the possibility of connecting them with high-level languages. https://www.mathworks.com/products/simulink.html (accessed Aug.
18, 2022).
REFERENCES
[17] Siemens, “Totally Integrated Automation Portal,” 2022.
[1] M. A. Sehr et al., “Programmable Logic Controllers in the Context
https://new.siemens.com/global/en/products/automation/industry-
of Industry 4.0,” IEEE Trans. Ind. Informatics, vol. 17, no. 5, pp.
software/automation-software/tia-portal.html (accessed Aug. 18,
3523–3533, May 2021, doi: 10.1109/TII.2020.3007764.
2022).
[2] D. M. Carpio Holguin, “Desarrollo de un controlador neuro difuso
[18] Siemens, “SIEMENS,” 2022.
sobre un sistema embebido y monitoreo remoto de variables a través
https://www.siemens.com/global/en.html (accessed Aug. 18, 2022).
de una plataforma IoT. Aplicación al control de velocidad de un
[19] The MathWorks Inc., “Help Center. nntool,” 2022.
motor de corriente directa.,” no. 277. pp. 1–16, 2022.
https://www.mathworks.com/help/deeplearning/ref/nntool.html
[3] A. Ghosh, G.-N. Wang, and J. Lee, “A novel automata and neural
(accessed Aug. 18, 2022).
network based fault diagnosis system for PLC controlled
[20] The MathWorks Inc., “MATLAB,” 2022.
manufacturing systems,” Comput. Ind. Eng., vol. 139, no. November
https://www.mathworks.com/products/matlab.html (accessed Aug.
2019, p. 106188, Jan. 2020, doi: 10.1016/j.cie.2019.106188.
18, 2022).
[4] D. Baptista and F. Morgado-Dias, “Artificial Neural Networks: A
[21] The MathWorks Inc., “Help Center. nntraintool,” 2022.
Review of Training Tools.” 2012.
https://www.mathworks.com/help/deeplearning/ref/nntraintool.html
[5] B. Joshi, “Application Of Neural Network On PLC-based
(accessed Aug. 18, 2022).
Automation Systems For Better Fault Tolerance And Error
Detection,” 2019.
[6] M. U. Adam, M. H. Ali, and S. L. Dhar, “Determination of the
Performance of Neural PID, Fuzzy PID and Conventional PID
Controllers on Systems with Several Overshoots,” Int. J. Adv. Res.
Sci. Eng., vol. 3, no. 1, pp. 791–799, 2015.
[7] H. Alshareefi, C. Lupu, L. Ismail, and L. Duc Luu, “The design and
testing of a neural controller based on artificial neural network
theory using LABVIEW facilities,” UPB Sci. Bull. Ser. C Electr.
Eng. Comput. Sci., vol. 83, no. 3, pp. 35–46, 2021.
[8] K. Chen, J. Wang, Z. Sun, J. Luo, and T. Liu, “Programmable Logic
Controller Stage Programming Using Spiking Neural P Systems,” J.

Authorized licensed use limited to: RENACyT Perú. Downloaded on December 19,2022 at 20:06:22 UTC from IEEE Xplore. Restrictions apply.

You might also like