OPC UA Tank System

This example will demonstrate the usage of OPC UA communication in a SystemModeler model over a simple tank system. OPC UA is a secure, robust and scalable communications protocol used in many different industries over the world. See the OPC Foundation website for more information.

SystemModeler 4.3.

Why Is OPC UA Useful Together with SystemModeler?

To be able to integrate SystemModeler’s modeling capabilities with real-world objects in real time is very powerful. Using OPC UA, safe communication between hardware, such as a Raspberry Pi or a PLC, and simulation models becomes possible.

Communication Using the OPCUA Library

The example model consists of a simple tank system that can communicate through the OPC UA protocol. The measurement of the liquid level of the first tank is written to a real-valued node on the OPC UA server. This value is then read by another component, to be used as a reference for the liquid level of the second tank.

The diagram view of the tank system using OPC UA communication.

Integrating OPC UA communication in SystemModeler models lets industries using OPC UA connect signals directly into a model with live data. That opens up many possibilities when it comes to control theory, signal processing and much more.

How Does It Work?

The SystemModeler components defined in the OPCUA Modelica library are using external C code to call functions to an implementation of the OPCUA Library in C code. Through the OPC UA components in SystemModeler, values can be both written and read to nodes on an OPC UA server. Since OPC UA is multiplatform, compared to OPC Classic, the OPC UA server can also run on small chips or on a Raspberry Pi, for example.

External C Code

By calling external C code, SystemModeler can communicate live to any compatible external hardware, using OPC UA.

Plot over both tank levels over time. The first tank starts full (1 m) and then gets drained. The measurement of the liquid level in the first tank is being written to the server at a sample rate of 0.2 s. The bottom tank uses the measurement of the first tank as the reference value for its liquid level, which can be seen in the bottom plot.

Connecting SystemModeler to Hardware

It is of course also possible to replace the models of the tanks with values coming from sensors of real liquid tanks, or to just connect some hardware to control the reference signals to the tanks in the model. We are going to show you how to do the latter. To get these signals into the model, you could either use ModelPlug, as in this example, or use Mathematica to connect hardware with a running simulation. To be able to run a model like this, you would of course have to have access to an Arduino or something similar.

This is how the model diagram view looks if you are using ModelPlug to connect to external hardware to control the reference signal of the first tank and the inflow of liquid to the second tank. This model serves well as operator training.

Image of the Arduino with knobs that control the reference values for the tanks. It is connected to the simulation in SystemModeler through the ModelPlug Library.

Plot of the inputs from the knobs (top) and both tank levels over time (bottom). The first signal sets the desired liquid level in the first tank. The second signal sets the inflow of liquid to the second tank. However, the second tank will still try to keep the same liquid level as the first tank and will follow faster or slower depending on the inflow.

If you actually had real tanks with liquid and sensors, you could replace the tank models in the model above with only sensor data. In that case, inputs and outputs from the tanks using Arduinos to connect to SystemModeler could be used, as well as OPC UA to transfer the sensor data between the tanks. For more use cases, see also how OPC Classic can be used.

OPC UA

Use industrial communication protocol OPC UA in SystemModeler to communicate with systems in the real world.