05347138.pdf

5
PLC Control and Matlab/Simulink Simulations. A Translation Approach Teresa Deveza *, J. F. Martins ** * Universidade de Évora, Évora, Portugal ** CTS/UNINOVA and FCT/UNL, Lisboa, Portugal [email protected]; [email protected] Abstract — This paper proposes a translation methodology to emulate PLC control program in the Matlab/Simulink environment. The translation package automatically translates the PLC control program into Matlab/Simulink software language. The PLC control program is translated into a Matlab function block, within the Matlab/Simulink environment, that will control the model of the industrial process as long as the simulation runs. The translation package inputs are: the type of PLC, the PLC’s number of inputs and outputs and the PLC control program file. The translation package output will be a Matlab/Simulink compatible m-file with the correspondent PLC control program translation. Universidade de Évora students are successfully using this package, so that they can test their PLC control programs together with Matlab/Simulink process models. Index Terms — Automation, Education, Industrial Control, Simulation, Modeling. I. INTRODUCTION The practical test of an automation and control process controlled by programmable logic controllers (PLC) is a well-known problem [1-3]. There are several solutions that can be implemented: scale models, batteries of led’s and switches and Human Machine Interfaces (HMI), Supervisory Control and Data Acquisition (SCADA) systems or simulation tools. The use of scale models of real processes is very expensive and difficult to adapt to different processes. There is no question that this is the best way to teach PLC controlled process, allowing the students to test their projects in an almost real environment, however their cost often prohibits its use. The use of led’s and switches sets is extremely confusing end uninteresting. This approach, only valid when small processes are considered, severely reduces the student’s motivation. Some HMI and SCADA systems allow this feature but there are very expensive, not intended for this purpose and usually consider property protocols. Some PC-based process simulation tools have been developed, using microcontroller technologies and designed to work with any type of PLC [4]. Other commercial PLC simulation tools are also available (PC-SIM, SIMTSX, PSIM just to name a few). However, often these solutions are not suitable to be integrated with other simulation tools. The use of Matlab/Simulink [5] has not been a regular approach for teaching industrial automation and PLC controlled processes. Assuming that the model of the industrial process is implemented in the Matlab/Simulink this paper presents a tool that can be used to implement the PLC control program in Matlab/Simulink environment. The basic idea is to consider the PLC control program as a Matlab function block, within the Matlab/Simulink environment, that will control the model of the industrial process as long as the simulation runs. The main objective of this work is to automatically translate the PLC control program, written as an instruction list, into Matlab/Simulink software language. II. INDUSTRIAL PROCESS MODELLING The implementation of an industrial production line involves a large investment. Every decision at the design stage should be made with extremely care in order to assure that the automated manufacturing process will successfully achieve the desired results. The problem of industrial process modeling is not easy or unique, and several approaches can be taken. These processes can be considered as a discrete event system, where the states of the dynamic system involved changes accordingly to the occurrences of various and distinct events. It is important, to keep the manufactures and process integrators competitiveness, that the industrial production systems keep being constantly improved. To achieve this objective an efficient modeling approach is a fundamental issue. A modern production line is a highly integrated system composed of automated workstations such as robots with tool-changing capabilities, a hardware handling system and storage system, PLC controlled processes, and a computer control system that controls the operations of the entire system. Every controlled industrial process can be modeled as a transfer function (continuous and/or discrete) with a set of inputs and a set of outputs, as presented in Fig. 1. The inputs refer to the control signals that are applied to the process actuators, and the outputs refer to the variables that are acquired through the process network of sensors and detectors. 978-1-4244-2728-4/09/$25.00 ©2009 IEEE

Transcript of 05347138.pdf

  • PLC Control and Matlab/Simulink Simulations. A Translation Approach

    Teresa Deveza *, J. F. Martins ** * Universidade de vora, vora, Portugal

    ** CTS/UNINOVA and FCT/UNL, Lisboa, Portugal [email protected]; [email protected]

    Abstract This paper proposes a translation methodology to emulate PLC control program in the Matlab/Simulink environment. The translation package automatically translates the PLC control program into Matlab/Simulink software language. The PLC control program is translated into a Matlab function block, within the Matlab/Simulink environment, that will control the model of the industrial process as long as the simulation runs. The translation package inputs are: the type of PLC, the PLCs number of inputs and outputs and the PLC control program file. The translation package output will be a Matlab/Simulink compatible m-file with the correspondent PLC control program translation. Universidade de vora students are successfully using this package, so that they can test their PLC control programs together with Matlab/Simulink process models.

    Index Terms Automation, Education, Industrial Control, Simulation, Modeling.

    I. INTRODUCTION The practical test of an automation and control process

    controlled by programmable logic controllers (PLC) is a well-known problem [1-3]. There are several solutions that can be implemented: scale models, batteries of leds and switches and Human Machine Interfaces (HMI), Supervisory Control and Data Acquisition (SCADA) systems or simulation tools. The use of scale models of real processes is very expensive and difficult to adapt to different processes. There is no question that this is the best way to teach PLC controlled process, allowing the students to test their projects in an almost real environment, however their cost often prohibits its use. The use of leds and switches sets is extremely confusing end uninteresting. This approach, only valid when small processes are considered, severely reduces the students motivation. Some HMI and SCADA systems allow this feature but there are very expensive, not intended for this purpose and usually consider property protocols. Some PC-based process simulation tools have been developed, using microcontroller technologies and designed to work with any type of PLC [4]. Other commercial PLC simulation tools are also available (PC-SIM, SIMTSX, PSIM just to name a few). However, often these solutions are not suitable to be integrated with other simulation tools.

    The use of Matlab/Simulink [5] has not been a regular approach for teaching industrial automation and PLC controlled processes. Assuming that the model of the industrial process is implemented in the Matlab/Simulink this paper presents a tool that can be used to implement the PLC control program in Matlab/Simulink environment. The basic idea is to consider the PLC control program as a Matlab function block, within the Matlab/Simulink environment, that will control the model of the industrial process as long as the simulation runs. The main objective of this work is to automatically translate the PLC control program, written as an instruction list, into Matlab/Simulink software language.

    II. INDUSTRIAL PROCESS MODELLING

    The implementation of an industrial production line involves a large investment. Every decision at the design stage should be made with extremely care in order to assure that the automated manufacturing process will successfully achieve the desired results.

    The problem of industrial process modeling is not easy or unique, and several approaches can be taken. These processes can be considered as a discrete event system, where the states of the dynamic system involved changes accordingly to the occurrences of various and distinct events. It is important, to keep the manufactures and process integrators competitiveness, that the industrial production systems keep being constantly improved. To achieve this objective an efficient modeling approach is a fundamental issue.

    A modern production line is a highly integrated system composed of automated workstations such as robots with tool-changing capabilities, a hardware handling system and storage system, PLC controlled processes, and a computer control system that controls the operations of the entire system. Every controlled industrial process can be modeled as a transfer function (continuous and/or discrete) with a set of inputs and a set of outputs, as presented in Fig. 1. The inputs refer to the control signals that are applied to the process actuators, and the outputs refer to the variables that are acquired through the process network of sensors and detectors.

    978-1-4244-2728-4/09/$25.00 2009 IEEE

  • Fig. 1. Industrial process model.

    Although Matlab/Simulink is not so often used in

    industrial processes modeling, this simulation package allows a comfortable modeling and simulation tool for continuous, discrete and mixed discrete/continuous sub-systems models. Nowadays, Matlab/Simulink covers a wide range of application areas and can also be used to build detailed process models in automation applications.

    III. PLC MODELING

    A PLC (Programmable Logic Controller) is basically composed by: power supply, control program and working memories, input/output circuits and a central control unit. PLCs are the most suitable and widely used technology in nowadays-industrial processes. A PLC can be seen as an integrated circuit that consists of logic elements with an interconnection pattern, parts of which are user programmable [6].

    A PLC emulates the behavior of an electric ladder diagram. As they are sequential machines, to emulate the workings of parallel circuits that respond instantaneously, PLCs use an input/output image table and a scanning cycle. When a control program is running, the PLC continuously executes a scanning cycle. The program scan solves the boolean logic related to the information in the input table with that in output and internal relay tables. In addition, the information in the output and internal relay tables is updated during the program scan. In a PLC, this boolean logic (PLC control program) is typically represented using a graphical language known as a ladder diagram [7]. However the PLC control program can be also described in text-oriented programming languages STL (Statement List) and SCL (Structured Control Language).

    The PLC modeling issue can be reduced to the emulation of the PLC control program. Several approaches can be taken regarding the PLC program. Several authors developed specific packages for the verification of the PLC program [8 - 9]. These packages verify the structure of the program using, among others, automata networks. Often these programs only verify the program structure without verifying if it achieves the desired control objectives. Other approach is the generation of the PLC program from other formalisms, such as petri nets [10], state diagrams or finite state machines. If the original formalism is error free this could be a valuable tool for developing PLC programs. Some authors developed software packages to translate PLC programs to DSP code, so that it can be used in non-PLC hardware [11].

    None of these approaches is usually education oriented or is intended to be used within the Matlab/Simulink environment. The proposed methodology approach will consider that the PLC is essentially modeled by emulating its control program, which interacts with the controlled industrial process itself, as presented in Fig. 2.

    INDUSTRIAL PROCESS

    PLC PROGRAM

    Process Outputs

    PLC Inputs

    Process Inputs

    PLC Outputs

    Fig. 2. PLC Control Program and Industrial Process interaction.

    The PLC control program is cyclic executed in the flowing way: the central control unit copies the state of the industrial process (PLC input circuits) into the internal working memory area, then executes the PLC control program stored in the control program memory area, and finally acts over the industrial process by transmitting its control actions through the output circuits to the industrial process actuators. This execution is made cyclically, as presented in Fig. 3.

    Systems operation

    Internal operation

    Input Circuits reading

    First instruction

    Second instruction

    Third instruction

    (n-1)th instruction

    nth instruction

    Systems operation Output Circuits writing

    PLC Control Program

    Fig. 3. PLC control program cyclic execution.

  • The PLC control program will generate outputs that will be the inputs of the industrial process, as the outputs of the industrial process will be the inputs of the PLC control program.

    IV. PLC/MATLAB TRANSLATION METHODOLOGY As stated before the proposed translation methodology

    assumes that the industrial process is already simulated in the Matlab/Simulink environment, as presented in Fig. 4.

    Fig. 4. PLC operation and Industrial Process interaction.

    The industrial PLC controlled process is simulated in a Matlab/Simulink block named Industrial Process Simulation Block. This block outputs (sensors and detectors outputs) are the process sensors and detectors signals, which will be used as inputs to the Matlab/Simulink block named PLC Control Program. This block will emulate the PLC operation and its outputs will correspond to the PLC outputs that will connect to the actuators input, in the Industrial Process Simulation Block.

    The block PLC Control Program is the keystone of the proposed methodology. It will emulate the PLC operation in the cyclic way that was presented in Fig. 3. This function block is a Matlab m-file.

    In order to automatically build this block the students must do the following:

    1. Read the functional specifications of the PLC-controlled process that they are intended to control;

    2. Copy the Matlab/Simulink Industrial Process Simulation Block, provided by the teacher, into the Matlabl/Simulink environment;

    3. Choose a PLC to control the process; 4. Elaborate the respective PLC control program

    accordingly to the given functional specifications, using for example the GRAFCET methodology;

    5. Write down the PLC control program using ladder diagrams or text-oriented programming languages;

    6. Save the PLC control program as a text-oriented programming language in a text file

    7. Run the proposed translation package in order to convert the PLC control program into the Matlab/Simulink language (Matlab/Simulink m-file function block PLC control program);

    8. Test the developed PLC control program with the given PLC-controlled process model (Matlab/Simulink m-file function block Industrial Process Simulation Block);

    9. Elaborate the respective work report. The proposed translation package, before automatically

    translate the students PLC control program into Matlab/Simulink language, will require from the students the following information:

    1. Type of PLC; 2. PLCs number of inputs and outputs; 3. PLC control program file for translation.

    A. Type of PLC The choice of the PLC type is essential for establishing

    the translation rules accordingly to the manufacturer program syntax. Although they are all boolean logic based, each PLC manufacturer develops its own programming syntax. In this way the translation package should know the PLC manufacturer in order to apply the adequate translation rules.

    B. PLCs number of Inputs and outputs The number of PLCs Inputs and Outputs clearly

    defines the arguments of the Matlab/Simulink function PLC Control Program (1). This function will be responsible for executing the PLC control program within the Matlab/Simulink environment, and will be created as a text m-file. di1 to din denote the PLCs digital inputs, ai1 to aim denote the PLCs analog inputs, do1 to dop denote the PLCs digital outputs and ao1 to aoq denote the PLCs analog outputs. n, m, p and q denote, respectively, the PLCs number of digital inputs, analog inputs, digital outputs and analog outputs.

    It is important to note that n+m define the dimension of the Mux block (a) in Fig. 4. Similarly p+q define the dimension of the Demux block (b) in Fig. 4.

    function output[ ]== PLC Control Program di1, ... ,din, ... ,ai1, ... ,aim( )...

    PLC Control Programin Matlab/Simulink language

    ...

    output = do1, ... ,dop, ... ,ao1, ... ,aoq[ ]

    (1)

    C. PLC Control Program file for translation The PLC control program is typically represented using

    a graphical language known as a ladder diagram. However, almost every PLC software-programming packages allows the use of text-oriented programming languages. Moreover, they allow the automatic conversion between ladder diagrams and text-oriented programming languages, and vice-versa. The proposed translation methodology will consider that the PLC control program is written as a text-oriented programming language, in a standard text file. This does not represent a problem because, as referred, almost every PLC

  • software-programming package allows saving the PLC control program in this format. Fig 5. shows a simple PLC Control Program text file considering, as an example, a Siemens PLC.

    1 // 2 // PROGRAM TITLE COMMENTS 3 // 4 NETWORK 1 5 LD I 0.0 6 A I 0.1 7 LD I 0.2 8 A I 0.3 9 OLD 10 = Q 0.0 11 // 12 NETWORK 2 13 LD I 0.4 14 LD I 0.5 15 CTU C5, +6 16 // 17 END

    Fig. 5. PLC Control Program standard text file.

    The PLC control program translation package is a software tool, developed in Visual Basic, which automatically converts the PLC control program text file into a correspondent Matalb/Simulink m-file. This m-file, containing the PLC control program described in Matalb/Simulink language, holds the Matalb/Simulink function defined in (1). Knowing the PLCs number of inputs/outputs, the conversion tool establishes the correct number of input and output arguments for function (1). The translation of the PLC Control Program itself relays on a set of translation rules applied to the set of PLC instruction list.

    A full PLC instruction list can be roughly divided into: Boolean Comparison Output Timer Counter Math Increment/Decrement Moving/Shifting Program Control Other Following some instructions conversion rules will be

    described, considering a Siemens PLC instruction list. Boolean instructions will be translated into Matlab/Simulink language using standard Matlab boolean functions, as presented in Table I, where I x.y denote a digital input and Q x.y denote a digital output, x and y are, respectively, the byte and bit of the considered digital input/output. Furthermore, do_g is a Matlab variable denoting digital output g and di_h is a Matlab variable denoting the digital input h. The bollean state TRUE will be represented in Matalb environment by 1 and FALSE by 0.

    TABLE I BOOLEAN INSTRUCTIONS TRANSLATION

    Boolean instruction PLC instruction

    Matlab/Simulink translation

    AND LD I a.bA I c.d = Q e.f

    do_g = di_h & di_i

    OR LD I a.bO I c.d = Q e.f

    do_g = di_h | di_i

    NOT LDN I a.b= Q c.d

    do_g = ~ di_i

    Combinations of various Boolean instructions will be

    converted using the above rules. As an example, the set of instructions (2) will be represented as (3).

    LD I 0.0 A I 0.1 LD I 0.2 OLD = Q 0.0

    (2)

    do_1 = (di_1 & di_2) | di_3 (3)

    PLC math instructions are usually boolean enabled.

    This implies the use of Matlab function if in order to represent their behavior. As an example, the PLC integer adding instruction (4) will be represented as (5) in the Matlab/Simulink environment. AIW0 and AQW0 represent, respectively, a PLC analog input and a PLC analog output. ao_1 is a Matlab variable denoting the first analog output and ai_1 is a Matlab variable denoting the first analog input.

    LD I 0.0 +I AIW0 , AQW0 (4)

    if di_1 ao_1 = ai_1 + ao_1 end

    (5)

    PLC control programs often uses internal flags (bit and

    variable internal memories) to represent states or store analog values. Whenever the translation package finds a PLC internal memory, automatically assigns a Matlab/Simulink variable to it. These variables are denoted as m or v, as they are digital or analog. The PLC multiply instruction (MUL) often involves the use of an auxiliary internal memory, as can be seen in (6) and (7), where the MOVW instruction (moving the value of one word variable 16 bit into another) is also used. Please note that the PLC internal variable VD refers to a 32-bit word.

    LD I 0.0 MOVW +6 , VD4 MUL +9 , VD4

    (6)

  • if di_1 v_4 = +6 v_4 = +9 * v_4 end

    (7)

    PLC counter instructions (CTUD counter up and

    down) can require several boolean inputs: one for counting up, other for counting down (if the case) and other for resenting the counter. Since the counting is only performed on the rising edge of the boolean input, the Matlab/Simulink translation should take into account the previous state of that boolean input. Please refer to (8) and (9) for a counting example, where di_1_prev is a Matlabb variable denoting the previous state of variable di_1. Previous state means the state in the previous PLC Control Program Cycle. In this example, by reaching counting 4 the counter bollean state changes to true. In Matlab environment c_10 denotes the bollean state of counter number 10, and c_10_value denote the counting value of the same counter.

    LD I 0.0 // Count up LD I 0.1 // Count down LD I 0.2 // Reset counter CTUD C10, +4

    (8)

    if di_1 & ~ di_1_prev c_10_value = c_10_value + 1 end if di_2 & ~ di_2 c_10_value = c_10_value - 1 end if di_3 c_10_value = 0 c_10 = 0 end if c_10_value >= +4 c_10 = 1 end

    (9)

    As an application example, (10) presents the

    Matlab/Simulink function block PLC Control Program for the PLC control program presented in Fig. 5.

    do_0 = (di_1 & di_2 ) | ( di_3 & di_4 ) if di_5 & ~ di_5_prev c_5_value = c_5_value + 1 end if di_6 c_5_value = 0 c_5 = 0 end if c_5_value >= +6 c_5_value = 1 end

    (10)

    V. CONCLUSIONS A new approach for testing PLC control programs for

    teaching automation and PLC-controlled processes was presented. This approach is based on the Matlab/Simulink software language.

    The PLC control program is translated into a Matlab function block, within the Matlab/Simulink environment, that will act over the model of the industrial process as long as the simulation runs. The developed translation package automatically translates the PLC control program, written as an instruction list, into Matlab/Simulink software language. The translation package produces a m-file, obtained by applying a set of translation rules that convert the PLC instruction list into Matlab language. This m-file is integrated into the Matlab/Simulink process simulation as a function block named PLC Control Program.

    Practical translation examples were presented in order to explain the translation methodology. This package is being successfully used by the Universidade de voras students, in order to test their PLC Control Programs together with Matlab/Simulink process models.

    REFERENCES [1] Mikell P. Groover, Automation, Production Systems and

    Computer Integrated Manufacturing, Prentice-Hall, 1987. [2] Andrew Kusiak; Computational Intelligence in Design and

    Manufacturing, John Wiley & Sons, 2000. [3] S. B. Morriss, Automated Manufacturing Systems, McGraw Hill,

    1994. [4] V Pinto, S. Rafael, J: F: Martins; PLC controlled industrial

    processes on-line simulator; IEEE International Symposium on Industrial Electronics, ISIE 2007, June 2007, Vigo, Spain.

    [5] Matlab/Simulink, http://www.mathworks.com/. [6] Electropedia - electrical and electronic terminology database

    under the IEC 60050 series (available on-line), http://www.electropedia.org/.

    [7] A. Rullan, Programmable logic controllers versus personal computers for process control, Computers and Industrial Engineering 33, pp. 421-424, 1997.

    [8] G. L. Kim, P. Paul, Y. Wang, UPPAAL in a nutshell, International Journal on Software Tools for Technology Transfer, 1, pp. 134-152, 1997.

    [9] M. Chmiel, E. Hrynkiewicz, M. Muszynski, The way of ladder diagram analysis for small compact programmable controller, Proceedings of the 6th Russian-Korean International Symposium on Science and Technology KORUS-2002, pp. 169-173, 2002.

    [10] Gi Bum Lee, Han Zandong, Jin S. Lee, Automatic generation of ladder diagram with control Petri Net, Journal of Intelligent Manufacturing, 15, 245252, 2004.

    [11] Hyung Seok Kim, Wook Hyun Kwon, Naehyuck Chang; A translation method for ladder diagram with application to a manufacturing process, Proceedings of the IEEE International Conference on Robotics and Automation, pp. 793-798, Detroit, USA, 1999.

    /ColorImageDict > /JPEG2000ColorACSImageDict > /JPEG2000ColorImageDict > /AntiAliasGrayImages false /CropGrayImages true /GrayImageMinResolution 200 /GrayImageMinResolutionPolicy /OK /DownsampleGrayImages true /GrayImageDownsampleType /Bicubic /GrayImageResolution 300 /GrayImageDepth -1 /GrayImageMinDownsampleDepth 2 /GrayImageDownsampleThreshold 2.00333 /EncodeGrayImages true /GrayImageFilter /DCTEncode /AutoFilterGrayImages true /GrayImageAutoFilterStrategy /JPEG /GrayACSImageDict > /GrayImageDict > /JPEG2000GrayACSImageDict > /JPEG2000GrayImageDict > /AntiAliasMonoImages false /CropMonoImages true /MonoImageMinResolution 400 /MonoImageMinResolutionPolicy /OK /DownsampleMonoImages true /MonoImageDownsampleType /Bicubic /MonoImageResolution 600 /MonoImageDepth -1 /MonoImageDownsampleThreshold 1.00167 /EncodeMonoImages true /MonoImageFilter /CCITTFaxEncode /MonoImageDict > /AllowPSXObjects false /CheckCompliance [ /None ] /PDFX1aCheck false /PDFX3Check false /PDFXCompliantPDFOnly false /PDFXNoTrimBoxError true /PDFXTrimBoxToMediaBoxOffset [ 0.00000 0.00000 0.00000 0.00000 ] /PDFXSetBleedBoxToMediaBox true /PDFXBleedBoxToTrimBoxOffset [ 0.00000 0.00000 0.00000 0.00000 ] /PDFXOutputIntentProfile (None) /PDFXOutputConditionIdentifier () /PDFXOutputCondition () /PDFXRegistryName () /PDFXTrapped /False

    /CreateJDFFile false /Description > /Namespace [ (Adobe) (Common) (1.0) ] /OtherNamespaces [ > /FormElements false /GenerateStructure false /IncludeBookmarks false /IncludeHyperlinks false /IncludeInteractive false /IncludeLayers false /IncludeProfiles true /MultimediaHandling /UseObjectSettings /Namespace [ (Adobe) (CreativeSuite) (2.0) ] /PDFXOutputIntentProfileSelector /NA /PreserveEditing false /UntaggedCMYKHandling /UseDocumentProfile /UntaggedRGBHandling /UseDocumentProfile /UseDocumentBleed false >> ]>> setdistillerparams> setpagedevice