Added min height based on | fixed dynamic speed in %/sec

This commit is contained in:
znetsixe
2025-11-20 11:09:26 +01:00
parent f2c9134b64
commit d52a1827e3
3 changed files with 44 additions and 13 deletions

View File

@@ -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" "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": { "staticHead": {
"default": 12, "default": 12,
"rules": { "rules": {

View File

@@ -81,11 +81,8 @@ class movementManager {
const direction = targetPosition > this.currentPosition ? 1 : -1; const direction = targetPosition > this.currentPosition ? 1 : -1;
const distance = Math.abs(targetPosition - this.currentPosition); const distance = Math.abs(targetPosition - this.currentPosition);
// Speed is a fraction [0,1] of full-range per second const velocity = this.getVelocity(); // units per second
this.speed = Math.min(Math.max(this.speed, 0), 1); if (velocity <= 0) {
const fullRange = this.maxPosition - this.minPosition;
const velocity = this.speed * fullRange; // units per second
if (velocity === 0) {
return reject(new Error("Movement aborted: zero speed")); return reject(new Error("Movement aborted: zero speed"));
} }
@@ -154,11 +151,11 @@ class movementManager {
const direction = targetPosition > this.currentPosition ? 1 : -1; const direction = targetPosition > this.currentPosition ? 1 : -1;
const distance = Math.abs(targetPosition - this.currentPosition); const distance = Math.abs(targetPosition - this.currentPosition);
// Ensure speed is a percentage [0, 1] const velocity = this.getVelocity();
this.speed = Math.min(Math.max(this.speed, 0), 1); if (velocity <= 0) {
return reject(new Error("Movement aborted: zero speed"));
// Calculate duration based on percentage of distance per second }
const duration = 1 / this.speed; // 1 second for 100% of the distance const duration = distance / velocity;
this.timeleft = duration; //set this so other classes can use it this.timeleft = duration; //set this so other classes can use it
this.logger.debug( this.logger.debug(
@@ -217,13 +214,16 @@ class movementManager {
const direction = targetPosition > this.currentPosition ? 1 : -1; const direction = targetPosition > this.currentPosition ? 1 : -1;
const totalDistance = Math.abs(targetPosition - this.currentPosition); const totalDistance = Math.abs(targetPosition - this.currentPosition);
const startPosition = 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) => const easeFunction = (t) =>
t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2; t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
let elapsedTime = 0; let elapsedTime = 0;
const duration = totalDistance / this.speed; const duration = totalDistance / velocity;
this.timeleft = duration; this.timeleft = duration;
const interval = this.interval; const interval = this.interval;
@@ -273,6 +273,20 @@ class movementManager {
constrain(value) { constrain(value) {
return Math.min(Math.max(value, this.minPosition), this.maxPosition); 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; module.exports = movementManager;

View File

@@ -127,7 +127,7 @@
} }
}, },
"maxSpeed": { "maxSpeed": {
"default": 10, "default": 1000,
"rules": { "rules": {
"type": "number", "type": "number",
"description": "Maximum speed setting." "description": "Maximum speed setting."