Several fixes, especially measurement and pressure updates and triggers where flawed

This commit is contained in:
znetsixe
2025-10-02 17:09:24 +02:00
parent 000bee7190
commit 5357290b41
3 changed files with 37 additions and 29 deletions

View File

@@ -68,6 +68,7 @@
},
oneditsave: function() {
const node = this;
// save asset fields
if (window.EVOLV?.nodes?.rotatingMachine?.assetMenu?.saveEditor) {
window.EVOLV.nodes.rotatingMachine.assetMenu.saveEditor(this);

View File

@@ -62,7 +62,7 @@ class nodeClass {
unit: uiConfig.unit
},
functionality: {
positionVsParent: uiConfig.positionVsParent || 'atEquipment', // Default to 'atEquipment' if not specified
positionVsParent: uiConfig.positionVsParent
}
};

View File

@@ -214,37 +214,37 @@ _callMeasurementHandler(measurementType, value, position, context) {
}
async handleInput(source, action, parameter) {
if (!this.isValidSourceForMode(source, this.currentMode)) {
let warningTxt = `Source '${source}' is not valid for mode '${this.currentMode}'.`;
this.logger.warn(warningTxt);
return {status : false , feedback: warningTxt};
}
this.logger.info(`Handling input from source '${source}' with action '${action}' in mode '${this.currentMode}'.`);
try {
switch (action) {
case "execSequence":
await this.executeSequence(parameter);
//recalc flow and power
this.updatePosition();
break;
return await this.executeSequence(parameter);
case "execMovement":
await this.setpoint(parameter);
break;
return await this.setpoint(parameter);
case "flowMovement":
// Calculate the control value for a desired flow
const pos = this.calcCtrl(parameter);
// Move to the desired setpoint
await this.setpoint(pos);
break;
return await this.setpoint(pos);
case "emergencyStop":
this.logger.warn(`Emergency stop activated by '${source}'.`);
await this.executeSequence("emergencyStop");
break;
return await this.executeSequence("emergencyStop");
case "statusCheck":
this.logger.info(`Status Check: Mode = '${this.currentMode}', Source = '${source}'.`);
break;
default:
this.logger.warn(`Action '${action}' is not implemented.`);
break;
@@ -254,6 +254,13 @@ _callMeasurementHandler(measurementType, value, position, context) {
} catch (error) {
this.logger.error(`Error handling input: ${error}`);
}
}
abortMovement(reason = "group override") {
if (this.state?.abortCurrentMovement) {
this.state.abortCurrentMovement(reason);
}
}
setMode(newMode) {
@@ -294,6 +301,9 @@ _callMeasurementHandler(measurementType, value, position, context) {
break; // Exit sequence execution on error
}
}
//recalc flow and power
this.updatePosition();
}
async setpoint(setpoint) {
@@ -341,20 +351,20 @@ _callMeasurementHandler(measurementType, value, position, context) {
calcPower(x) {
if(this.hasCurve) {
if (!this._isOperationalState()) {
this.measurements.type("power").variant("predicted").position('upstream').value(0);
this.measurements.type("power").variant("predicted").position('atEquipment').value(0);
this.logger.debug(`Machine is not operational. Setting predicted power to 0.`);
return 0;
}
//this.predictPower.currentX = x; Decrepated
const cPower = this.predictPower.y(x);
this.measurements.type("power").variant("predicted").position('upstream').value(cPower);
this.measurements.type("power").variant("predicted").position('atEquipment').value(cPower);
//this.logger.debug(`Calculated power: ${cPower} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
return cPower;
}
// If no curve data is available, log a warning and return 0
this.logger.warn(`No curve data available for power calculation. Returning 0.`);
this.measurements.type("power").variant("predicted").position('upstream').value(0);
this.measurements.type("power").variant("predicted").position('atEquipment').value(0);
return 0;
}
@@ -372,7 +382,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
// If no curve data is available, log a warning and return 0
this.logger.warn(`No curve data available for power calculation. Returning 0.`);
this.measurements.type("power").variant("predicted").position('upstream').value(0);
this.measurements.type("power").variant("predicted").position('atEquipment').value(0);
return 0;
}
@@ -382,14 +392,14 @@ _callMeasurementHandler(measurementType, value, position, context) {
if(this.hasCurve) {
this.predictCtrl.currentX = x;
const cCtrl = this.predictCtrl.y(x);
this.measurements.type("ctrl").variant("predicted").position('upstream').value(cCtrl);
this.measurements.type("ctrl").variant("predicted").position('atEquipment').value(cCtrl);
//this.logger.debug(`Calculated ctrl: ${cCtrl} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
return cCtrl;
}
// If no curve data is available, log a warning and return 0
this.logger.warn(`No curve data available for control calculation. Returning 0.`);
this.measurements.type("ctrl").variant("predicted").position('upstream').value(0);
this.measurements.type("ctrl").variant("predicted").position('atEquipment').value(0);
return 0;
}
@@ -398,9 +408,9 @@ _callMeasurementHandler(measurementType, value, position, context) {
// this will be either the differential pressure, downstream or upstream pressure
getMeasuredPressure() {
const pressureDiff = this.measurements.type('pressure').variant('measured').difference();
// Both upstream & downstream => differential
if (pressureDiff != null) {
if (pressureDiff) {
this.logger.debug(`Pressure differential: ${pressureDiff.value}`);
this.predictFlow.fDimension = pressureDiff.value;
this.predictPower.fDimension = pressureDiff.value;
@@ -420,7 +430,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
// Only downstream => use it, warn that it's partial
if (downstreamPressure != null) {
this.logger.warn(`Using downstream pressure only for prediction: ${downstreamPressure} `);
this.logger.warn(`Using downstream pressure only for prediction: ${downstreamPressure} This is less acurate!!`);
this.predictFlow.fDimension = downstreamPressure;
this.predictPower.fDimension = downstreamPressure;
this.predictCtrl.fDimension = downstreamPressure;
@@ -504,11 +514,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
// rich context handler for pressure updates
updateMeasuredPressure(value, position, context = {}) {
if (!this._isOperationalState()) {
this.logger.warn(`Machine not operational, skipping pressure update from ${context.childName || 'unknown'}`);
return;
}
// Enhanced logging with child context
this.logger.debug(`Pressure update: ${value} at ${position} from ${context.childName || 'child'} (${context.childId || 'unknown-id'})`);
@@ -548,6 +554,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
//what is the internal functions that need updating when something changes that has influence on this.
updatePosition() {
if (this._isOperationalState()) {
const currentPosition = this.state.getCurrentPosition();
@@ -659,12 +666,12 @@ _callMeasurementHandler(measurementType, value, position, context) {
if (power != 0 && flow != 0) {
// Calculate efficiency after measurements update
this.measurements.type("efficiency").variant(variant).position('downstream').value((flow / power));
this.measurements.type("efficiency").variant(variant).position('atEquipment').value((flow / power));
} else {
this.measurements.type("efficiency").variant(variant).position('downstream').value(null);
this.measurements.type("efficiency").variant(variant).position('atEquipment').value(null);
}
return this.measurements.type("efficiency").variant(variant).position('downstream').getCurrentValue();
return this.measurements.type("efficiency").variant(variant).position('atEquipment').getCurrentValue();
}