Compare commits

..

7 Commits

Author SHA1 Message Date
Woutverheijen
59dec46846 test 2025-10-24 09:40:40 +02:00
Woutverheijen
133cadf225 remove test 2025-10-23 12:23:45 +02:00
Woutverheijen
60d7dcb1ac test 2025-10-23 12:20:46 +02:00
c081acae4e Remove non-implemented temperature handling function 2025-10-10 13:27:31 +02:00
08185243bc Merge pull request 'dev-Rene' (#1) from dev-Rene into main
Reviewed-on: RnD/rotatingMachine#1
2025-10-06 14:16:18 +00:00
Rene De ren
bc916c0165 log updates 2025-10-03 15:41:53 +02:00
znetsixe
5357290b41 Several fixes, especially measurement and pressure updates and triggers where flawed 2025-10-02 17:09:24 +02:00
3 changed files with 57 additions and 52 deletions

View File

@@ -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);

View File

@@ -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
} }
}; };
@@ -115,7 +115,7 @@ class nodeClass {
const mode = m.currentMode; const mode = m.currentMode;
const state = m.state.getCurrentState(); const state = m.state.getCurrentState();
const flow = Math.round(m.measurements.type("flow").variant("predicted").position('downstream').getCurrentValue()); const flow = Math.round(m.measurements.type("flow").variant("predicted").position('downstream').getCurrentValue());
const power = Math.round(m.measurements.type("power").variant("predicted").position('upstream').getCurrentValue()); const power = Math.round(m.measurements.type("power").variant("predicted").position('atEquipment').getCurrentValue());
let symbolState; let symbolState;
switch(state){ switch(state){
case "off": case "off":

View File

@@ -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)
@@ -156,10 +161,6 @@ _callMeasurementHandler(measurementType, value, position, context) {
this.updateMeasuredFlow(value, position, context); this.updateMeasuredFlow(value, position, context);
break; break;
case 'temperature':
this.updateMeasuredTemperature(value, position, context);
break;
default: default:
this.logger.warn(`No handler for measurement type: ${measurementType}`); this.logger.warn(`No handler for measurement type: ${measurementType}`);
// Generic handler - just update position // Generic handler - just update position
@@ -214,37 +215,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 +255,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 +302,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 +352,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 +383,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 +393,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 +409,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 +431,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 +515,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 +555,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 +667,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();
} }
@@ -763,9 +771,9 @@ _callMeasurementHandler(measurementType, value, position, context) {
module.exports = Machine; module.exports = Machine;
/*------------------- Testing -------------------*/ /*------------------- Testing -------------------*/
/*
curve = require('C:/Users/zn375/.node-red/public/fallbackData.json'); /*
//curve = require('C:/Users/zn375/.node-red/public/fallbackData.json');
//import a child //import a child
const Child = require('../../measurement/src/specificClass'); const Child = require('../../measurement/src/specificClass');
@@ -781,7 +789,6 @@ const PT1 = new Child(config={
}, },
functionality:{ functionality:{
softwareType:"measurement", softwareType:"measurement",
positionVsParent:"upstream",
}, },
asset:{ asset:{
supplier:"Vega", supplier:"Vega",
@@ -803,7 +810,6 @@ const PT2 = new Child(config={
}, },
functionality:{ functionality:{
softwareType:"measurement", softwareType:"measurement",
positionVsParent:"upstream",
}, },
asset:{ asset:{
supplier:"Vega", supplier:"Vega",
@@ -819,18 +825,17 @@ console.log(`Creating machine...`);
const machineConfig = { const machineConfig = {
general: { general: {
name: "Hydrostal", name: "Hidrostal",
logging: { logging: {
enabled: true, enabled: true,
logLevel: "debug", logLevel: "debug",
} }
}, },
asset: { asset: {
supplier: "Hydrostal", supplier: "Hidrostal",
type: "pump", type: "pump",
category: "centrifugal", category: "centrifugal",
model: "H05K-S03R+HGM1X-X280KO", // Ensure this field is present. model: "hidrostal-H05K-S03R", // Ensure this field is present.
machineCurve: curve["machineCurves"]["Hydrostal"]["H05K-S03R+HGM1X-X280KO"],
} }
} }
@@ -859,18 +864,17 @@ const machine = new Machine(machineConfig, stateConfig);
machine.logger.info(`Registering child...`); machine.logger.info(`Registering child...`);
machine.childRegistrationUtils.registerChild(PT1, "upstream"); machine.childRegistrationUtils.registerChild(PT1, "upstream");
machine.childRegistrationUtils.registerChild(PT2, "downstream"); machine.childRegistrationUtils.registerChild(PT2, "downstream");
/*
//feed curve to the machine class
//machine.updateCurve(curve["machineCurves"]["Hydrostal"]["H05K-S03R+HGM1X-X280KO"]);
PT1.logger.info(`Enable sim...`); PT1.logger.info(`Enable sim...`);
PT1.toggleSimulation(); PT1.toggleSimulation();
PT2.logger.info(`Enable sim...`); PT2.logger.info(`Enable sim...`);
PT2.toggleSimulation(); PT2.toggleSimulation();
machine.getOutput(); */
//manual test //manual test
//machine.handleInput("parent", "execSequence", "startup"); //machine.handleInput("parent", "execSequence", "startup");
/*
machine.measurements.type("pressure").variant("measured").position('upstream').value(-200); machine.measurements.type("pressure").variant("measured").position('upstream').value(-200);
machine.measurements.type("pressure").variant("measured").position('downstream').value(1000); machine.measurements.type("pressure").variant("measured").position('downstream').value(1000);
@@ -880,8 +884,8 @@ const tickLoop = setInterval(changeInput,1000);
function changeInput(){ function changeInput(){
PT1.logger.info(`tick...`); PT1.logger.info(`tick...`);
PT1.tick(); //PT1.tick();
PT2.tick(); //PT2.tick();
} }
async function testingSequences(){ async function testingSequences(){