Dynamic Data Acquisition

Learning outcomes

  • Choose a sampling interval from the fastest dynamics of interest and explain what aliasing does to a sampled signal.
  • Compute the lag a first-order filter adds and judge when filtering helps an estimator.
  • Explain how an estimator should use a late or missing sample.

Book chapter: Control in Petrochemicals and Polymers (Volume 12), Chapter 12, Loss-in-Weight Additive Feeders and the Holdup Their Scales Cannot Weigh (PDF).
Practice in 15 minutes: 5 · Principal Components on Plant Data, 8 · Late, Lost and Wrong Laboratory Samples
Model: Any; this page is about the data that every model is fitted to and every estimator is corrected by.
Decision: The sampling interval, the filter and how late or missing values are handled, all chosen before any optimizer runs.
Learning: Labeled, repeatable data from a simulator are the cheapest training sets a student can make.

There are many methods to acquire and send data for industrial systems with a range of proprietary and community-based standards that facilitate exchange of information between instruments, a programmable logic controller (PLC), a distributed control system (DCS), and other systems that measure, analyze, or optimize the system. Exchange of information is increasingly important, particularly for optimization solutions, as availability of information is the foundation for many automation and optimization methods. Of particular interest to this course are the methods to retrieve data, run parameter estimation or optimization algorithms, and then either display advisory results or implement a solution back into the process.

Common Communication Standards

MODBUS

ASCII or RTU MODBUS is an older standard than OPC and has several limitations that motivated the creation of OPC. Although it is an old standard, several legacy pieces of equipment still support this protocol. There are several serial or network connection possibilities including RS232, RS422, RS485 (serial) or TCP/IP (network).

This example code is a Modbus server and client that communicate using pymodbus. The code writes 115 values to integer registers. The registers start at address 40001.

# Modbus server (TCP)
from pymodbus.server import StartTcpServer
from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext

def run_async_server():
    nreg = 200
    # initialize data store
    store = ModbusSlaveContext(
        di=ModbusSequentialDataBlock(0, [15]*nreg),
        co=ModbusSequentialDataBlock(0, [16]*nreg),
        hr=ModbusSequentialDataBlock(0, [17]*nreg),
        ir=ModbusSequentialDataBlock(0, [18]*nreg))
    context = ModbusServerContext(slaves=store, single=True)

    # initialize the server information
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'APMonitor'
    identity.ProductCode = 'APM'
    identity.VendorUrl = 'https://apmonitor.com'
    identity.ProductName = 'Modbus Server'
    identity.ModelName = 'Modbus Server'
    identity.MajorMinorRevision = '3.0.2'

    # TCP Server
    StartTcpServer(context=context, host='localhost',\
                   identity=identity, address=("127.0.0.1", 502))

if __name__ == "__main__":
    print('Modbus server started on localhost port 502')
    run_async_server()

# Modbus client
from pymodbus.client import ModbusTcpClient as ModbusClient
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadBuilder
from pymodbus.payload import BinaryPayloadDecoder
import time

print('Start Modbus Client')
client = ModbusClient(host='127.0.0.1', port=502)
reg=0; address=0

# initialize data
data = [0.1,1.1,2.1,3.1,4.1]

for i in range(10):
   print('-'*5,'Cycle ',i,'-'*30)
   time.sleep(1.0)

   # increment data by one
   for i,d in enumerate(data):
      data[i] = d + 1

   # write holding registers (40001 to 40005)
   print('Write',data)
   builder = BinaryPayloadBuilder(byteorder=Endian.Big,\
                                  wordorder=Endian.Little)
   for d in data:
      builder.add_16bit_int(int(d))
   payload = builder.build()
   result  = client.write_registers(int(reg), payload,\
              skip_encode=True, unit=int(address))

   # read holding registers
   rd = client.read_holding_registers(reg,len(data)).registers
   print('Read',rd)

client.close()

See MODBUS Transfer on Data-Driven Engineering for additional information and examples.

OPC

OLE (Object Linking and Embedding) for Process Control (OPC), was developed in 1996 by an industrial automation group based on the need for a common platform for exchanging data. The OPC standard details the communication of real-time or historical plant data between control devices and computers. OPC is sometimes referred to as "Oh, Please Connect" with frequent difficulty in connecting to various computers with incorrect DCOM settings. A recent effort termed OPC-UA or Unified Architecture, is a new implementation of the software that allows communication to devices other than the Windows OS platform. In November 2011, the OPC Foundation (body primarily responsible for the OPC standard) officially renamed OPC to mean "Open Platform Communications".

This example code Show OPC DA Example Code writes to an OPC Server with an OPC DA Client with OpenOPC. The code writes 16 values to 16 individual OPC tags on a Kepware Server.

# #######################################
# OPC write
# #######################################
try:
    # OPC connection
    import OpenOPC
    opc=OpenOPC.client()
    b=opc.connect('Kepware.KEPServerEX.V5')
    #opc.connect('Kepware.KEPServerEX.V5','localhost')

    Load1_avg  = opcm[0][0]
    Load2_avg  = opcm[0][1]
    Load3_avg  = opcm[0][2]
    Load4_avg  = opcm[0][3]
    Load1_max  = opcm[1][0]
    Load2_max  = opcm[1][1]
    Load3_max  = opcm[1][2]
    Load4_max  = opcm[1][3]
    Load1_min  = opcm[2][0]
    Load2_min  = opcm[2][1]
    Load3_min  = opcm[2][2]
    Load4_min  = opcm[2][3]
    Load_T12   = opcm[3][0]
    Load_T21   = opcm[3][1]
    Load_T32   = opcm[3][2]
    Load_T41   = opcm[3][3]

    opc.write( ('Channel2.Device1.T_12_Load_AVG',Load1_avg) )
    opc.write( ('Channel2.Device1.T_21_Load_AVG',Load2_avg) )
    opc.write( ('Channel2.Device1.T_32_Load_AVG',Load3_avg) )
    opc.write( ('Channel2.Device1.T_41_Load_AVG',Load4_avg) )
    opc.write( ('Channel2.Device1.T_12_Load_MAX',Load1_max) )
    opc.write( ('Channel2.Device1.T_21_Load_MAX',Load2_max) )
    opc.write( ('Channel2.Device1.T_32_Load_MAX',Load3_max) )
    opc.write( ('Channel2.Device1.T_41_Load_MAX',Load4_max) )
    opc.write( ('Channel2.Device1.T_12_Load_MIN',Load1_min) )
    opc.write( ('Channel2.Device1.T_21_Load_MIN',Load2_min) )
    opc.write( ('Channel2.Device1.T_32_Load_MIN',Load3_min) )
    opc.write( ('Channel2.Device1.T_41_Load_MIN',Load4_min) )
    opc.write( ('Channel2.Device1.T_12_Load_INST',Load_T12) )
    opc.write( ('Channel2.Device1.T_21_Load_INST',Load_T21) )
    opc.write( ('Channel2.Device1.T_32_Load_INST',Load_T32) )
    opc.write( ('Channel2.Device1.T_41_Load_INST',Load_T41) )

    opc.close()
except:
    print 'OPC communication failed'
    pass

The newer OPC UA (Unified Architecture) is platform independent and does not rely on the DCOM communication. It is more secure and includes functionality that is in OPC DA (Data Access) and OPC HDA (Historical Data Access).

SQL Client/Server

SQL (Structured Query Language) is a programming language popular with enterprise and web applications that requirement storage and access to historical or real-time data. It is not commonly used for process control or automation like MODBUS or OPC but the large user base of SQL programmers and requirements for big-data suggests that SQL may become a more popular platform in the future.

See the Data-Driven Engineering course for additional information on SQL in Python.

Data From the Apps

Every app in apmonitor.com/apps exports its run as CSV with Export CSV. A student can make a labeled, repeatable data set in a minute: choose a case, run it, inject a fault or a disturbance at a known time, and export. The same case run again gives the same data, which is what a fair comparison of models or estimators needs. The Process Monitoring Workbench and the loss-in-weight feeder are good first sources.

Sampling, Filtering, Late and Missing Samples

Sampling. A signal sampled every `\Delta t` (frequency `f_s = 1/\Delta t`) represents frequencies only up to `f_s/2`. A component at frequency `f` above that limit appears at the alias frequency

$$f_{\text{alias}} = \left| f - m f_s \right|, \qquad m = \text{the integer nearest to } f/f_s$$

so fast noise or a 60 Hz pickup can show up as a slow wave that no later processing can separate from the process. Sample several times faster than the fastest dynamics you need, and remove higher frequencies with an analog or anti-aliasing filter before sampling.

Filtering. A first-order filter with time constant `\tau_f` smooths a measurement `y_k`:

$$y_{f,k} = \alpha\, y_{f,k-1} + (1 - \alpha)\, y_k, \qquad \alpha = e^{-\Delta t/\tau_f}$$

It also delays the signal by about `\tau_f`. An estimator or controller that is given filtered data without a model of the filter sees a slower process than the real one.

Late and missing samples. A laboratory assay or analyzer reports a value measured at time `t_m` that arrives later. The estimator must compare it with the model output at `t_m`, not at the arrival time:

$$e = y_{t_m} - g\big(x(t_m)\big)$$

Moving horizon estimation does this naturally, because the past states are still decision variables in its window. A missing sample is dropped from the objective (its weight set to zero), not replaced by the last good value, which would tell the estimator that the process stopped changing.

Data Acquisition and Communication

There are several hardware platforms that allow data acquisition and software platforms that facilitate communication.

Robot Operating System (ROS)

ROS is a C++ or Python library that allows inter-process communication. It can be run on anything from a desktop computer to an Arduino (at least in part). Its strength comes from the many different types of ROS packages that already exist and allow for sensors and actuators to communicate.

Micro-processors

Several micro-processors, such as the Raspberry PI and the Beagle Bone Black, have been developed to allow on-board data acquisition and processing. These credit-card sized platforms run a full version of Linux with ARM processors several digital and analog inputs and outputs.

Micro-controllers

Instrumentation and Control Course at Notre Dame

The Arduino is a popular micro-controller that allows data acquisition, limited on-board processing, and output capabilities. With a large developer community and supported sensors, this platform is a popular choice for data acquisition and automation applications. The Temperature Control Lab (TCLab) connects to a computer with a serial USB connection with MATLAB or Python. The serial USB connection sends commands (heater level, LED level) and receives data (temperature) to enable real-time control.

Generative AI Learning

"My temperature is logged every 10 s but the heater duty cycles at a period of 9.5 s, and I see a slow wave with a period of a few minutes in the data. Explain what is happening and compute the period of the slow wave."

Check the answer: Compute it yourself: f = 1/9.5 Hz, f_s = 0.1 Hz, m = 1, so the alias is |1/9.5 - 0.1| Hz, a period of 190 s. A good answer names aliasing and gets that number. Confirm by sampling a 9.5 s sine every 10 s in Python and measuring the period of the result.

Course Information

TCLab

Project

Applications

Advanced Control Exercises

Exams

Modeling

Machine Learning

Estimation

Control

Reinforcement Learning

Related Courses

Admin