Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMPSYS 725 Distributed Cyber-Physical Systems Design

Department of Electrical, Computer, and Software Engineering

IEC 61499 Function Blocks Lab

Objectives:

1.    Gain hands-on experience with FBDK, the industry reference implementation of IEC 61499 Function Blocks (FBs).

2.    Experience creating, compiling, testing, and modifying a Basic Function Block (BFB) type.

3.    Experience execution of distributed FB applications.

4.    Modifying a Composite Function Block (CFB) to increase its functionality.

Use the Answer sheet provided under  Canvas  Modules>Part  2  Lab>  CS725_Part2_Lab_Questions to answer the questions in the lab sheet, and submit it on Canvas Assignment> Lab 2 submission. The answers will not be marked. So, just put in brief answers/screenshots in the answer sheet provided.

Submitting the answer sheet is worth 1% of the final grade.

How to Install FBDK

•    Download the fbdk.zip file from Canvas. Extract this file to your local drive (H: drive is you are working on a University PC).

•    Inside,  you  will  find  "editor.jar".  You  can  run  this  by  opening  a  command  prompt  and  writing  "java  -jar editor.jar".

•   Alternatively, if you are on windows, you can double click "editor.bat".

NOTE:  Do  not run the  editor.jar  directly,  as  FBDK  outputs  debugging text to the terminal.  If you have  no terminal, you cannot see the text.

•    If everything works, you will be prompted with an EULA (Figure 1), which you can agree with to continue.

Figure 1: EULA for FBDKtool

Then you will be shown the editor view as in Figure 2.

Figure 2: FBDK editor view.

Modify an existing Function Block (FB) type

•    Open function block type X2Y2_ST using File/Open  (/student/X2Y2_ST.fbt). Try to run it by clicking at the "Launch" button1.

•    Perhaps  you  will   see   something   like   shown  in   Figure   3a   Error!   Reference   source   not   found the

"UNSUPPORTED_TYPE" error message. This is because the block has not been compiled yet. Compile the block to the Java class by File/Save as. You will see the Save window (Figure 3b) where you need to tick the box next to Java (if you have changed anything in the block, then the box next to XML should also be selected) and OK.

Make sure that in the field "Package" you see fb.rt.student.

•    If you see the window shown in Figure 3c, the compilation was successful!

•    In case you something like in Error! Reference source not found, as shown in Figure 3d, then the preference needs to be changed by clicking on the Preference icon2. Edit the location where java sdk/jre was installed.

Don't forget to click on save! (You need the Java JDK installed in your computer. If only Java JRE exists, then

install JDK. The java and javac PATH variables should point to the same bin folder in the JDK installed on your computer.) The recommended JDK version is 1.8.

•    In the  Preferences,  also  set the  log  to  be  "ON".  This  will  ensure  that the  execution trace  appears  on the command line. If you do not have a command line, you may have to install Java JRE to make sure that the

command line appears when you run FBDK.

Figure 3a: UNSUPPORTED_TYPE error

Figure 3b: Save window

Figure 3c: Compilation succeeded window

Figure 3d: Setting preferences

Note:

1.           The above steps of setting the Preferences have to be done only once during the first instance of installing the FBDK tool. (have to set the log = "ON" every time, though! It is "OFF" by default.)

2.           The default behaviour of FBDK when closing is to "discard changes". Be careful to save your work.

3. Also, if you make changes, save and still the change is not observed when you Launch it, then restarting FBDK tool can solve the issue.

4. If the FBDK tool behaves differently than expected, restarting will often solve the issue. (You may end up restarting many times during your assignment!)

a. Launching the Function Block:

Now run the block in the test environment by Launch/ X2Y2_ST. The test environment produces a frame in which you can test just one function block by entering its input parameters. Unfortunately, not all of the input fields have labels, so you need to guess. The Function Block X2Y2_ST is given in Figure 4a, and the testing window is shown in Figure 4b.

Question 1: Give X = 4, Y = 2. What is the observed OUT?

Question 2: What operation is the Function Block performing on X and Y?

Figure 4a: Function Block X2Y2_ST with the events and variables.

Figure 4b: Testing of X2Y2_ST. Enter the input X and Y to observe output OUT.

b. Changing the name of the Function Block:

Now let us change the function block type name to MY_X2Y2_J.fbt by clicking the Name/Comment item in the tree in the editor's left pane. Save the block (tick on XML).

c. Modifying the block functionality

Now you can start making some modifications. For example, let us change the formula and compute X2  + Y2 .

•    For doing that you need to modify algorithm REQ, which will be written in JAVA instead of original Structured Text (ST). Just double click on it and you will see the Figure 5.

•    Click Java radio button and the structured text algorithm will be automatically converted to equivalent JAVA text. Now change the code in the box to: OUT.value = X.value*X.value+Y.value*Y.value;

Note, that all function block variables are objects, that is why their values are accessed by X.value, Y.value, etc.

•    Try  to  run  by  Launch/MY_X2Y2_J What  happened?  You  again  get  the  message  UNSUPPORTED  TYPE. Remember that you have changed the block's name, but have not compiled it with new name yet. Compile the

new block by saving it as Java (tick on Java, then OK) and try to run it again.

Make sure that the block computes now X2  + Y2!

Figure 5: Algorithm window for the Function Block.

Question 3: Give X = 4, Y = 2. What is the observed OUT?

Question 4: What operation is the Function Block performing on X and Y?

d. Adding inputs and outputs to the Function Block:

This is done by modifying the Execution Control Chart (ECC).

To add new inputs click right button of mouse on the function block shape and following menu: New/Variable/Input as shown in Figure 6a appears.

Add a new numeric input Z (of type REAL), an event input XYZ, an event output CNF2 and a data output OUT2. The intention is to modify the block so that when it is activated by XYZ event, it shall compute OUT2=X+Y+Z and signal the event CNF2.

Now, we need to associate each event with an input or output. To create an association between an event input and data input, position the mouse to the left of the event input (on the word EVENT), hold ALT and press the LEFT mouse button. (MacOS users hold CONTROL). While holding the mouse button, drag the cursor to the

data input name, as illustrated in Figure 6b, positioning the cursor at the data type name.

When you are finished adding all the new IO and associations, your FB should look like Figure 6c.

e. Modifying the block's body:

In the navigation tree, click on the ECC icon.

Go to the Edit pane. Make right mouse click and select New/Algorithm from the pop-up menu. You will see the Edit Algorithm window.

Set the algorithm name "XYZ_COMP".

Set the type to Java.

Enter java code to set OUT2.value as the sum of X.value, Y.value, and Z.value. Now your window should look like Figure 6d. Press OK to save the algorithm XYZ_COMP.

Figure 6a: New Event/Variable Menu

Figure 6c: The completed FB interface

Figure 6b: Connecting Events and Variables

Figure 6d: Algorithm XYZ_COMP

Aside: Manual editing of Function Block via the XML

All  editing  can  also  be  accomplished  by  direct  access  to  the  XML  text  of the  function  block  description.  For example, let us insert the action manually, modifying directly the XML source of the MY_X2Y2_J.fbt file as follows:

1.    In the ECC of the FB, right click and select New>State to add a new state called XYZ_S.

2.    Click on the state REQ (on the state which is the one in the box)– the corresponding XML element will be highlighted in yellow (Figure 7a).

3.    Copy the nested element and paste it to the element corresponding state XYZ_S.

4.    Modify the element: change the algorithm name (to XYZ_COMP) and output event (to CNF2), and set the x and y.

5. Parse the edited XML by pressing the Parse button3. It should now look like Figure 7b. (Note the additional elements that get added to ECC as a result of the changes in XML made.) The box with XYZ_COMP|CNF2 is called an Action. Each Action has an Algorithm (XYZ_COMP here) and an Event (CNF2 here). This means that after the algorithm is executed, the event will be triggered.

Figure 7a: Highlighted XML by selecting state REQ.

Figure 7b: Changing ECState of XYZ_S

Now you can connect the new state XYZ_S to the state START.  Remember the connector works when Alt is pressed. (Figure 8a).

•    Connect from START to XYZ_S with guard condition = 1.

•    Double-click on the transition condition from START to XYZ_S (currently – 1).

•    Select the event XYZ from the menu as follows. If the Event drop box is greyed out, select an empty data from the Guard Condition drop box (Guard Condition should not show the value 1).

•    Similarly connect from XYZ_S state to START and let the Guard Condition be default value 1 (Figure 8b).

•    Save the resultant FB, compile it, and run. Check if the block does what you want. (You may have to restart FBDK tool to observe the change in results)

Question 5: Give X = 4, Y = 2, Z = 3. What is the observed OUT?

Question 6: What operation is the Function Block performing on X, Y and Z ?

Question 7: Run and see the printouts of the execution trace in the command line window of Java. You may have to   set   Preferences   log   =   "ON"  to   get  the   trace.  Also,   in  the   algorithm  XYZ   include   a   print   statement

System.out.println ("This is in algorithm XYZ"). You can see the statement also in the execution trace.

Question 8: Without editing the XML, how will you add the Action to the state XYZ_S? (Try using left and right mouse clicks on the state XYZ_S).

Now let us experiment with changing the ECC.

1.    Delete the transition from state START to XYZ_S just right mouse click on the condition of the transition (XYZ), and select Delete from the menu.

2.   Also delete the transition from REQ to START.

3.    Then connect REQ with XYZ_S with a transition having condition XYZ.

The resulting ECC will look as in Figure 8c. Save and compile the block.

Figure 8a: Draw Transition with Guard condition

Figure 8b: Setting Guard condition

Figure 8c: Modified ECC

Figure 8d: Test values

Question 9: Give X = 1, Y = 2, Z = 3 as shown in Figure 8d. Then press XYZ. What you see?

No reaction since the block is not expecting this event input in the current state.

Confirm this with the ECC diagram. What should be done to obtain XYZ? You can see that from the START state there is no direct path to XYZ state. The first state has to be REQ, which then leads to the next state XYZ.

Press REQ, then XYZ and the OUT result 5 will be displayed (12  + 22  = 5). Now the ECC is in state REQ and if you press XYZ, then there will be reaction: value 6.0 for OUT2 and output event CNF2.

After experimenting with the modified MY_X2Y2_J, modify its ECC back to the previous version (as seen in Figure 8e). Save and compile. It will be used in further exercises.

Figure 8e: Final ECC that will be used in the System configuration

Using a modified FB Type in a System Configuration

System configuration is the only structure of IEC 61499 that is supposed to be immediately executable. It does not need to be compiled to Java. Provided that all the types used in it (devices, resources and function blocks) are compiled and stored correctly, a system configuration can be started from FBDK.

•    Open  system  configuration X2Y2_TESTL.  Explore its  devices  and  resources by  double-clicking them  in the navigation  tree  and/or  double-clicking  the  blocks  in  the  editor  pane.  You  will  find  that  this  system configuration  uses  X2Y2  Function  Block  (in  RES2,  it  is  called  TESTEE)  and  "wraps  it"  with  HMI  and communication functions.

•    Try to run it.  Since it uses the X2Y2 function block, you will need to  open and  compile X2Y2.fbt  (save as xml/java) before running the system configuration. Now it should run, and you will be presented with two windows (Figure 9). One of them has editable values in it.

•    When you edit them and press [return], the system is invoked. Remember to press return after each entry.

Figure 9: One window for each device – this is a distributed application.