Simulation and digital twin
The engine that runs a project on a controller also runs it as a simulation: the same packages, the same fixed step, the same image, as fast as the models compute. A digital twin is the same project again, run in real time beside the plant and fed with its measurements.
Offline simulation
A plant model and the application under test in one project, wired in the image:
[engine]
tick_ms = 100.0
[models.plant]
kind = "fmi"
path = "packages/plant.fmu"
[models.ctrl]
kind = "raw"
path = "packages/ctrl"
[[instance]] # the controller reads the plant's output of the previous tick
id = "ctrl"
model = "ctrl"
inputs = { pv = "plant.y" }
[[instance]]
id = "plant"
model = "plant"
inputs = { u = "ctrl.u" }
[[recorder]]
id = "main"
signals = ["@io"]
taktwerk run sim.toml --speed max --no-connectors --until-time 86400 --seed 1
--speed maxruns unpaced on engine time; input ages and every event count model time, so the rows are the same at any speed (Pace).--set,--modeland a scenario file change a run without editing the project: other parameters, another package version, a disturbance, a sensor fault. Each is recorded inrun.json.- The record is the same format a plant run writes; the Python package and the workbench read both.
examples/closed-loop is an FMU and a C controller wired this
way; examples/campaign adds a seeded noisy sensor and a
disturbance scenario.
Digital twin
A twin runs a plant model in real time with the plant’s own inputs, so its outputs can be put next to the measurements, or stand in for what the plant does not measure:
flowchart LR
PLC[PLC] -- "manipulated values, measurements<br/>opcua-client" --> E
subgraph E[taktwerk]
TW[plant model] --> PI[(image)]
end
E -- "OPC UA server" --> HMI[HMI, historian]
E -- "recorder" --> R[records]
- An
opcua-clientreads the manipulated values (and the measurements to compare with) into external inputs, with amax_age_ms, so the twin stops stepping when the data stops. - The model’s outputs are on the engine’s OPC UA server for any client; mapped in the
opcua-clientthey go back to the PLC. A twin that only reads needs nowrites. - A recorder with
@iokeeps every input as received and every output each tick, for a comparison afterwards: the same record can be replayed offline with the measured inputs set by a scenario, or compared run against run in the workbench.
An estimator that corrects the model from the measurements is an application package of its own; see A controller or estimator beside a PLC.