fix: continuous proportional control — eliminate dead zone between start/stop levels

Previously PS only sent demand to MGC when level > startLevel AND
direction === 'filling'. Between startLevel and stopLevel (the 'dead
zone'), pumps kept running at their last commanded setpoint with no
updates. Basin drained uncontrolled until hitting stopLevel.

Fix: send percControl on every tick when level > stopLevel. The
_scaleLevelToFlowPercent math naturally gives:
  - Positive % above startLevel (pumps ramp up)
  - 0% at exactly startLevel (pumps at minimum)
  - Negative % below startLevel → clamped to 0 → MGC scales to 0
    → pumps ramp down gracefully

This creates smooth visible ramp-up and ramp-down as the basin fills
and drains, instead of a sudden jump at startLevel and stuck ctrl in
the dead zone.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
znetsixe
2026-04-14 13:42:43 +02:00
parent c62d8bc275
commit e8dd657b4f

View File

@@ -264,15 +264,26 @@ class PumpingStation {
return; return;
} }
if (level > startLevel && direction === 'filling') { // Continuous proportional control: command pumps whenever level is
const percControl = this._scaleLevelToFlowPercent(level); // above stopLevel. The percControl ramp gives:
this.logger.debug(`Controllevel based => Level ${level} control applying to pump : ${percControl}`); // - 0% at minFlowLevel (= startLevel) → pumps barely running
// - linearly up to 100% at maxFlowLevel → all pumps full
// - Below startLevel but above stopLevel: percControl < 0 → clamp
// to 0 → MGC turns off pumps (graceful ramp-down instead of a
// dead zone where pumps keep running at their last setpoint).
if (level > stopLevel) {
const rawPercControl = this._scaleLevelToFlowPercent(level);
const percControl = Math.max(0, rawPercControl);
this.logger.debug(`Controllevel based => Level ${level} percControl ${percControl}`);
if (percControl > 0) {
await this._applyMachineLevelControl(percControl); await this._applyMachineLevelControl(percControl);
// Also forward to machine groups (e.g. MGC) — the level-based
// control originally only addressed direct-child machines, but in
// a hierarchical topology (PS → MGC → pumps) the machines sit
// under MGC and PS.machines is empty.
await this._applyMachineGroupLevelControl(percControl); await this._applyMachineGroupLevelControl(percControl);
} else {
// Between stopLevel and startLevel with percControl ≤ 0:
// tell MGC to scale back to 0 rather than leaving pumps
// running at the last commanded setpoint.
await this._applyMachineGroupLevelControl(0);
}
} }
if (level < stopLevel && direction === 'draining') { if (level < stopLevel && direction === 'draining') {