From d52a1827e3160b8a09f1c310276c636d4db26ee1 Mon Sep 17 00:00:00 2001 From: znetsixe <73483679+znetsixe@users.noreply.github.com> Date: Thu, 20 Nov 2025 11:09:26 +0100 Subject: [PATCH] Added min height based on | fixed dynamic speed in %/sec --- src/configs/pumpingStation.json | 17 +++++++++++++++ src/state/movementManager.js | 38 ++++++++++++++++++++++----------- src/state/stateConfig.json | 2 +- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/configs/pumpingStation.json b/src/configs/pumpingStation.json index d8ea505..5adf4a0 100644 --- a/src/configs/pumpingStation.json +++ b/src/configs/pumpingStation.json @@ -299,6 +299,23 @@ "description": "Reference height to use to identify the height vs other basins with. This will say something more about the expected pressure loss in m head" } }, + "minHeightBasedOn": { + "default": "outlet", + "rules": { + "type": "enum", + "values": [ + { + "value": "inlet", + "description": "Minimum height is based on inlet elevation." + }, + { + "value": "outlet", + "description": "Minimum height is based on outlet elevation." + } + ], + "description": "Basis for minimum height check: inlet or outlet." + } + }, "staticHead": { "default": 12, "rules": { diff --git a/src/state/movementManager.js b/src/state/movementManager.js index 424c628..f949f48 100644 --- a/src/state/movementManager.js +++ b/src/state/movementManager.js @@ -81,11 +81,8 @@ class movementManager { const direction = targetPosition > this.currentPosition ? 1 : -1; const distance = Math.abs(targetPosition - this.currentPosition); - // Speed is a fraction [0,1] of full-range per second - this.speed = Math.min(Math.max(this.speed, 0), 1); - const fullRange = this.maxPosition - this.minPosition; - const velocity = this.speed * fullRange; // units per second - if (velocity === 0) { + const velocity = this.getVelocity(); // units per second + if (velocity <= 0) { return reject(new Error("Movement aborted: zero speed")); } @@ -154,11 +151,11 @@ class movementManager { const direction = targetPosition > this.currentPosition ? 1 : -1; const distance = Math.abs(targetPosition - this.currentPosition); - // Ensure speed is a percentage [0, 1] - this.speed = Math.min(Math.max(this.speed, 0), 1); - - // Calculate duration based on percentage of distance per second - const duration = 1 / this.speed; // 1 second for 100% of the distance + const velocity = this.getVelocity(); + if (velocity <= 0) { + return reject(new Error("Movement aborted: zero speed")); + } + const duration = distance / velocity; this.timeleft = duration; //set this so other classes can use it this.logger.debug( @@ -217,13 +214,16 @@ class movementManager { const direction = targetPosition > this.currentPosition ? 1 : -1; const totalDistance = Math.abs(targetPosition - this.currentPosition); const startPosition = this.currentPosition; - this.speed = Math.min(Math.max(this.speed, 0), 1); + const velocity = this.getVelocity(); + if (velocity <= 0) { + return reject(new Error("Movement aborted: zero speed")); + } const easeFunction = (t) => t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2; let elapsedTime = 0; - const duration = totalDistance / this.speed; + const duration = totalDistance / velocity; this.timeleft = duration; const interval = this.interval; @@ -273,6 +273,20 @@ class movementManager { constrain(value) { return Math.min(Math.max(value, this.minPosition), this.maxPosition); } + + getNormalizedSpeed() { + const rawSpeed = Number.isFinite(this.speed) ? this.speed : 0; + const clampedSpeed = Math.max(0, rawSpeed); + const hasMax = Number.isFinite(this.maxSpeed) && this.maxSpeed > 0; + const effectiveSpeed = hasMax ? Math.min(clampedSpeed, this.maxSpeed) : clampedSpeed; + return effectiveSpeed / 100; // convert %/s -> fraction of range per second + } + + getVelocity() { + const normalizedSpeed = this.getNormalizedSpeed(); + const fullRange = this.maxPosition - this.minPosition; + return normalizedSpeed * fullRange; + } } module.exports = movementManager; diff --git a/src/state/stateConfig.json b/src/state/stateConfig.json index 8a0b39b..548e797 100644 --- a/src/state/stateConfig.json +++ b/src/state/stateConfig.json @@ -127,7 +127,7 @@ } }, "maxSpeed": { - "default": 10, + "default": 1000, "rules": { "type": "number", "description": "Maximum speed setting."