Merge pull request 'dev-Rene' (#1) from dev-Rene into main
Reviewed-on: #1
This commit is contained in:
@@ -68,6 +68,7 @@
|
|||||||
},
|
},
|
||||||
oneditsave: function() {
|
oneditsave: function() {
|
||||||
const node = this;
|
const node = this;
|
||||||
|
|
||||||
// save asset fields
|
// save asset fields
|
||||||
if (window.EVOLV?.nodes?.rotatingMachine?.assetMenu?.saveEditor) {
|
if (window.EVOLV?.nodes?.rotatingMachine?.assetMenu?.saveEditor) {
|
||||||
window.EVOLV.nodes.rotatingMachine.assetMenu.saveEditor(this);
|
window.EVOLV.nodes.rotatingMachine.assetMenu.saveEditor(this);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class nodeClass {
|
|||||||
unit: uiConfig.unit
|
unit: uiConfig.unit
|
||||||
},
|
},
|
||||||
functionality: {
|
functionality: {
|
||||||
positionVsParent: uiConfig.positionVsParent || 'atEquipment', // Default to 'atEquipment' if not specified
|
positionVsParent: uiConfig.positionVsParent
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
* OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*
|
*
|
||||||
* Ownership of this code remains solely with the original author. Unauthorized
|
* Ownership of this code remainregisterChilds solely with the original author. Unauthorized
|
||||||
* use of this Software is strictly prohibited.
|
* use of this Software is strictly prohibited.
|
||||||
*
|
*
|
||||||
* @summary A class to interact and manipulate machines with a non-euclidian curve
|
* @summary A class to interact and manipulate machines with a non-euclidian curve
|
||||||
@@ -120,18 +120,23 @@ class Machine {
|
|||||||
|
|
||||||
/*------------------- Register child events -------------------*/
|
/*------------------- Register child events -------------------*/
|
||||||
registerChild(child, softwareType) {
|
registerChild(child, softwareType) {
|
||||||
this.logger.debug('Setting up child event listeners');
|
this.logger.debug('Setting up child event for softwaretype ' + softwareType);
|
||||||
|
|
||||||
if(softwareType === "measurement"){
|
if(softwareType === "measurement"){
|
||||||
const position = child.config.functionality.positionVsParent;
|
const position = child.config.functionality.positionVsParent;
|
||||||
|
const distance = child.config.functionality.distanceVsParent || 0;
|
||||||
const measurementType = child.config.asset.type;
|
const measurementType = child.config.asset.type;
|
||||||
const key = `${measurementType}_${position}`;
|
const key = `${measurementType}_${position}`;
|
||||||
|
//rebuild to measurementype.variant no position and then switch based on values not strings or names.
|
||||||
const eventName = `${measurementType}.measured.${position}`;
|
const eventName = `${measurementType}.measured.${position}`;
|
||||||
|
|
||||||
|
this.logger.debug(`Setting up listener for ${eventName} from child ${child.config.general.name}`);
|
||||||
// Register event listener for measurement updates
|
// Register event listener for measurement updates
|
||||||
child.measurements.emitter.on(eventName, (eventData) => {
|
child.measurements.emitter.on(eventName, (eventData) => {
|
||||||
this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
|
this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
|
||||||
|
|
||||||
|
|
||||||
|
console.log(` Emitting... ${eventName} with data:`);
|
||||||
// Store directly in parent's measurement container
|
// Store directly in parent's measurement container
|
||||||
this.measurements
|
this.measurements
|
||||||
.type(measurementType)
|
.type(measurementType)
|
||||||
@@ -214,37 +219,37 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleInput(source, action, parameter) {
|
async handleInput(source, action, parameter) {
|
||||||
|
|
||||||
if (!this.isValidSourceForMode(source, this.currentMode)) {
|
if (!this.isValidSourceForMode(source, this.currentMode)) {
|
||||||
let warningTxt = `Source '${source}' is not valid for mode '${this.currentMode}'.`;
|
let warningTxt = `Source '${source}' is not valid for mode '${this.currentMode}'.`;
|
||||||
this.logger.warn(warningTxt);
|
this.logger.warn(warningTxt);
|
||||||
return {status : false , feedback: warningTxt};
|
return {status : false , feedback: warningTxt};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.logger.info(`Handling input from source '${source}' with action '${action}' in mode '${this.currentMode}'.`);
|
this.logger.info(`Handling input from source '${source}' with action '${action}' in mode '${this.currentMode}'.`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "execSequence":
|
case "execSequence":
|
||||||
await this.executeSequence(parameter);
|
return await this.executeSequence(parameter);
|
||||||
//recalc flow and power
|
|
||||||
this.updatePosition();
|
|
||||||
break;
|
|
||||||
case "execMovement":
|
case "execMovement":
|
||||||
await this.setpoint(parameter);
|
return await this.setpoint(parameter);
|
||||||
break;
|
|
||||||
case "flowMovement":
|
case "flowMovement":
|
||||||
// Calculate the control value for a desired flow
|
// Calculate the control value for a desired flow
|
||||||
const pos = this.calcCtrl(parameter);
|
const pos = this.calcCtrl(parameter);
|
||||||
// Move to the desired setpoint
|
// Move to the desired setpoint
|
||||||
await this.setpoint(pos);
|
return await this.setpoint(pos);
|
||||||
break;
|
|
||||||
case "emergencyStop":
|
case "emergencyStop":
|
||||||
this.logger.warn(`Emergency stop activated by '${source}'.`);
|
this.logger.warn(`Emergency stop activated by '${source}'.`);
|
||||||
await this.executeSequence("emergencyStop");
|
return await this.executeSequence("emergencyStop");
|
||||||
break;
|
|
||||||
case "statusCheck":
|
case "statusCheck":
|
||||||
this.logger.info(`Status Check: Mode = '${this.currentMode}', Source = '${source}'.`);
|
this.logger.info(`Status Check: Mode = '${this.currentMode}', Source = '${source}'.`);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this.logger.warn(`Action '${action}' is not implemented.`);
|
this.logger.warn(`Action '${action}' is not implemented.`);
|
||||||
break;
|
break;
|
||||||
@@ -254,6 +259,13 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error handling input: ${error}`);
|
this.logger.error(`Error handling input: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
abortMovement(reason = "group override") {
|
||||||
|
if (this.state?.abortCurrentMovement) {
|
||||||
|
this.state.abortCurrentMovement(reason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setMode(newMode) {
|
setMode(newMode) {
|
||||||
@@ -294,6 +306,9 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
break; // Exit sequence execution on error
|
break; // Exit sequence execution on error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//recalc flow and power
|
||||||
|
this.updatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
async setpoint(setpoint) {
|
async setpoint(setpoint) {
|
||||||
@@ -341,20 +356,20 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
calcPower(x) {
|
calcPower(x) {
|
||||||
if(this.hasCurve) {
|
if(this.hasCurve) {
|
||||||
if (!this._isOperationalState()) {
|
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.`);
|
this.logger.debug(`Machine is not operational. Setting predicted power to 0.`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//this.predictPower.currentX = x; Decrepated
|
//this.predictPower.currentX = x; Decrepated
|
||||||
const cPower = this.predictPower.y(x);
|
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}`);
|
//this.logger.debug(`Calculated power: ${cPower} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
|
||||||
return cPower;
|
return cPower;
|
||||||
}
|
}
|
||||||
// If no curve data is available, log a warning and return 0
|
// 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.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;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -372,7 +387,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
|
|
||||||
// If no curve data is available, log a warning and return 0
|
// 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.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;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -382,14 +397,14 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
if(this.hasCurve) {
|
if(this.hasCurve) {
|
||||||
this.predictCtrl.currentX = x;
|
this.predictCtrl.currentX = x;
|
||||||
const cCtrl = this.predictCtrl.y(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}`);
|
//this.logger.debug(`Calculated ctrl: ${cCtrl} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
|
||||||
return cCtrl;
|
return cCtrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no curve data is available, log a warning and return 0
|
// 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.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;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -398,9 +413,9 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
// this will be either the differential pressure, downstream or upstream pressure
|
// this will be either the differential pressure, downstream or upstream pressure
|
||||||
getMeasuredPressure() {
|
getMeasuredPressure() {
|
||||||
const pressureDiff = this.measurements.type('pressure').variant('measured').difference();
|
const pressureDiff = this.measurements.type('pressure').variant('measured').difference();
|
||||||
|
|
||||||
// Both upstream & downstream => differential
|
// Both upstream & downstream => differential
|
||||||
if (pressureDiff != null) {
|
if (pressureDiff) {
|
||||||
this.logger.debug(`Pressure differential: ${pressureDiff.value}`);
|
this.logger.debug(`Pressure differential: ${pressureDiff.value}`);
|
||||||
this.predictFlow.fDimension = pressureDiff.value;
|
this.predictFlow.fDimension = pressureDiff.value;
|
||||||
this.predictPower.fDimension = pressureDiff.value;
|
this.predictPower.fDimension = pressureDiff.value;
|
||||||
@@ -420,7 +435,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
|
|
||||||
// Only downstream => use it, warn that it's partial
|
// Only downstream => use it, warn that it's partial
|
||||||
if (downstreamPressure != null) {
|
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.predictFlow.fDimension = downstreamPressure;
|
||||||
this.predictPower.fDimension = downstreamPressure;
|
this.predictPower.fDimension = downstreamPressure;
|
||||||
this.predictCtrl.fDimension = downstreamPressure;
|
this.predictCtrl.fDimension = downstreamPressure;
|
||||||
@@ -504,11 +519,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
|
|
||||||
// rich context handler for pressure updates
|
// rich context handler for pressure updates
|
||||||
updateMeasuredPressure(value, position, context = {}) {
|
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
|
// Enhanced logging with child context
|
||||||
this.logger.debug(`Pressure update: ${value} at ${position} from ${context.childName || 'child'} (${context.childId || 'unknown-id'})`);
|
this.logger.debug(`Pressure update: ${value} at ${position} from ${context.childName || 'child'} (${context.childId || 'unknown-id'})`);
|
||||||
|
|
||||||
@@ -548,6 +559,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
|
|
||||||
//what is the internal functions that need updating when something changes that has influence on this.
|
//what is the internal functions that need updating when something changes that has influence on this.
|
||||||
updatePosition() {
|
updatePosition() {
|
||||||
|
|
||||||
if (this._isOperationalState()) {
|
if (this._isOperationalState()) {
|
||||||
|
|
||||||
const currentPosition = this.state.getCurrentPosition();
|
const currentPosition = this.state.getCurrentPosition();
|
||||||
@@ -659,12 +671,12 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
|
|
||||||
if (power != 0 && flow != 0) {
|
if (power != 0 && flow != 0) {
|
||||||
// Calculate efficiency after measurements update
|
// 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 {
|
} 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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user