Twincat 3 Project Development Steps

Twincat 3 Project Development Steps

TwinCAT 3 Project Development Steps

Lamp Control

17/10/2014

This tutorial describes all necessary steps in the development of a PLC application for control of a standard ESO Lamp device. The same steps, with minor differences, are applicable for other ESO Standard PLC devices, e.g. Shutter devices.

Creating New Project

  1. Create new solution (File / New / Project…) and select TwinCAT Project / TwinCAT XAE Project (XML format) and give it a name (e.g. DemoLamp). Select the location where to save the solution and then press OK to continue.
  2. Right-click on PLC and select Add New Item…
  3. From Plc Templates select Standard PLC Project and give it a name (e.g. again DemoLamp). Press Add to continue.
  4. Under PLC/DemoLamp expand DemoLamp Project and then expand the References.
  5. Right-click on References and select Add library… On the pop-up dialog, under Company, select ESO. Expand (Miscellaneous) and then select the libraries to include. Every project requires the library called ESO TC3 Common Library. In addition, a specific library for the device has to be included, e.g. ESO TC3 Lamp Library. Include all libraries needed for the project (hold the Ctrl key and make multiple selections) and then press OK to continue. The libraries will appear under References.
  6. Save the project.

Connecting to Target PLC

  1. Click on the current Target on the Toolbar. The target can be <Local> or any other PLC target. Ensure that <Local> is selected . Click on <Local> and then select Choose Target System… and on the pop-up click on the Search (Ethernet) button.
  2. On the Add Route Dialog under Enter Host Name / IP input field enter the PLC name or its IP address. Make sure that the corresponding radio button selection (Host Name or IP Address) in the lower left corner corresponds to the type of data to be entered.
  3. Press Enter and wait until the list of hosts is displayed. Find the target PLC to be used in the list and select it . If there is no an X under the Connected column, press the Add Route button and wait until the X appears. Press the Close button to continue. Note, if an X is already there, just press the Close button to continue. Press OK again. The target PLC is now displayed on the Toolbar.

Discovering PLC I/O Terminals (Scan)

  1. Switch the PLC to Config Mode, i.e. click on the Restart TwinCAT (Config Mode) Icon . This can also be done from the top menu by clicking on TwinCAT and selecting Restart TwinCAT (Config Mode). Confirm the action with OK. After a couple of seconds the Run icon in the lower right corner of the screen should become .
  2. In the project tree, under I/O, right-click on Devices and select Scan. Confirm with OK.
  3. Under found devices select only Device 1 (EtherCAT) and Device 4 (NOV-DP-RAM). Press OK to continue.
  4. Press Yes when asked to Scan for boxes.
  5. If the PLC application involves motor control, select Yes when (and if) asked about the NC-Configuration. Otherwise select No.
  6. Select No when asked to Activate Free Run.
  7. Save the project.

Writing PLC Program

  1. In the project tree, under PLC / DemoLamp / DemoLamp Project / POUs, double-click on MAIN (PRG). The program MAIN will be open for editing.
  2. Under VAR add an instance of a lamp, e.g. “Lamp1: FB_LAMP;”. The correct FB name, i.e. FB_LAMP, can be found by pressing F2 (Input Selector) and then under Structured Types / ESO_TC3_Lamp_Library / POUs select FB_LAMP.
  3. Under the code part in the editor, write “Lamp1();” and save the project. The complete program looks like this:
  4. Under the Build pull-down menu, select Rebuild DemoLamp and ensure that there are no errors or warnings in the Output window.

Mapping of Program Variables to Physical I/Os

  1. Under DemoLamp Instance expand both PlcTask Inputs (yellow) and Outputs (red), as shown below. These attributes are available for linking/mapping to the physical I/Os. Depending on the hardware configuration, e.g. if there is intensity control or fault feedback signal, not all of them have to be mapped. Signals i_bOn (feedback status), i_nCouplerState (operational state of the system) and q_bSwitch (lamp control output signal) have to be mapped for every lamp.
  2. Under I/O / Devices / Device 1 (EtherCAT) expand the terminal whose I/O signal is to be linked to the program variable and right-click on it. For example, right-click on Term 8 (EL2008) / Channel 1 / Output and select Change Link… Select MAIN.Lamp1.q_bSwitch and press OK to continue. Do the same for all other links.
  3. Link MAIN.Lamp1.i_nCouplerState to the State of the coupler that hosts the I/O terminal (e.g. EK1100) or the State variables of any other I/O terminals. This link is mandatory and it is used as a check if the system is OPERATIONAL. If the link is not established, it will not be possible to initialize the device.

Instantiating Device GUI from the GUI Template

  1. Right-click on VISUs and select Add and then select Visualisation…
  2. Give the name, e.g. GUI and press OK.
  3. A new tab, called GUI will appear next to the MAIN tab.
  4. In the lower right corner of the screen click on Toolbox and then expand the Basic list. Drag and drop the Frame onto GUI.
  5. On the Frame Configuration popup, under Available Visualisations, select LAMP_GUI_TEMPLATE and then click on Add under Selected Visualisations. Click OK to complete.
  6. An instance of the Lamp GUI will appear. Click on the lower right corner of the inserted frame and enlarge it enough to cover the complete GUI.
  7. Click on the Properties tab in the lower right corner of the screen.
  8. Under Position, set X and Y values to zero.
  9. Under References / ESO_TC3_Lamp_Library.LAMP_GUI_TEMPLATE / m_DeviceName enter ‘Lamp1’ (note the single quotes!) and press enter.
  10. Under m_Instance enter MAIN.Lamp1 and press enter. The References now look like this:
  11. Save the project.

Activating Configuration and Logging in

  1. Activate the Configuration, i.e. click on the Activate Configuration Icon. This can also be done from the top menu by clicking on TwinCAT and selecting Activate Configuration.
  2. When asked, confirm the action with Yes or OK. Confirm that the system should be Restarted in Run Mode. After a couple of seconds the Run icon should appear in the lower right corner of the screen indicating the Run Mode.
  3. Click on the green Login icon to log into the PLC and automatically download the program. This can also be done from the top menu by clicking on PLC and selecting Login.

Controlling Device from the GUI

The figure on the left shows how the lamp GUI appears when it is just started and the lamp is not initialised yet. The one on the right shows the status when the lamp is in Local Control and ON.

GUI Lamp jpg GUI Lamp ON jpg

  1. After Login is complete, switch to the GUI tab.
  2. Select Local Control to enable buttons and entry fields on the GUI.
  3. Press the INIT button to initialize the device. The LED next to it will become green once the device is initialized.
  4. Set Intensity, if used, and turn the lamp ON/OFF with the corresponding buttons. Monitor the status of the device.
  5. Enter some values for Warmup and Cooldown and repeat the control exercise.
  6. Save the project.

Configuring Operational Mode on PLC Boot and OPC UA Server

  1. Double-click on PLC / DemoLamp. In the DemoLamp window, under the Project tab, check the Autostart Boot Project check-box. With this setting the PLC will reboot in Run Mode.
  2. Under the Settings tab, under the Target Files section, check both TMC File and TPY File. These files are needed for the OPC UA Server.
  3. Save the project and then Activate Configuration.
  4. Confirm with OK and once again to Restart TwinCAT System in Run Mode.
  5. Login again.

Controlling Device from OPC UA Clients

  1. Start an OPC UA Client, e.g. UaExpert.
  2. Select the Target OPC UA Server and Connect.
  3. Find the instance of Lamp1 under Root/Objects/PLC1/MAIN.
  4. Expand Lamp1 in order to display cfg, ctrl, info and stat folders.
  5. Drag and drop all stat attributes to the Default DA View. Do the same for the ctrl attributes.
  6. Initialise the lamp by setting nCommand to 1 and then bExecute to TRUE (1).
  7. To turn the lamp ON, nCommand = 3 and bExecute = TRUE (1).
  8. To turn the lamp OFF, nCommand = 2 and bExecute = TRUE (1).
  9. Control and monitor the status of the device from both environments OPC UA Client and TwinCAT 3.

OPCUA View Lamp All jpg