The following apps must be installed on your IED in order to complete this guide:
Download the provided TIA Portal V17 project into your PLC. It was originally compiled for a CPU 1212C FW V4.4, so you may need to adjust the device settings if you're using a different device. In case no PLC or simulation is available, you can use Flow Creator. Once running, the Data Block GlobalDB_LiveTwin [DB62]
contains two variables of data type Real
: pump_speed
is the value that will be used as input for the simulation, and flow_rate_l_min
is the calculated flow rate in l/min
that will be written back to the PLC from LiveTwin.
Configure a user in the Databus configurator and give this user permission to publish and subscribe to the topic ie/#
. This is where the data will be exchanged between the S7 Connector and LiveTwin.
Next, we need to configure the two data points in the S7 Connector. Start by configuring the Databus credentials (created in the previous step) in the upper left corner.
Add a new data source. With the provided TIA Portal program, an S7+ connection should be configured as follows (substitute the PLC IP address for your own):
The following two data points are used in this example. Note the Name, Address, Data Type, Acquisition Cycle, and Access Mode (Read or Read & Write).
This guide shows two different ways to import the Simulink model into LiveTwin. The first option is to use SIMATIC Target and export the model directly from a running Simulink instance to a running LiveTwin instance. The other way is to export the model as a .zip file and later upload it in the LiveTwin WebUI (the procedure used to generate the provided file is described in this guide).
If you want to try out the model in Simulink, you'll need to initialize the parameters by running the provided .m file in Matlab.
Open the Simulink model and go to the Settings page.
In the Code Generation tab, select the SIMATIC Target based on Simulink Coder as your target.
In the SIMATIC Target options, choose LiveTwin for Industrial Edge and enter your Edge Device IP (with /livetwin
), username, and password. Then, connect to the LiveTwin application.
In the Engineering Integration tab, configure your LiveTwin Template and Project accordingly. Cyclic time can be adjusted later in the app as well.
In the Accessibility tab, activate the checkbox.
To upload your model to LiveTwin, go to the Simulink Coder App in Simulink and click Generate Code. In LiveTwin, the model will be uploaded as a template and a project based on this template will be created.
In case you don't have access to or don't want to use Matlab Simulink and SIMATIC Target, you can simply upload the provided .zip file in the LiveTwin WebUI. Start by creating a new template like in the screenshot:
The model will be uploaded to LiveTwin.
Create a new project based on your template according to the screenshot:
Once a LiveTwin project has been created, you will have to configure the connections. Start by going to the Instance Settings.
In the Server Settings tab, configure your Databus credentials. The output topic is not strictly necessary.
In the Inputs/Outputs window, configure first the pump_speed
input with the data source and variable name you used in the S7 Connector:
And then go to the next page and configure the flowrate_lmin
(lowercase "L" for "liters") output:
Make sure that the Tag Names given here match the names of the variables that were configured in the S7 Connector.
To obtain sensible results, you can adjust the model parameters pressure_pipe_length
and pressure_pipe_outlet_height
, for example as follows:
Apply the changes. The model is now configured and ready to run.
Start your model instance:
in the Monitoring window (left menu), open the chart for your running instance:
Select the relevant variables to monitor:
Start Update in the upper right of the monitoring window. You should now see the input and output variables with changing values.
In TIA Portal, you can go online on the PLC and observe that the result flow_rate_l_min
has been written back to the PLC from LiveTwin.
The flow rate has thus been indirectly measured based on a Simulink model and the measured pump speed, removing the need for a hardware sensor.
In case you have no PLC available, you can also run the LiveTwin model in Flow Creator mode and provide inputs within Flow Creator directly. You can use the provided flow to simulate input values.
In order to use Flow Creator, you have to select Flow Creator as the model type during project creation:
Import the provided flow and edit the LiveTwin node:
Select the model project you have created in LiveTwin:
Use the button to start or stop the instance:
You can then view the running model in the Monitoring tab of LiveTwin as usual, or observe the outputs in the "Output" debug node in Flow Creator.