Skip to content

About

Batch reactor control in CODESYS (IEC 61131-3 ST): fill/heat/hold/drain sequence, PI control, interlocks, latched alarms, HMI, and GMP-style URS/FS/OQ with 17 automated OQ tests

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Batch Reactor Control: IEC 61131-3 (CODESYS) batch sequence with validation documents

A fill, heat, hold and drain batch sequence for a single jacketed vessel, written in IEC 61131-3 Structured Text and run on the CODESYS runtime. GMP-style documents come with it: user requirements, a functional specification, and an operational qualification (OQ) protocol that traces each requirement to a test. A Siemens SCL version of the same function block is included as a secondary, untested deliverable.

Status: the CODESYS project builds with 0 errors and 0 warnings, and 17/17 OQ scenarios pass on the CODESYS Control Win V3 x64 runtime in simulation mode (CODESYS_OQ_results.md). The same 17 pass on the Python reference model (OQ_results.md) and on the SCL source run by a small interpreter written for this repo (SCL_cross_check.md). Every key value agrees across the three (for example, OQ-01 peak temperature 59.92 degC, batch time 220.3 s). The SCL has not been compiled in TIA Portal or run in PLCSIM. The plant is a simulated vessel, and no real I/O was used.

CODESYS HMI during HOLD

CODESYS visualisation, running live against the simulated plant (PLC_PRG, 100 ms task). This frame is in HOLD: the PI holds 59.6 degC at about 16 % heater.

CODESYS HMI after a heater-stuck-on fault

Here the "heater stuck on" fault was switched on from the HMI during the batch. A03 over-temperature latched as first-out and the horn and FAULT state came on. ACK is refused while the temperature is still above the limit.

Demo batch

One nominal batch, generated from the SCL blocks run in the software interpreter (not a PLC recording).

What it does

  • Seven-state sequence: IDLE, FILL, HEAT, HOLD, DRAIN, FAULT, ESTOP
  • PI temperature control (60 degC) with conditional anti-windup
  • Equipment interlocks applied last, so no state can bypass them (heater needs level >= 20 % and agitator running)
  • Seven latched alarms with first-out, fail-safe outputs, horn, and a reset that is refused while the cause is present
  • Hard-wired E-stop contact handled above everything else; restart needs release plus operator reset
  • Edge-detected Start and Acknowledge inputs

Repository layout

Path Contents
codesys/src/FB_BatchReactor.st The controller: IEC 61131-3 function block, logic identical to sim/controller.py
codesys/src/FC_PlantModel.st, ST_Plant.st Simulated vessel (same equations as sim/plant.py) with fault-injection fields
codesys/src/PLC_PRG.st, GVL_Sim.st Real-time simulation in a 100 ms task, plus the variables the HMI uses
codesys/src/PRG_OQ.st, GVL_OQ.st, FC_RigScan.st, ST_Rig.st The 17 OQ scenarios, executed on the runtime
codesys/visu/ HMI screen Visu_Reactor and the visualisation manager/library settings (CODESYS native exports)
codesys/build_and_test.py, codesys/run.ps1, codesys/report.py Headless build: creates BatchReactor.project, compiles, runs the OQ on the runtime, writes the results
plc/*.scl, plc/*.db, plc/*.udt Siemens SCL version of the same blocks (secondary; not compiled in TIA Portal)
sim/controller.py, sim/plant.py Python reference model of the controller and the vessel
sim/oq_scenarios.py, sim/run_oq.py 17 OQ scenarios and the results/plot generator
sim/scl_interp.py, sim/scl_cross_check.py Interpreter for the SCL subset used in plc/, and the run of all OQ scenarios on the SCL source
tests/ pytest: scenarios on the Python model, and on the SCL source
docs/URS.md, docs/FS.md Requirements and functional specification with traceability
docs/OQ_protocol.md Test protocol with results for the CODESYS runtime, the reference model and the SCL interpreter
docs/INTERVIEW_NOTES.md Short explanations of the design decisions

Run it

CODESYS (V3.5 SP22 Patch 4 with CODESYS Control Win V3 x64; scripting is built in):

powershell -File codesys\run.ps1   # builds codesys\BatchReactor.project, runs the 17 OQ scenarios, writes docs\CODESYS_OQ_results.md

To use the HMI, open codesys\BatchReactor.project and choose Online > Simulation, then Login and Start, then open Visu_Reactor. START, STOP and ACK are momentary. E-STOP and "heater stuck on" are toggles.

Python reference model and SCL cross-check:

pip install pytest matplotlib numpy
python sim/run_oq.py           # writes docs/OQ_results.md and docs/nominal_batch.png
python sim/scl_cross_check.py  # runs the scenarios on plc/*.scl, writes docs/SCL_cross_check.md
pytest -q tests                # 37 passed (17 Python model + 20 SCL source)

Notes on design choices

  • Test-first: the logic was exercised against failure cases (blocked inlet, stuck valve, stuck heater, leak, bad sensor) before being written for the PLC. Running the tests also exposed a tuning problem (6.8 degC overshoot with the first gains), fixed by retuning the PI before the numbers above were recorded.
  • Interlocks last: applying them after the sequence means a future edit to one state cannot accidentally switch the heater on dry.
  • E-stop during a fault: an early version returned to IDLE on the E-stop reset and kept a stale alarm word, so the next fault showed the wrong first-out. Reset from ESTOP now returns to FAULT while alarms are latched (OQ-17).
  • OQ on the PLC itself: PRG_OQ runs every scenario on the CODESYS runtime with its own controller and plant instances, scan by scan at 0.1 s. That runs faster than real time, so the 17 scenarios finish in seconds. The real-time program PLC_PRG drives the HMI. Both call the same FB_BatchReactor and FC_PlantModel.
  • Why three implementations: the Python model was written first to design and test the logic, then ported to the PLC. A translation slip in a port would otherwise go unnoticed, so the same scenarios run on all three. The SCL interpreter (REAL as 32-bit float) matches the Python model scan for scan, to within 0.0002 degC. It is not a Siemens compiler and does not check TIA Portal's type rules.
  • Testing the tests: planting bugs in the SCL showed OQ-14 missed a reset that ignores the cause (the controller re-faults one scan later). OQ-14 now checks every scan of the Ack pulse. Weakening the heater interlock threshold is caught by no test, because the sequence never asks for heat below 20 %: the interlock is a backstop that black-box tests cannot reach; it is checked by review.
  • HMI as generated XML: the CODESYS script API cannot place visualisation elements, so codesys/visu/make_visu.py generated the first version of the screen from element templates. The button actions were then set in the CODESYS editor, and the result was exported.
  • Simplified plant: the vessel is a first-order model for logic testing, not a validated process model.

License

MIT, see LICENSE.

About

Batch reactor control in CODESYS (IEC 61131-3 ST): fill/heat/hold/drain sequence, PI control, interlocks, latched alarms, HMI, and GMP-style URS/FS/OQ with 17 automated OQ tests

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages