forked from RnD/generalFunctions
Added min height based on | fixed dynamic speed in %/sec
This commit is contained in:
@@ -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": {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
}
|
||||
},
|
||||
"maxSpeed": {
|
||||
"default": 10,
|
||||
"default": 1000,
|
||||
"rules": {
|
||||
"type": "number",
|
||||
"description": "Maximum speed setting."
|
||||
|
||||
Reference in New Issue
Block a user