LABORATORY OPERATION MANUAL

76
TOMSK POLYTECHNIC UNIVERSITY S.V. Efimov COMPUTER-AIDED SYSTEM SOFTWARE LABORATORY OPERATION MANUAL Recommended for publishing as a study aid by the Editorial Board of Tomsk Polytechnic University Tomsk Polytechnic University Publishing House 2014

Transcript of LABORATORY OPERATION MANUAL

TOMSK POLYTECHNIC UNIVERSITY

S.V. Efimov

COMPUTER-AIDED SYSTEM SOFTWARE

LABORATORY OPERATION MANUAL

Recommended for publishing as a study aid by the Editorial Board of Tomsk Polytechnic University

Tomsk Polytechnic University Publishing House 2014

UDC 004.41(075.8) BBC 31.3я73

E91

Efimov S.V. E91 Computer-aided system software. Laboratory operation manu-

al: study aid / S.V. Efimov; Tomsk Polytechnic University. – Tomsk: TPU Publishing House, 2014. – 76 p.

The laboratory operation manual provides basic instructions on performance

of laboratory works. The laboratory operation manual has been prepared on the basis of the origi-

nal Russian language materials and it is fully consistent with the course of «Com-puter-aided system software».

UDC 004.41(075.8) BBC 31.3я73

Reviewers

Candidate of Physical and Mathematical Sciences Senior Research Associate

Institute of Monitoring of Climatic and Ecological Systems of the Siberian office of the Russian Academy of Sciences

A.I. Gribenyukov

Doctor of Technical Sciences, Professor The Head of Department of Automated Control Systems

A.M. Korikov

© FSAEI HE TPU, 2014 © Efimov S.V., 2014 © Design. Tomsk Polytechnic University

Publishing House, 2014

3

Laboratory Work № 1 INSIGHT INTO CODESYS SOFTWARE PRODUCT

Purpose

To conceptualize students’ fundamental understanding of CoDeSys development system for industrial controllers by the example of simple application to control a running machine. Introduction into user interface, as well as several programming languages supported in CoDeSys, and language combining methods.

Task

A running machine is to be observed by a machine operator. Correct running must be confirmed at certain intervals. If there is no confirmation, a warning is first issued, shortly afterwards the machine will be stopped. The machine moves an arm along a rectangular path, and completed circuits are to be counted.

Procedure

1. Start of CodeSys

CoDeSys starts as most Windows applications:

Start → Programs → 3S Software → CoDeSys V2.3 → CoDeSys V2.3

2. Start new project

Start a new project by clicking File → New

• Target Settings The project is hardware independent, it can be tested in emulation mode. But the certain controller should be selected. Select CoDeSys SP for Windows NT Realtime in the dialogue window 'Configuration' and confirm by clicking Ok button.

• Main Program PLC_PRG POU The first program component – New POU – is defined in the next dialogue window. Select the language of the POU FBD and save the unit type proposed by default – Program Type of the POU Program and name – Name PLC_PRG.

PLC_PRG is the special setting (POU). It is called cyclically and executed by the runtime system in operation.

4

• Confirmation Switch We will start with the confirmation switch. Confirmation switch is a variable, which alters its value when operator confirms correct sequence of operation.

Mark the three question marks (???) in the first network, and type in the name of the switch (e.g. Observer). Now press the right-arrow key. The dialog window, which appears for the declaration of variables, contains the Name Observer and the Type BOOL. Alter the Class to VAR_GLOBAL (for global variables). The variable is entered in the object for global variables by clicking OK button. The following text appears there:

VAR_GLOBAL Observer: BOOL; END_VAR

• Rising Edge of the Confirmation Switch The correct operation should be confirmed by switching the button, not just by continuously holding the confirmation button. To make out these states the push and release moments should be determined, i.e. the switch changes from the off state (FALSE) to the on state (TRUE), and vice versa.

Return to the PLC_PRG POU and mark the location behind the Observer variable. A rectangular marking appears there. Execute the Box command through the quick menu (right mouse button).

A box for the AND operator is inserted and the name is marked. Now call the input assistant with <F2>. Select first the Standard Function Blocks in the dialog (left), and there the Trigger Function Block R_TRIG, which belongs to the Standard.lib. R_TRIG reports the rising edges of a Boolean value, which in this case is our switch.

R_TRIG Function Block Description

The trigger function block R_TRIG generates the pulse when the rising edge appears at the input.

FUNCTION_BLOCK R_TRIG VAR_INPUT CLK : BOOL; END_VAR VAR_OUTPUT Q : BOOL; END_VAR

5

VAR M : BOOL := FALSE; END_VAR Q := CLK AND NOT M; M:= CLK; END_FUNCTION_BLOCK

The Q output will remain FALSE as long as the input variable CLK is FALSE. If CLK changed to TRUE, Q will be set to TRUE. Each time the function is called up, Q will return FALSE until CLK has falling edge followed by an rising edge.

Declaration Example: RTRIGInst : R_TRIG;

Example in IL: CAL RTRIGInst(CLK := VarBOOL1) LD RTRIGInst.Q ST VarBOOL2

Example in ST: RTRIGInst(CLK:= VarBOOL1); VarBOOL2 := RTRIGInst.Q;

The name for the new data copy of R_TRIG should be created. Click with the left mouse button behind the function block and enter the name Trig1 (Fig. 1.1). The Declare variables dialog will appear where the class (Class) VAR (for local variables), the name (Name) Trig1 and the type (Type) R_TRIG are already entered. Press OK button.

Figure 1.1. The R_TRIG Function Block Diagram

6

• Falling Edge of the Confirmation Switch Mark the location Trig1 behind the function block (rectangular marking), insert designation AND (as described above) and alter it to OR (logical OR). Mark the input of the OR-operator and insert before it a Box of Type F_TRIG named Trig2. for the falling edge, having the instance Name Trig2. Press the <F2> function key (input assistance) in front of the Trig2 function block, and select the Observer variable in the Global Variables category of the dialog which appears.

F_TRIG Function Block Description

The function block F_TRIG detects a falling edge

FUNCTION_BLOCK F_TRIG VAR_INPUT CLK: BOOL; END_VAR VAR_OUTPUT Q: BOOL; END_VAR VAR M: BOOL := FALSE; END_VAR Q := NOT CLK AND NOT M; M:= NOT CLK; END_FUNCTION_BLOCK

The output Q and the help variable M will remain FALSE as long as the input variable CLK returns TRUE. As soon as CLK returns FALSE, Q will first return TRUE, then M will be set to TRUE. This means each time the function is called up, Q will return FALSE upon each CLK change from TRUE to FALSE.

Declaration Example: FTRIGInst : F_TRIG;

Example in IL: CAL FTRIGInst(CLK := VarBOOL1) LD FTRIGInst.Q ST VarBOOL2

ST Sample: FTRIGInst(CLK:= VarBOOL1);

7

VarBOOL2 := FTRIGInst.Q;

• Time Monitoring, First Part Insert a Box of Type TOF (switch-off delay) with the name Timer1 behind the OR-operator using the quick menu. Replace the three question marks at the PT input with the time constant T#10s for 10 seconds (the time can later be altered, after successful tests)

TOF Function Block Description

The function block TOF implements a turn-off delay.

TOF(IN, PT, Q, ET). The IN and PT inputs with the BOOL and TIME types respectively. The Q and ET outputs are of types BOOL and TIME. The Q and ET outputs are of types BOOL and TIME also.

If IN is TRUE, than Q output is TRUE and the ET output is 0. If IN changed to FALSE, the count in milliseconds starts at the ET output. The count stops when the specified time interval achieved. The Q input is FALSE if IN is FALSE, and ET is equal to PT, and the Q output is TRUE otherwise.

Thus, Q has a falling edge when the time indicated in PT in milliseconds has run out.

Declaration Example: TOFInst : TOF ;

Example in IL: CAL TOFInst(IN := VarBOOL1, PT := T#5s) LD TOFInst.Q ST VarBOOL2

Example in ST: TOFInst(IN := VarBOOL1, PT:= T#5s); VarBOOL2 :=TOFInst.Q;

• Issue «Warning» Click the Assign command behind the Q output of the Timer1 function block using the quick menu. Replace the three question marks (???) with the variable name Warning. In the dialog Declaration of variables, enter the Class VAR_GLOBAL and the type BOOL.

Now, mark the position in the middle of the line connecting the timer input and the Warning variable, and execute the Negate command via the quick

8

menu. This causes the Boolean signal to be inverted, and is displayed by means of a small circle (Fig. 1.2).

Figure 1.2. The Warning Variable Switching FBD

• Set the Stop Signal after Exceeding the Second Time Limit Create another network with the menu command Insert→Network (after). Use the quick menu to add a Box of Type TON (function block «switch-on delay») with the name Timer2 into this network. Allocate the variable Warning to the IN input using the <F2> key, and the time constant T#5s to the PT input. After the Timer2 function block we need an Assignment again, this time to the variable Stop (Class VAR_GLOBAL).

Figure 1.3. The TON Function Block Diagram

• TON Description The function block Timer On Delay implements a turn-on delay.

TON(IN, PT, Q, ET). The IN and PT inputs are of the types BOOL and TIME respectively. The Q and ET outputs are of types BOOL and TIME also.

If the IN is FALSE, the Q output is FALSE, and the ET output is 0. As IN is set to TRUE, the count in milliseconds starts at the ET output till the PT interval is achieved. The Q is TRUE if IN is TRUE, and the ET is equal to the PT, and the Q is FALSE otherwise.

Thus, Q has a rising edge when the time indicated in PT in milliseconds has run out.

Declaration Example: TONInst : TON;

9

Example in IL: CAL TONInst(IN := VarBOOL1, PT := T#5s) LD TONInst.Q ST VarBOOL2

Sample in ST: TONInst(IN := VarBOOL1, PT:= T#5s);

• Insert POU for the Machine The object organizer POUs is located in left hand area of the CoDeSys window (with PLC_PRG). Insert another POU with the name Machine, of type Program and with the Language SFC under POUs, using the quick menu command Add object. The initial diagram in SFC includes a step «Init», and of a subsequent transition «Trans0» followed by a jump back to Init (Fig. 1.4).

Figure 1.4. The Initial SFC Diagram

The simplified SFC, without IEC steps, will be used further. If there is the action rectangular right from the Init, deselect the Use IEC-Steps box and redefine the POU Machine.

• Specify the Machine’s Sequence Each phase in the operation of our machine requires a step. Mark the transition Trans0 in such a way that a dotted frame appears round Trans0, and use the quick menu to select the command Step-Transition (after). Repeat this procedure four times. There should be six steps including Init.

If you click directly on the name of a transition or of a step it will be highlighted. So, you can alter it. The step after the Init step should be called Go_Right, and the following steps Go_Down, Go_Left, Go_Up,and Count.

10

• Programming the First Step After a double click on the Go_Right step CoDeSys starts defining the step action and you will be asked about the desired Language. Select ST (structured text) and go to a separate window appeared for the action associated with this step. The machine arm should be moved in the X-direction. The program line looks as followed:

X_pos:= X_pos + 1;

Completing the line X_pos :=X_pos+1; with the Return button, you have to declare the variable X_pos having Type INT (for integer). A small triangle appears in the upper corner of the step to indicate that this step has been programmed (Fig. 1.5).

• Programming the Next Steps Repeat this procedure for the other steps with altered program lines. Declare the variables Y_pos and Counter of Type INT.

The Go_Down step: program line is Y_pos := Y_pos + 1; The Go Left step: program line is X_pos := X_pos – 1; The Go Up step: program line is Y_pos := Y_pos - 1; The Count step: program line is Counter := Counter + 1.

• Specify Transitions A transition should contain the condition for progressing from one phase to the next one. Overwrite the first transition after Init with the variable Start. In the declaration of variables enter the Class VAR_GLOBAL and the Type BOOL. The machine thus starts to run when the start switch is pressed.

The second transition should contain the condition X_Pos = 100, so that when the X-position has reached the value 100 the next phase starts. The third transition contains the condition Y_pos = 50. The fourth contains the condition X_pos = 0, the fifth contains the condition Y_pos = 0, the sixth contains the condition TRUE (continue immediately after a single execution).

• Keeping Process Stopped Go back to the PLC_PRG POU and insert a third network. Replace the question marks by the variable Stop, and after that select the Return command from the context menu. The Return has the effect of leaving the PLC_PRG POU when Stop is set.

11

Figure 1.5. The Machine Operation SFC Diagram

12

• Call POU Machine Add another network, set the focus there and insert the command Box from the context menu. The «AND» in the box is marked already. Press <F2> and in the appeared input assistant dialog select the machine POU in the User defined Programs category. This completes the programming.

• Build Project Build the project with the menu command Project→Rebuild all, or the <F11> function key. If you complete the build procedure correctly, the message «0 errors» should be reported at the bottom of the window. If not, check that all the entries should be done correctly. The reported error may also help.

3. Visualization

• Create Visualization The third tab in the CoDeSys object organizer named Visualization. Go to the Visualization tab. Use the Object Organizer’s quick menu to call the Add Object command. Give the visualization object the name Observation.

The visualization tab should finally look like this:

Figure 1.6. The Machine Operation Visualization

13

• Draw Visualization Element Let’s start with the confirmation switch (the rectangle with the text OK in the figure).

Select the symbol for Rectangle from the toolbar. Press the left hand mouse key in the visualization editor, hold it down, and draw a rectangle with it. Release the mouse key when it has reached the desired form and size.

• Configure the First Visualization Element The configuration dialog is called with a double click on the rectangle. In the Contents field of the Text Category write the text OK.

Select the Variables Category, click in the Change Color field and call up the input assistance with the <F2> function key. Make a double click to the point in the right hand half of the dialog box and the global variable will appear. Select the Observer variable. The field now contains Observer.

After this, select the Colors Category in the configuration dialog, and click on the Inside button in the Color area. Select a color (e.g. light blue). Then select another color with the Inside button in the Alarm color area (e.g. blue).

Enter the variable Observer again in the Input Category and select the Toggle variable point. Leave the configuration dialog.

This causes the rectangle to be colored light blue during running operation when the Observer variable is in the FALSE state, and blue when it is in the TRUE state. The state is changed with each click on our key button.

• Expand Visualization Draw a circle for the warning. Select Configure option with the double click on the circle and configure it with the following values:

♦ Text Category, Contents field with Warning; ♦ Colors Category, Color area using Inside with grey color, ♦ Alarm color with red color; ♦ Variable Category, Change color variable. Warning.

Copy the circle you’ve created using the menu command Edit → Copy and insert another one with the menu command Edit → Paste. Alter the following values in the new Stop circle:

♦ Text Category, Contents field with new entry Stop; ♦ Variable Category, Change color variable. Stop.

14

Draw a rectangle for the Start key entering the following values: ♦ Text Category, Contents field with Start; ♦ Variable Category, Color change variable. Start; ♦ Input Category, select the point Toggle variable enter. Start in the

field; ♦ Colors Category, Color area using Inside with red colour and Alarm

color with green.

Draw a rectangle for the counter and configure it with the following values: ♦ Text Category, Contents field with Counter: %s (%s functions as a

place holder for the variable value) ♦ Variable Category, Textdisplay field with Machine. Counter

Draw a small rectangle for the machine and configure it with the following values:

♦ Absolute movement Category, X-Offset field with Machine.X_pos; ♦ Absolute movement Category, Y-Offset field with Machine.Y_pos; ♦ Colors Category, Color area using Inside with blue colour.

If you like, you can draw two rectangle frames around the two areas for observation and for the Machine. Enter Observation (or Machine) as the Contents in the Text Category, and select the Vertical alignment bottom. Using the quick menu command Send to back place the rectangle frames behind the existing elements.

4. Starting the Target System

If you connect a PLC to the CoDeSys for the first time, some settings should be adjusted.

Open the dialog Communication parameters in the Online menu. Select the New button to configure the connection to you target system. It’s desirable to enter an appropriate name for the connection.

In the simplest case, CoDeSys SP RTE and CoDeSys programming environment are executed on the same PC. If the PLC is connected to another computer in the network, the ‘localhost’ parameter should be changed by the name or IP address of this computer.

The setting is confirmed by clicking the OK button.

15

5. Starting the Project

The connection to the PLC will be established using the menu command Online → Login. If the remote connection is used, you will be asked to confirm the project code download. Now start the project by selecting Online → Run from the CoDeSys menu. By means of the visualization you can control the machine operation.

To start the project in the simulation mode, the option Online → Simulation Mode should be pointed. Then, switch to the online mode and start the project following the instruction given above.

Individual Tasks

1. Realize the color change of machine depending on color changing of the Warning circle.

2. Realize the acceleration of the machine arm with pressing the OK button. 3. Realize the visualization of the machine movement number in the

Counter field (the movements in any direction should be counted). 4. Realize the stop of the machine arm by switching-off the Start button. 5. Realize the color change of the machine arm with pressing the OK button. 6. Realize the machine arm reverse with the alarm-state of the OK button. 7. Realize the line width of the machine arm with the OK button switch.

16

Laboratory Work № 2 PRIMARY SIGNAL PROCESSING

Purpose

To gain practical skills in working with CoDeSys signal generators, in creating user function blocks in ST language. Introduction into visualization options (trends, parameter editing).

Task

To simulate desired and noise signals using the signal generator. To realize the filtering of received signal by different filters: exponential smoothing, moving average and median filters.

To visualize the filter operation.

To provide a benchmark of filters with RAMP library.

Procedure

1. Start CodeSys

Create a new project selecting the FBD language.

2. CoDeSys library connection

The signal generators contained in util.lib are used in this laboratory work. The library contains also the set of different functions and function blocks applied for BCD (binary-coded decimal) and bit/byte functions, mathematic auxiliary functions, as well as for controllers, generators and analog value processing.

The library manager is opened with the Window → Library Manager command. Information about included libraries, the POUs, user-defined POUs and the FBD is stored with the project and can be viewed in the dialog Information about external library (Fig. 2.1).

Click Insert in the Library Manager and locate the util.lib in the opened dialog (<Disc>:\Program Files\3S Software\CoDeSys V2.3\Library\util.lib).

17

Figure 2.1. The Library Manager Dialog

3. Task Performance

• The desired signal simulation To simulate the desired signal the function block GEN is used. Mark the position left from three question marks in the first FBD graphic editor network and click the rectangular marking. Insert the Box command from the context menu, and press <F2> key button. Select the Standard Function Blocks in the appeared assistant dialog (left). Select GEN from the signal generator list in util.lib.

The GEN Description

The function generator generates typical periodic functions:

The inputs are a composition consisting of MODE from the pre-defined counting type GEN_MODE (Fig. 2.2), BASE of the type BOOL, PERIOD of the type TIME, CYCLES and AMPLITUDE of INT values and RESET of the BOOL type.

The output OUT of the type INT.

The MODE describes the function which should be generated, whereby the enumeration values: TRIANGLE and TRIANGLE_POS deliver two triangular functions, SAWTOOTH_RISE and SAWTOOTH_FALL are ascending a descending sawtooth functions, RECTANGLE a rectangular signal and SINE and COSINE the sine and cosine.

BASE defines whether the cycle period is really related to a defined time (BASE=TRUE) or whether it is related to a particular number of cycles, which means the number of calls of function block (BASE=FALSE).

18

Figure 2.2. Signal Types Generated by the Function Block GEN (MODE values)

The PERIOD or CYCLES inputs define the corresponding cycle period.

The AMPLITUDE input defines, in a trivial way, the amplitude of the function to be generated.

The function generator is again set to 0 as soon as RESET=TRUE.

Set up the GEN initial parameters and the POU name SIN_GEN, as is shown in Fig. 2.3. Connect the function block ADD to the output value of the signal generator (using the command Box; then alter the default POU name to ADD manually or select the POU from FBD Operators with Input Assistant obtained via <F2>).

ADD Description

Addition of variables of the types: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL and LREAL.

19

Two TIME variables can also be added together resulting in another time (e.g., t#45s + t#50s = t#1m35s).

The result is of type TIME. Example in IL: LD 7 ADD 2,4,7 ST Var 1

Example in ST: var1 := 7+2+4+7;

Insert the next signal generator with new input parameters at the free input of the unit ADD. Click ADD and select Assign command. Name the output signal as temp out. In the declaration of variables dialog enter the type of the variable Type INT.

Figure 2.3. The Desired Signal Simulator

• Noise Simulation To simulate a noise, use the function block BLINK. The function block BLINK generates a pulsating signal. Create a new network with the menu command Insert → Network (after). Insert the new POU with the command Box and alter the name to BLINK.

Set up the initial parameters for BLINK as is shown in Fig.2.4 and the function block name BLINK_GEN.

20

Figure 2.4. The BLINK and BOOL_TO_INT Function Block Diagrams

BLINK Description

The input consists of ENABLE of the type BOOL, as well as TIMELOW and TIMEHIGH of the type TIME.

The output OUT is of the type BOOL.

If ENABLE is set to TRUE, BLINK begins, to set the output for the time period TIMEHIGH to TRUE, and then afterwards to set it for the time period TIMELOW to FALSE.

Insert the function block BOOL_TO_INT at the output value of the generator signal (Box, <F2>, select Conversion Operators in the Input Assistant category).

BOOL_TO Description

Conversion from type BOOL to any other type: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL and LREAL.

For number types the result is 1, when the operand is TRUE, and 0, when the operand is FALSE.

For the STRING type the result is‚ TRUE or‚ FALSE. Exaple in IL: LD TRUE BOOL_TO_INT ST I (*Result: 1 *) LD TRUE BOOL_TO_STRING ST str (*Result: 'TRUE' *) LD TRUE BOOL_TO_TIME ST t (*Result: T#1ms *) LD TRUE BOOL_TO_TOD ST (*Result: TOD#00:00:00.001 *) LD FALSE BOOL_TO_DATE

21

ST dat (*Result: D#1970-01-01 *) LD TRUE BOOL_TO_DT ST dandt (*Result:DT#1970-01-01-00:00:01 *)

Example in ST: i:=BOOL_TO_INT(TRUE); (* Result:1 *) str:=BOOL_TO_STRING(TRUE); (* Result:"TRUE" *) t:=BOOL_TO_TIME(TRUE); (* Result:T#1ms *) tof:=BOOL_TO_TOD(TRUE); (* Result:TOD#00:00:00.001 *) dat:=BOOL_TO_DATE(FALSE); (* Result:D#1970 *)

As the output value of function block BLINK is Boolean 1 or 0, use the function block MUL and add the noise signal to desired signal using the function block ADD (Fig. 2.5) to visualize the noise influence on the desired signal. Assign the resulting output signal to the variable out of the integer type.

Figure 2.5. The Resulting Signal of the Desired and Noise Signals

MUL Description

Multiplication of variables of the types: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL and LREAL.

Example in IL: LD 7 MUL 2,4,7 ST Var 1

Example in ST: var1 := 7*2*4*7;

4. Signal Filtering

The result signal should be filtered by applying of different filtering algorithms.

a. Exponential Smoothing

The exponential smoothing is a method of mathematical transformation, applied by time series forecasting.

22

( )1

1 1

1;: : 1,t

t t t

c ts

s c s t− −

== + α ⋅ − >

where st is the smoothed series, сt is the initial series, α is the smoothing coefficient selected by user ( )0 1 .< α <

Out values obtained by addition of the desired and noise signals are the initial series for the filter.

b. Moving Average

The moving average is the common name for family of functions which values at each point are equal to the mean value of data set over the covered period. The moving averages are used usually with the time series data to smooth the short-term fluctuations and determine main trends and cycles. Mathematically, the moving average is a type of convolution function, so it could be considered as the low-pass filter used for the signal processing.

The simple, or arithmetic, moving average, is equal to the arithmetic mean of data set over the covered period, and calculated from the following formula:

11 1

0

1 ,n

t t t i t n t nt t i

i

p p p p ps pn n

−− − − − +

−=

+ + …+ + …+ += =∑

where st is the simple moving average value at the t point, n is the number of data set values to calculate the moving average (smoothing interval), the wider the interval, the more smoothing the function graph, 1tp − is the data set value at the 1t − point.

The number of data set values are specified by a user. Filter repeats the initial graph form till the desired number of function values are attained.

c. Median Filter

Median filter is one of the digital filters widely used by digital signal and image processing to reduce the noise level.

The count values in the filter box are sorted in ascending (descending) order, and the value at the middle of the ordered list is got to filter output. In case of even number of counts the output value is equal to the mean value of two counts from the middle of the list. The box is shifted down the filtered signal, and calculations are repeated.

23

Example The example of the median filter for the regular signal is given below.

x = [2 80 6 3] y[1] = median[2 2 80] = 2 y[2] = median[2 80 6] = median[2 6 80] = 6 y[3] = median[80 6 3] = median[3 6 80] = 6 y[4] = median[6 3 3] = medianа[3 3 6] = 3

as a result: y = [2 6 6 3] – median filter output.

The count box size is set by user. To attain the desired number of smoothing function values the filter duplicates the initial graph form

To create the filter function block insert another POU of Type Function Block and with ST language (Language ST) using the quick menu command Add object in the left hand area of CoDeSys.

Structured Text (ST)

The Structured Text consists of a series of instructions which, as determined in high level languages, (IF..THEN..ELSE) or in loops (WHILE..DO) can be executed.

Example: IF value < 7 THEN WHILE value < 8 DO value:=value+1; END_WHILE; END_IF;

Tasks for Self-Fulfillment

Create function blocks for the received signal filtering. Realize three presented filtering algorithms in ST language. Then, generate out signal at the filter input, the sum of the desired and noise signals, and other parameters provided by user algorithms:

♦ Create another network with the menu command Insert →Network (after).

♦ Open the catalog of function blocks using the Box command from the quick menu.

♦ Select the desired filter User defined function blocks in. ♦ Set the in and out parameters of the selected filter (see Fig. 2.6).

24

Figure 2.6. The Median Filter Diagram

5. Visualization of Filter Operation

Insert a new POU in the Visualization page and name it.

Select Trend on the tools panel. Expand the trend using the left mouse button to desired size, release the button. Open the dialog with double click on the element.

Click the Vertical axis key button in the opened dialog and set the Scale parameters as it is shown in figure 2.7. Close the Vertical axis dialog.

Figure 2.7. The Vertical Axis Dialog

25

Click the Choose variable key button in the Trend Configuration dialog, and select the output signal out and the output signal of a filter. Change the color of the filter output signal (Fig. 2.8).

Figure 2.8. The Variables Dialog

Insert the similar trends for the next two filters.

Realize the following input data editing during the filter operation in the visualization tab:

• exponential smoothing – smoothing coefficient α; • moving average – a number of data sets to calculate the moving

average; • median filter – size of count dialog;

To edit the filter settings transfer the rectangle to the visualization tab and provide a double click on it. Insert the following parameters in the rectangle configuration:

• write down <editing variable> %s (e.g., alpha: %s) in the Text field Content;

• in the Variables field Textdisplay write down PLC_PRG.<editing variable> (e.g., PLC_PRG.alpha);

• mark the Text input of variable ‘Textdisplay’ in the Input field; • in Min and Max insert the minimum and maximum possible values of

the editing variable; • select Numpad in the pulldown list.

The resulting visualization dialog looks as it is shown below:

26

Figure 2.9. The Visualization of the Median Filter Operation

Start the application (Online → Login, Run). Clicking on the rectangle with the editing variable displays a digital keyboard where the variable value can be changed. Test the operation of filter by different variable values.

Add the library function block RAMP to the main application (Box, Input Assistant → Standard function blocks → function manipulators → RAMP_REAL). Set the input parameters of the function block (Fig. 2.10).

Figure 2.10. The RAMP FBD

The Description of Function Block RAMP_REAL

RAMP_REAL serves to limit ascendance and descendance of signals.

The input consists on the one hand out of three INT values: IN, the function input, and ASCEND and DESCEND, the maximum increase or decrease for a given time interval, which is defined by TIMEBASE of the type TIME.

27

Setting RESET to TRUE causes RAMP_INT to be initialized a new. The output OUT of the type REAL contains the ascend and descend limited function value.

When TIMEBASE is set to t#0s, ASCEND and DESCEND are not related to the time interval, but remain the same.

Create a trend with the out signal and with the output signal of the function block RAMP in the visualization tab. Realize the editing of ASCEND and DESCEND parameters of the RAMP block in the visualization tab. Make the comparative analysis of the RAMP block and the realized filters.

Advancement Questions

1. What is the effect of the increasing (decreasing) α coefficient on the operation of the exponential smoothing filter?

2. What is the effect of increasing (decreasing) number of data set values for moving average calculation on the filter operation?

3. What is the effect of increasing (decreasing) number of counts in the median filter window on the filter operation?

4. How is output value calculated with even (odd) number of counts in the median filter window?

5. Calculate the output values of the signal for the exponential smoothing filter with following settings: the smoothing coefficient – 0,2, the data set values [1 15 0 7 4 4].

6. Calculate the output values of the signal for the moving average filter with following settings: the smoothing interval – 3, data set values[5 8 12 3 8 1].

7. Calculate the output values of the signal for the median filter with following settings: the number of counts in the window – 3, the data set values [6 1 4 50 2 1].

28

Laboratory Work № 3 TANK LEVEL CONTROL

Purpose

To realize the application of tank level control in CoDeSys.

Task

The task is to maintain the desired liquid level in a tank by the drain valve controlling.

Simulate the liquid supply with the signal generator. Calculate he liquid level applying the integrating method. Use a PID controller within the control loop (Util lib). Create the function block PWM for the drain valve controlling.

Design a mnemonic diagram which shows the control algorithm of tank liquid level.

Present the realized algorithms and process visualization in CoDeSys.

Procedure

1. Start CodeSys

Create a new project. Select the FBD language. Connect the util.lib to the project.

2. Task performance

• Simulation of Liquid Supply. Task for Self-Guided Performance

• Calculation of Liquid Level in a Tank. To calculate the liquid level in a cylindrical tank divide the liquid volume inside this tank by the area of the tank bottom.

2 ,Vhr

where h – the liquid level in the cylindrical tank, and r – the bottom radius.

Calculation of the liquid volume in a tank can be performed by integrating the difference of the liquid supply rate and the rate of liquid outflow from the tank. The util.lib contains the function block INTEGRAL for numerical integration.

29

Description of the INTEGRAL Function Block.

This function block approximately determines the integral of the function.

The analog input IN of the type REAL (Fig. 3.1). The TM input of the DWORD type contains the time which has passed in msec, and the input of RESET of the type BOOL allows the function block to start anew with the value TRUE. The output OUT is of the type REAL.

Figure 3.1. The Function Block Diagram of Numerical Integration

The integral is approximated by two step functions. The average of these is delivered as the approximated integral.

The two-point trapezoidal rule is applied in the calculation algorithm.

The trapezoidal rule (also known as trapezium rule) is a method of numerical integration of a single variable function when the integrand in each linear interval should be approximated by the first degree polynomial, i.e. the linear function.

The area under the graph of the function is approximated by rectangular trapezoids. The polynomial order is equal to 1.

For general case, one can use the following trapezoid formula:

( )1

0

2

10

2

2

,2

b nn

iia

nn

ii

f ff x dx h f

b a f f fn

=

=

+ ≈ + =

− + = +

∑∫

where fi – the integrand value at the points of the interval partition (a, b); the interval is divided into the equal sections with the step h; f0, fn – the integrand values at a and b points respectively (Fig. 3.2).

Figure 3.2. The Graphical Representation

of Trapezoidal Rule

30

• The Liquid Level Control in a Tank The PID controller is used in the control loop of the liquid level (Fig. 3.3).

Figure 3.3. The Diagram of PID Controller Operation

A proportional-integral-derivative controller (PID controller) is a generic control loop feedback mechanism widely used in industrial control systems for the control signal calculation to achieve the desirable accuracy and quality in the process. The PID controller is named after its three correcting terms, whose sum constitutes the manipulated variable. The first term is proportional to the difference of input value and response value (the error signal), the second one is the integral of the error signal, and the third term is derivative of the error.

The proportional term produces an output value opposing to the current error from the predefined value. The more the error, the more the output value. If the input signal is equal to the predefined value, the output signal is equal to zero.

However, the manipulated variable can be never stabilized at the predefined value by applying just the proportional controller. There is a so-called statistical error, which is equal to the manipulated variable error that provides the output signal stabilizing the output variable at this value. E.g. the output signal in a temperature controller (this is heater capacity) is decreased by approximation of temperature value to the predefined temperature, and the system is stabilized if the capacity is equal to heat losses. Temperature can not gain the predefined value because the heater capacity is equal to zero this case and starts getting cold.

The higher the proportionality factor between input and output signals (the gain factor), the less the statistical error. However, the self-oscillations could appear if the gain factor is high enough and there are delays in the system. Further increasing of the gain factor would result in system instability.

31

The integral term is proportional to the integral of operating deviation. It is used to eliminate statistical error. It enables the PID controller to consider the statistical error in course of time.

If there is no external disturbance in the system, the controlled value will be stabilized at the predefined value, the proportional term signal will be equal to 0, and the output signal will be provided by integral term. However, the integral term presence may result in self – oscillations.

Derivative term is proportional to the rate of changing the controlled value error and intended to counter future errors. Errors can be caused by external disturbances or by controller’s delay.

PID controller is intended to support the predefined value x0 of a certain variable x by changing the another variable u. x0 called the predefined value, and difference ( )0e x x= − called error, or deviation from the predefined value.

The output signal u is determined by summary of three terms:

( ) ( ) ( )0

,t

p i d

deu t P I D K e t K e d Kdt

= + + = + τ τ +∫

where Kp, Ki, Kd are gain parameters of the proportional, integral and derivative terms of PID controller, respectively.

PID Function Block Description

The PID function block realizes the control law (Fig. 3.4):

( ) ( ) ( )0

1( ,TN

OFFSET

de tY Y KP e t e t TV

TN dt= + + +∫

where Y_OFFSET is the stationary value, KP is the proportionality coefficient, TN is the constant of integration (ms), e(t) is the error signal (SET_POINT – ACTUAL).

Input parameters: ACTUAL – input value of signal; SET_POINT – target value of the controlled variable; KP – proportionality coefficient; TN – the constant of integration; TV – derivative action time; Y_MIN, Y_MAX – the output X value limits.

32

Output values: Y – output signal of PID controller.

Figure 3.4. The PID Function Block Diagram

Inputs ACTUAL, SET_POINT, KP, Y_OFFSET, Y_MIN Y_MAX are of type REAL. The TN and TV inputs are of type DWORD, the RESET and MANUAL inputs are of type BOOL.

The Y – REAL, LIMITS_ACTIVE and OVERFLOW outputs are of type BOOL.

Y is also limited to the allowed range between Y_MIN and Y_MAX. If Y exceeds this range, LIMITS_ACTIVE, a BOOLean output variable, becomes TRUE. If no limitation of the manipulated variable is desired, Y_MIN and Y_MAX are set to 0.

If MANUAL is TRUE, then the control is suspended, that is Y is not altered (by the controller), until MANUAL becomes FALSE, whereby the controller is re-initialized.

Because of the additional integral part, an overflow can come about by incorrect parameterization of the controller, if the integral of the error becomes high enough. To detect such situation the Boolean output OVERFLOW is intended, which in this case would have the value TRUE. At the same time, the controller is suspended and will only be activated again by re -initialization.

• Drain Valve Control by the Analog PWM Function Block Pulse width – modulation (PWM) is the control of average load voltage by changing the pulse durations which control the key.

33

The PWM signal is generated by analog comparator (Fig. 3.5), where the reference signal (of a triangle waveform) is applied to one input (to the inverting comparator input according to the figure) and the continuous analog signal is applied to another input. The output pulse repetition rate of PWM is equal to the triangle, or sawtooth, voltage frequency. When the value of the reference signal is more than the modulation waveform, the PWM signal (magenta) is in the high state, otherwise it is in the low state.

Figure 3.5. PWM by Use of Analog Comparator

Practice Case

Implement the PWM function block using the information presented above. Use the signal generator GEN to apply the sawthooth signal to the PWM input. Use the PID controller output as a continuous analog signal

• Mnemonic Diagram Assembly Figure 3.6 presents a mnemonic diagram intended to liquid level control in a tank. FDB is the implementation language.

34

Figure 3.6. Mnemonic Diagram For the Liquid Level Control

35

In this diagram: circuit 1 simulates the liquid supply into the tank by means of the sine wave oscillator; circuit 2 contains a functional block of numerical integration, determines the level of liquid in the tank (OPEN_DEGREE – degree of opening of the drain valve), and also a block LEVEL for calculating of the level of liquid in the tank; circuit 3 generates a ramp signal to the PWM function block; circuit 4 is a PID controller which generates a feedback signal (L – a current level of liquid in the tank, MAX_LEVEL – a required level value); circuit 5 includes a timer for timing a single period of the sawtooth waveform generator; circuit 6 represents a subscriber unit START_TIMER, wherein for each new period of the sawtooth signal generator switches between the drain valve motion and for the time period of the current for the set mode is changed draining valve opening degree; circuit 7 simulates the function block PWM (PWM - Pulse-Width Modulation).

Task for Self-Practice

Build the mnemonic diagram similar to the diagram presented in the figure 6, which implements the algorithm of liquid level control. Describe the internal logic of the PWM function block.

Creating the START_TIMER user block is the optional task. One of the possible variants to complete the task is presented in the diagram given above.

3. Visualization of Mnemonic Diagram Operation

Figures 3.7 and 3.8 present one of the diagram operation samples: process of tank filling and tank dewatering if necessary.

Task for Self-Practice

Visualize the mnemonic diagram operation. You may use the variant presented in the study guide or you may develop another one.

Figure 3.7. Visualization of Liquid Level Control. Position 1

36

Figure 3.8. Visualization of Liquid Level Control. Position 2

37

38

Checklist and tasks

1. Describe the operation principle of the INTEGRAL function block, the function block purpose, input and output parameters.

2. Describe the PID intend, provide the succinct description of output signal components in the function block.

3. Provide the description of the PWM function block intend, required input and obtained output parameters.

4. Change the mnemonic diagram logic in such a way to present a number of times at the visualization tab when the liquid level in the tank is lower (higher) than a critical point (the critical point value should be different from the required liquid level and assigned by user).

5. Change the diagram logic in such a way that the program will stop the operation and report the appropriate message to user when the liquid level comes to any minimal (or maximal) critical point (the critical point value should be different from the required liquid level and assigned by user).

39

Laboratory Work № 4 INTRODUCTION TO MASTERSCADA

Purpose

These methodological instructions are intended to conceptualize students’ basic knowledge of MasterSCADA package and provide the experience in:

• SCADA task tailoring; • supervisory control; • automatic control; • workflow history storage; • security execution; • execution of general-system functions.

Task

Realize the liquid level control and visualize the algorithm by means of MasterSCADA

Procedure

1. Start MasterSCADA in development mode

MasterSCADA startup in development mode is similar to any other Windows program: click Start on the desktop or on the button panel. So, start MasterSCADA through the command

All programs/MasterSCADA/MasterSCADA.

Select a project you will be work with in the opened dialog (Fig. 4.1): new project, class project or another one which already exists, and specify the path for the project.

If you create a new project, a dialog shown in fig. 4.2 will appear after project creation and the project name confirmation.

Through this dialog window you can lock the project editing from users who don’t have the project password. If the dialog fields are empty, any user can open the project in the editing mode. By project reopening the password window will not appear anymore, so if you want to set a password, e.g., after competing the project, choose in main menu the option Project → Save.

40

Figure 4.1. Creating a New Project

Figure 4.2. Setting the Project Password

2. Main Dialog Window of Project Management

So, MasterSCADA is ready for operation. Following the action sequence mentioned above you make the manager project window open, the main action field of the project (Fig. 4.3). Opposed to many module programs, you should not switch between different actions and files by editing in MasterSCADA. The project manager operates on the one-stop-service principle into the MasterSCADA information space.

41

Figure 4.3. The MasterSCADA Main Window

System Tree

Studying the System tree of a completed project it can be determined the architecture type realized by a developer, the number of computers interconnected within the system, the way of connecting the external devices, input and output devices, the number of external signal to be processed by MasterSCADA. In fact, the System tree is the specific type of automation structure diagram. The System tree derivation starts from the Computer element.

The Computer element is, for sure, the cross-point of the real and virtual elements of automation system which is to be built. Neither of the MasterSCADA projects can exist without this element.

The Computer can contain child elements interacting with MasterSCADA • controller;

42

• input/ otput module; • OPC server; • MaserLink; • DB connector .

These interactions will be observed a bit later. At this moment it is required to insert a computer and provide a unique computer name. To do this click the right mouse button on the System option and select the command Insert → Computer (Fig. 4.4).

Figure 4.4. Inserting a Computer

The unique computer name is provided in the element property dialog (Fig. 4.5).

Figure 4.5. Computer Name Assignment

43

As all the computers for training are connected into a local network not only the unique computer name should be assigned, but also the developer account to be created to avoid network conflicts. To create a new operator account (developer account) select the Operators tab in Computer Properties, click the Developer position and with the Add button insert the account name (Fig. 4.6).

Figure 4.6. Adding the Developer Account

Object Tree

The Object in MasterSCADA is a basic system unit of the designed system corresponded to a real technological object (production department, manufacturing area, instrument, pump, valve, sensor, etc.), controlled by the system which is developed by means of MasterSCADA. On the other hand, this is the traditional object with standard characteristics. The object can include other objects, variables and function blocks (office library objects, intended to control and monitoring, corresponding sometimes to real objects, e.g., a pump or a valve or sometimes perform just one control or monitoring function, e.g., a controller). Each object of MasterSCADA has characteristics and files, which represent it to a developer. Windows with the dynamic graphics (mnemonic diagrams), trends, reports, message logs, and other files can be created by operator.

The MasterSCADA studying and designing can be taken easier if you have a clear idea about the desired result. It enables the correct way of designing: from the general to the special, or top-down design. The real technological object should be divided into some sub-objects at an early stage of programming. E.g. a workshop for the X product manufacturing should be computerized, and one of the main tasks is the tank level control.

44

Let us create the object Workshop, with another object Tank E-1 within it, where the certain level should be supported. However, before creating any objects a computer should be assigned to the designed system: select the Object properties, and then in the tab General select the designed computer.

Figure 4.7. Computer Assignment to Object

The object adding is performed with the right-click menu by selecting the command Insert → Object (Fig. 4.8).

The sub-object of the main element – Object – is our automation object Workshop with the Tank E-1 within it. There is a graphic window – mnemonic diagram – in each object, which contains all the essential characteristics of technological process and equipment conditions. Normally, mnemonic diagram displays the technological scheme of the object, where the equipment is represented as mnemonic, or «viable» images. The image condition is characterized with their discoloration, location or forms, and the parameters are displayed as «panel» instruments. Only the main equipment and basic parameters are displayed on the workshop level. Unnecessary specification is not helpful. It is also important on the workshop level to draw up reports about the supplied materials and output products. To observe the parameter behavior in time, what is very important, there is the Trend file. The trend’s opportunities are more considerable, e.g., it can display the

45

parameter dependence. Message logs is another essential file tab. By means of message logs the object events are monitored: both technological events as the start and the end of technological cycles and operations and also abnormal, alarm events: overriding the predefined limits, valve failure, etc. It should be considered that there are several files of the same type. It depends on the information structure you want to get. But one mnemonic diagram will be always the prime component, it is the object face. Usually, this diagram is used to locate other file buttons.

Figure 4.8. Add the Object

We will work with the Tank E-1 object within this laboratory work.

Mnemonic Diagram Creating

As announced, mnemonic diagrams (graphic windows), trends, message logs, reports can be created for each object. The program provides the graphic window categorizing as several graphic windows of different purposes are

46

needed for the same object in real projects (mnemonic diagram, control window, setting window, etc). The full list of graphic file types and their basic settings are adjusted on the Window Properties tab in the root node of the System tree: size by default, window opening and displaying in executive mode.

Figure 4.9. Window Properties Dialog

Generally, designers start from mnemonic diagram creation. To create a mnemonic diagram of an object go to the Window Properties tab, select Mnemonic Diagram in the table and click the button Create. If the mnemonic diagram was created earlier, click Edit to open it.

47

The MasterSCADA interface has been changed (Fig. 4.10) – two trees are displayed as before, but instead of Window Properties tab a blank page pops up, where the mnemonic diagram to be created. There is an additional toolbar above this page and other five toolbars on the right-hand side: Elements, Inputs, Outputs, Palette, Properties.

Figure 4.10. Mnemonic Diagram Creation

To display the mnemonic diagram in full screen mode execute the command File → Full Screen Mode or press <F11> hot key. Return to the previous mode is also performed by pressing <F11> or by clicking the icon shown in the figure 4.11.

48

Figure 4.11. Return From Full Screen Mode of Mnemonic Diagram Development

Task. Set the mnemonic diagram size and background using the Properties toolbar (Fig. 4.12).

Figure 4.12. The Properties Toolbar

To start the project in Runtime mode just from this mnemonic diagram mark in Windows tab the Starting mnemonic diagram (Fig. 4.13).

Figure 4.13. Setting the Starting Mnemonic Diagram Option

49

Main Types of Variables

The main variable types used in the project tree include: • value; • command; • calculation; • event.

Adding to the object is performed with the right-click menu (Fig. 4.14).

Figure 4.14. Main Variable Types

The main difference between the types lies in their purposes.

Value is a variable that is able to take on the external value. The value of any other variable can be written in the variable of the value type. If this variable is considered as an object, then this object has the input but no output. The

50

basic properties of Value are type of values (analog, discrete, string, etc.), range of application, poll period, value monitoring, etc., (Fig. 4.15).

Figure 4.15. The Value Type

Task. Study the Value properties.

Calculation is a variable that can be processed due to embedded formula editor (Fig. 4.16). If this variable is considered as an object, then its input value is calculated in formula editor, and the output value can be assigned by e.g. the Value variable.

Figure 4.16. The Calculation Type

This example shows that the variable Calculation 1 is equal to the double of Value 1.

Task. Study the Calculation properties.

Command is a variable that has the output and applied to set the values of other variables, which are connected with it (Fig. 4.17).

51

Figure 4.17. The Command Type

Task. Study the Command properties.

Event is a variable that includes not only the formula editor but also has the opportunity to start a certain action based on the value obtained from the given formula.

Figure 4.18. The Event Type

Task. Study the Event properties.

The Project Tree Design

Suppose the task is the liquid level maintenance in a tank by the drain valve control with constant liquid supply.

52

As this project is not connected to the real hardware signals will be emulated through the formula editor of the variables Calculation and Events.

Let’s add a command and name it Target Value. Its value is the predetermined liquid level. Set the value 25.00 in the Output Poll tab (Fig. 4.19). This is default level value by running the project in the Runtime mode.

Figure 4.19. Properties of Target Value Variable

Add the Calculation variable and name it Level. Use the equation of liquid level changing based on IF structure (Fig. 4.20).

Figure 4.20. Adding the Equation for the Level Variable

To add the equation for the liquid level changing select the Level variable and open the Formula tab. Add the Target Level and Level variables in the Variable List window (adding is performed by dragging the variables from the project tree into this window with the LMB). When the variable adding has been

53

completed, make up the IF – equation(Level < Target Value, Level+1, Level-1). This structure works in the following way: if Level < Target Value, then Level+1, otherwise Level-1.

Set the value before the poll 0.0 in the Output Poll tab of the Level variable.

Then, add a variable that indicates the valve state (open/closed). Add the variable Event in the project tree and name it State. Since the predefined level maintenance is controlled with the drain valve, the valve should be closed when Level < Target Value, and when Level > Target Value it should be open. Insert this condition in the Formula tab (Fig. 4.21)

Figure 4.21. Drain Valve State

So, if the Condition variable gets the value of Boolean unit, the valve is open, otherwise it is closed. Add the Calculation variable named Inverted State, which will indicate the valve inverse state (Fig. 4.22).

Figure 4.22. Valve Inverted State

54

This variable is required by the valve state visualizing.

The emergency valve opening is the next step that should be specified if the Level goes over the emergency limits. In case of emergency the valve should open and the Target Level comes to the value 0.0.

Add the Event variable named Emergency in the project tree. Suppose the emergency occurs when the liquid level value exceeds 85 %. Then the equation of this emergency is Level >= 85 (Fig. 4.23)

Figure 4.23. Emergency Equation

Meeting this condition the Emergency variable gets the value of Boolean unit. In this case the Target Value should be equal to 0.0.

For the Target Value assignment the additional variable is required with the value of 0.0. Add the Calculation variable named Target Value Reset and assign the Constant value 0.0 in the Output Poll tab (Fig. 4.24)

Figure 4.24. Constant Value Assignment of the Target Value Reset

55

Let’s return to the Emergency variable and add the action Assign to the Target Value. This operation is performed in the properties tab Actions (Fig. 4.25). Select Assign in the Action field. Drag the Target Value variable into the Object field and the Target Value Reset is to be dragged into the Parameter field.

Figure 4.25. Action Adding in the Emergency Variable

Then, the valve should be added into the project tree. Use the embedded libraries for the purpose (Fig. 4.26).

Figure 4.26. Adding the Mnemonic Valve into the Object Tree

56

Select Mnemonic Valve in the Libraries folder Actuators and click the object in which the valve should be added – the Tank E-1 in this instance). Next the valve parameters should be connected with the project tree variables: the State variable to be connected with the mnemonic valve value Open, and the Inverted State to be connected with the Closed variable. The connection is performed by dragging the one variable on the another one. As a result, the pink vertical line is displayed in the project tree (Fig. 4.27).

Figure 4.27. Parameter Connection in the Project Tree

So, the project tree is realized to maintain the tank liquid level. This project tree will be extended with new variables by solving further problems such as trend creating etc. However, the next stage is to visualize the control process of the tank liquid level.

3. Visualization of Technological Process

Before starting the process visualization it should be noted that the solution of the same visualization problems can be performed in the software in a variety of ways. This laboratory operation manual provides the simplest and intuitive methods of visualization.

Each visualization in SCADA starts from creating a mnemonic diagram, setting its resolution, background, and other properties. It was considered in the previous sections. The next step is layout of information about the process and the project control tools and navigation service.

Open the mnemonic diagram in the full screen mode and create a tank and pipe lines within this diagram. Select Palette in Volume Elements division (Fig. 4.28).

Then the valve should be added into the mnemonic diagram. Press the F11 hot key to escape the full screen mode. The project tree is displayed on the left-hand side. Drag the Mnemonic Valve with the LMB (Fig. 4.29).

57

Figure 4.28. Creation of Tank and Pipe Lines

Figure 4.29. Adding the Valve into the Mnemonic Diagram

58

Task. Set the valve colors: green corresponds to the open state, red is closed. Turn the valve upright, place it near the pipe line and accomplish the pipe line. To complete the task click the Valve object with the RMB and select the Properties option in the context menu (Fig. 4.30).

Figure 4.30. Valve Properties

As a result the image presented in figure 4.31 should be displayed.

Figure 4.31. Valve Built-in Mnemonic Diagram

The next step is the liquid level dynamicizing. Select the tank in the mnemonic diagram, click the Properties and click the Input icon (Fig. 4.32).

59

Figure 4.32. Level Dynamicizing

Select the Fill Ratio in the Fill folder and drag the Level variable from the project tree into the Fill Ratio field. Then on the right-hand side of the Fill Ratio click the ellipsis icon (Fig. 4.32). Adjust the dynamicizing settings in the pop up window (Fig. 4.33).

Figure 4.33. Dynamicizing Settings

60

So, the task of dynamisizing is completed.

To change the Target Value in the on-line mode a slider should be inserted into the mnemonic diagram. To insert a slider drag the Target Value from the project tree into the mnemonic diagram and select Slider in the menu. Drag the Level variable twice in the same way and select Indicator at first and then Graph in the menu (Fig. 4.34).

Figure 4.34. Current Mnemonic Diagram

4. Online Project Launch

Launch the project in the on-line mode. To start this, press the icon shown in picture 4.35.

Figure 4.35. Project Launch in On-Line Mode

Enter the account previously created into the logon window.

Try to change the Target Value, check the correctness of the visualization.

State Indicators

Add state indicators of tank liquid level: • below normal (Level <= 10); • normal (10 < Level < 80); • above normal (Level >= 80).

Add three Events to the project tree and define the state conditions in the properties of Formula tab. Then, drag these Events from the project tree into the mnemonic diagram and select the Mnemonic Indicator in the menu. Select

61

Text in the Drawing Primitives section from the Palette and write down the mnemonic state indicators (Fig. 4.36).

Figure 4.36. Mnemonic State Indicators

Launch the project online and check the correctness of state indicator work.

Trend Creating

Select the Tank E-1 object and click Add in the Trends tab. Insert the trend name in the pop up dialog (Fig. 4.37). Drag the Level variable into the coordinate grid and save changes. So, the trend for the Level variable has been created

Figure 4.37. Trend Creating

Report Creating

A report is created in the similar way. Click the Tank E-1 object and open the Reports tab in its properties. Click the Add Report button and insert the report name (Fig. 4.38). Then, add the comment in the Excel cell and drag the required parameters from the project tree (Fig. 4.39).

above normal

normal

below normal

62

Figure 4.38. Report Creating

Figure 4.39. Adding a Parameter to Report

Control Tools Creating

By opening the project online generally, it starts working from the starting mnemonic diagram, from which different services, mnemonic diagrams and other data reporting forms can be called by means of control tools, e.g. buttons.

Add the control buttons to the designed mnemonic diagram to provide the call functions:

• current mnemonic diagram print; • trend; • action log; • operator change; • message windows; • stopping the runtime mode.

Add the Command variable to the project tree, name it Print Mnemonic Diagram and select the Discrete Type. Click Apply, and the Action tab should appear (Fig. 4.40).

Set the Print action in the Action tab of the Mnemonic Diagram object. To add the Print Mnemonic Diagram button to the mnemonic diagram drag

63

the command Print Mnemonic Diagram from the project tree and set its name in the button properties.

Figure 4.40. Adding Print Mnemonic Diagram Command

Task. Add the Trend, Report, Action Log, Operator Change, Message Windows, Runtime Stop call buttons to the mnemonic diagram in the same manner (Fig. 4.41).

Figure 4.41. Project Control Buttons

System Access

Create a new account with browsing access (Fig. 4.42).

Figure 4.42. Creation of new account

Print Trend Report Message Operator Action Log Stop

64

Suppose, the access to the Stop button should be assigned for the Browsing position (account op). The access to the Stop button isn’t allowed for the Browsing position by default. Select the command of the project stopping and open the Access Right tab from its properties. Select the Set Value and mark the access for the Browsing position (Fig. 4.43).

Figure 4.43. Set the Access Rights

Then, go to computer properties into the Access Right tab and mark the access for the Browsing position in the Project → Disable Execution settings (Fig. 4.44).

Figure 4.44. Set the Access Right in Computer Properties

Start the project in online mode under the new account for the Browsing position. Check the correctness of access to the Stop button.

Task. Create several accounts with different access rights in the system. Start the project in online mode and make certain that the system runs correctly.

65

Checklist and Tasks

1. What kind of information can be obtained from the project tree and what is the purpose of the computer element?

2. Describe adding the Object and Mnemonic Diagram elements within MasterSCADA.

3. Describe the basic types of variables in MasterSCADA and their purposes.

4. Change the operating logic of the mnemonic diagram in such a way as to the Emergency indicator will light up and the mnemonic diagram will stop running when the liquid level exceeds the predefined target value.

5. Change the operating logic of the mnemonic diagram in such a way as to the fill color of liquid – inflated part of the tank will change when the liquid level changes. The color range is set optionally.

66

Laboratory Work № 5 DEVELOPMENT OF PACKAGED SOFTWARE

OF TANK LEVEL CONTROL

Purpose

The purpose of this section is to describe a possible variant of data exchange between middle level and upper level software using the OPC server.

Task

Realize data transmission from CoDeSys to MasterSCADA required for the tank level control based on algorithm designed within the Laboratory Work № 3. Visualize the level control in MasterSCADA on the basis of the data obtained.

Codesys OPC Setting

The required software: Codesys (with installed Codesys OPC, Codesys SP PLCWinNT), MasterSCADA.

The platform 3S CoDeSys SP PLCWinNT V2.4 should be set in Configuration field and Download symbol file should be marked in the General tab (Fig. 5.1).

A project with the target system to be created and the Download symbol file parameter in the tab General to be set (Fig. 5.2).

Figure 5.1. Target Settings

67

Next, the software in IEC 61131-3 languages is to be developed in the project.

Start the PLCWinNT (Start → All programs → 3S Software → CoDeSys SP PLCWinNT → CoDeSys SP PLCWinNT V2.4) and a message window pops up informing that the license is left and the program runs in demo mode. The only limit for the demo program compared to major version is the two hour operating time limit. After two hours this SoftPLC will stop working which demands the restart.

After starting this SoftPLC the connection between the SoftPLC and CoDeSys should be created.

To set the SoftPLC and CoDeSys connection select in menu Codesys Online → Communications Parameters the setting New, insert the connection name and select the TCP/IP protocol (Fig. 5.2).

Figure 5.2. Channel Communications Parameters

The set channel is selected in Communication Parameters window (Fig. 5.3).

Figure 5.3 Communications Parameters

68

Check the setting with the command running Online → Login (<Alt + F8>). If everything is correct, a dialog will pop up with a question «The program has changed. Download the new program?» (Fig. 5.4).

Figure 5.4. New Program Download in PLC

If the connection is set correctly, the program download will be performed and the PLCWinNT window displays the project information (Fig. 5.5).

Figure 5.5. The PLC simulator window (PLCWinNT)

After the connection stability has been confirmed the CoDeSys and SoftPLC should be disconnected (Online → logout or <Ctrl + F>). Then, go to Options in the Project menu. Select the Symbol Configuration and mark the Dump symbol entries (Fig. 5.6).

69

Figure 5.6. Symbol configuration

Press the Configure symbol file button (Fig. 5.7).

Figure 5.7. Parameter Configurations

It should be pointed out that the grey tick in the Export variables of object box indicates that there are parameters in the selected objects (these are all objects at the moment), which have been already entered into the list for OPC server transmission. If just the certain variables are to be transferred, other

70

data should be delisted. To exclude undesirable data unselect the Export variables of object and mark just the required parameters (Fig. 5.8).

Figure 5.8. Setting the Parameter List

Everything concerned the programming environment has been completed. Now the OPC server parameters should be set. To perform this task start the OPC server configurator: Start → All Programs → 3S Software → Communication → CoDeSys OPC Configurator. Click by the right mouse button on the Server element and select Append PLC. Select the Connection element and press the Edit button . The CoDeSys Communication dialog will pop up. Select the connection which was set earlier in the project (Fig. 5.9).

71

Figure 5.9. OPC Configurator Setting

All setting have been adjusted. If we start the project now, everything will run incorrectly because files, which include the parameters for the OPC server transmission, are created during the project compiling. The parameter transferring to the server is performed by downloading the project into controller. Changes in the symbol file parameters doesn’t result in the project change. And by the next connection to the controller the download will not be performed (because the project was downloaded by the first connection when the connection was tested), so the parameters to the OPC server also will not be transmitted.

To correct the situation the compiled project should be downloaded again after cleaning the PLC simulator storage. Execute the commands Clean All in

72

the Project menu and then, Rebuild All in the same menu (Fig. 5.10). Then, the CoDeSys will recompile and reload the project by the PLC connection and transfer the data to the OPC server at the same time.

Figure 5.10. Cleaning and Rebuilding the Project

When the project runs, the OPC server update the parameters with the discreteness predefined in the OPC configurator (we left the default setting).

Next, the data exchange with the upper level software should be realized. As the upper level software the MasterSCADA is used.

Create a project in MasterSCADA. Add a computer into the project. Adding the Computer 1 is presented in figure 5.11.

Figure 5.11. Adding the Computer

73

Then, the OPS server search to be preformed: click with the right mouse button on the Computer → OPC search. Select the OPS server for CoDeSys from the displayed list and insert the OPC variables: click on the OPC server for CoDeSys with the RMB (Fig. 5.12).

Figure 5.12. Insert the OPC Variables

Select the required parameters in the pop up window (Fig. 5.13).

Figure 5.13. Variable Selecting

74

The results are presented in figures 5.14 (offline) and 5.15 (online).

Figure 5.14. List of Variables in Offline Mode

Figure5.15. List of Variables in Online Mode

Task. Concerning the information presented above transfer the parameters from CoDeSys which are required for your task to visualize the tank level control (liquid level, valve state, etc.) and add these parameters to the MasterSCADA mnemonic diagram. As a result, a similar picture will be obtained (Fig. 5.16):

75

Figure 5.16. Visualization of Algorithm for Tank Level Control in MasterSCADA

Secondary Assignments

1. Display the valve opening and the current liquid level relation in the MasterSCADA diagram. The diagram data should be received from CoDeSys.

2. Realize the object (a rectangular) motion from the Laboratory Work №1 in MasterSCADA having the visualization data transferred.

3. Display the output values and filtered signal in the diagram designed within the Laboratory Work № 2.

Educational Edition

Национальный исследовательский

Томский политехнический университет

ЕФИМОВ Семён Викторович

ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ АВТОМАТИЗИРОВАННЫХ СИСТЕМ

Лабораторный практикум

Учебное пособие Издательство Томского политехнического университета, 2014

На английском языке

Published in author’s version

Scienсe Editor Doctor of Technical Sciences, Professor

G.P. Tsapko

Linguistic Advisor N.V. Kurkan Typesetting V.D. Pyatkova

Registered at TPU Publishing House

Available on a TPU Corporate Portal in full accordance with the quality of the given make up page

Tomsk Polytechnic University Quality management system

of Tomsk Polytechnic University Publishing House was certified in accordance with ISO 9001:2008 requirements

. 30, Lenina Ave, Tomsk, 634050, Russia Tel/fax: +7 (3822) 56-35-35, www.tpu.ru