wrps-demo-kit/03-plc/src/91_config_sim.st
Clio Liu dca7797d68 feat(plc): ST sources, generators and the Modbus contract
The PLC program from the old repo's 04-plc/, flattened into one folder and
checked against the running system.

Verified during the move:
  - build.py regenerates register-map.csv byte-identically (69 points)
  - polled the live PLC: the SIMULATION build is what is deployed and
    running, %MW21=2 wet weather, values moving, run hours accumulating
  - addresses, %MW HR1024 segmentation and %QW17/%QW7 signedness all
    match the map

Corrections against the old repo:
  - 10_globals.st header cited WRPS-CTL-002 (the FDS); it means CTL-003
  - build.py wrote the map to its parent directory; now beside itself
  - deploy/README.md was a single-file folder; now DEPLOY.md
  - dropped the empty editor-devices/remote/
  - README no longer claims the simulation build is uncompiled - it is
    the one running

Two open items are now stated plainly rather than buried:
  - none of the 20 acceptance tests in CTL-003 have ever been run
  - the OpenPLC Editor lived only on the retired dev-ubuntu host, so
    there is currently NO route to deploy a new program (DEPLOY.md 0)

Documents the setpoint distinction: IO_MUX seeds %MW defaults once at
first scan, operators retune them live, and that tuning exists only in
the container volume - a restart reverts it.
2026-09-02 15:48:49 +10:00

45 lines
1.9 KiB
Smalltalk

(* =====================================================================
91_config_sim.st - CONFIGURATION, simulation build
Replaces 90_config_field.st in `--mode sim`. Identical to it except
for the third program instance.
Scan task: 100 ms cyclic, section 4. The interval must stay at
100 ms: FB_PUMP, FB_LEVEL_CTRL and FB_HEADROOM all integrate against
a hardcoded SCAN_S := 0.1, as does PROGRAM SIMULATION.
Declaration order sets execution order within the task:
SIMULATION first - models the plant, using the run commands and
speed CONTROL published on the previous scan
IO_MUX second - simulated image in, previous scan's outputs out
CONTROL third - reads only the process image
Section 8.2 says SIMULATION runs AFTER CONTROL. It runs first here,
deliberately. With it last, the first scan after every start has no
simulated image yet, so IO_MUX falls back to the (all zero) field
inputs - and an all-zero field means ThermalOK FALSE and LSLL dry,
which makes FB_PUMP latch a trip on all three units and the station
enter dry-run lockout. Those latch until a reset command, so every
demo would have to begin by clearing trips that never happened.
The cost of running it first is that SIMULATION reacts to run
commands one scan late - 100 ms at 1x. That is the same lag IO_MUX
already has on published outputs, and it is invisible next to a
3 s pump start delay.
Simulation time scaling (%MW23) applies only inside SIMULATION.
CONTROL's timers stay in real seconds; see README.md.
===================================================================== *)
CONFIGURATION Config0
RESOURCE Res0 ON PLC
TASK plc_task(INTERVAL := T#100ms, PRIORITY := 0);
PROGRAM inst_sim WITH plc_task : SIMULATION;
PROGRAM inst_mux WITH plc_task : IO_MUX;
PROGRAM inst_ctl WITH plc_task : CONTROL;
END_RESOURCE
END_CONFIGURATION