generic updates completed for now

This commit is contained in:
znetsixe
2025-07-01 15:25:07 +02:00
parent 85eb1eb4a6
commit a6dfbec5d0
9 changed files with 97 additions and 1408 deletions

View File

@@ -44,7 +44,7 @@ maintenanceAlert: this.state.checkMaintenanceStatus()
//load local dependencies
const EventEmitter = require('events');
const {logger,configUtils,configManager,state, nrmse, MeasurementContainer, predict, interpolation , childRegistrationUtils} = require('generalFunctions');
const {loadCurve,logger,configUtils,configManager,state, nrmse, MeasurementContainer, predict, interpolation , childRegistrationUtils} = require('generalFunctions');
class Machine {
@@ -53,13 +53,31 @@ class Machine {
//basic setup
this.emitter = new EventEmitter(); // Own EventEmitter
this.logger = new logger(machineConfig.general.logging.enabled,machineConfig.general.logging.logLevel, machineConfig.general.name);
this.configManager = new configManager();
this.defaultConfig = this.configManager.getConfig('rotatingMachine'); // Load default config for rotating machine
this.defaultConfig = this.configManager.getConfig('rotatingMachine'); // Load default config for rotating machine ( use software type name ? )
this.configUtils = new configUtils(this.defaultConfig);
this.config = this.configUtils.initConfig(machineConfig);
// Init after config is set
this.logger = new logger(this.config.general.logging.enabled,this.config.general.logging.logLevel, this.config.general.name);
// Load a specific curve
this.model = machineConfig.asset.model; // Get the model from the machineConfig
this.curve = this.model ? loadCurve(this.model) : null;
if (!this.model || !this.curve) {
this.logger.warning(`${!this.model ? 'Model not specified' : 'Curve not found for model ' + this.model} in machineConfig. Cannot make predictions.`);
// Set prediction objects to null to prevent method calls
this.predictFlow = null;
this.predictPower = null;
this.predictCtrl = null;
this.hasCurve = false;
}
else{
this.hasCurve = true;
machineConfig = { ...machineConfig, asset: { ...machineConfig.asset, machineCurve: this.curve } }; // Merge curve into machineConfig
this.config = this.configUtils.initConfig(machineConfig);
this.predictFlow = new predict({ curve: this.config.asset.machineCurve.nq }); // load nq (x : ctrl , y : flow relationship)
this.predictPower = new predict({ curve: this.config.asset.machineCurve.np }); // load np (x : ctrl , y : power relationship)
this.predictCtrl = new predict({ curve: this.reverseCurve(this.config.asset.machineCurve.nq) }); // load reversed nq (x: flow, y: ctrl relationship)
}
this.state = new state(stateConfig, this.logger); // Init State manager and pass logger
this.errorMetrics = new nrmse(errorMetricsConfig, this.logger);
@@ -71,10 +89,6 @@ class Machine {
this.flowDrift = null;
this.predictFlow = new predict({ curve: this.config.asset.machineCurve.nq }); // load nq (x : ctrl , y : flow relationship)
this.predictPower = new predict({ curve: this.config.asset.machineCurve.np }); // load np (x : ctrl , y : power relationship)
this.predictCtrl = new predict({ curve: this.reverseCurve(this.config.asset.machineCurve.nq) }); // load reversed nq (x: flow, y: ctrl relationship)
this.currentMode = this.config.mode.current;
this.currentEfficiencyCurve = {};
this.cog = 0;
@@ -239,55 +253,84 @@ class Machine {
// Calculate flow based on current pressure and position
calcFlow(x) {
const state = this.state.getCurrentState();
if(!this.hasCurve) {
const state = this.state.getCurrentState();
if (!["operational", "accelerating", "decelerating"].includes(state)) {
this.measurements.type("flow").variant("predicted").position("downstream").value(0);
this.logger.debug(`Machine is not operational. Setting predicted flow to 0.`);
return 0;
}
if (!["operational", "accelerating", "decelerating"].includes(state)) {
this.measurements.type("flow").variant("predicted").position("downstream").value(0);
this.logger.debug(`Machine is not operational. Setting predicted flow to 0.`);
return 0;
}
//this.predictFlow.currentX = x; Decrepated
const cFlow = this.predictFlow.y(x);
this.measurements.type("flow").variant("predicted").position("downstream").value(cFlow);
//this.logger.debug(`Calculated flow: ${cFlow} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
return cFlow;
}
// If no curve data is available, log a warning and return 0
this.logger.warn(`No curve data available for flow calculation. Returning 0.`);
this.measurements.type("flow").variant("predicted").position("downstream").value(0);
return 0;
}
// Calculate power based on current pressure and position
calcPower(x) {
const state = this.state.getCurrentState();
if (!["operational", "accelerating", "decelerating"].includes(state)) {
this.measurements.type("power").variant("predicted").position('upstream').value(0);
this.logger.debug(`Machine is not operational. Setting predicted power to 0.`);
return 0;
}
if(!this.hasCurve) {
const state = this.state.getCurrentState();
if (!["operational", "accelerating", "decelerating"].includes(state)) {
this.measurements.type("power").variant("predicted").position('upstream').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.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);
return 0;
}
// calculate the power consumption using only flow and pressure
inputFlowCalcPower(flow) {
this.predictCtrl.currentX = flow;
const cCtrl = this.predictCtrl.y(flow);
this.predictPower.currentX = cCtrl;
const cPower = this.predictPower.y(cCtrl);
return cPower;
if(!this.hasCurve) {
this.predictCtrl.currentX = flow;
const cCtrl = this.predictCtrl.y(flow);
this.predictPower.currentX = cCtrl;
const cPower = this.predictPower.y(cCtrl);
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);
return 0;
}
// Function to predict control value for a desired flow
calcCtrl(x) {
this.predictCtrl.currentX = x;
const cCtrl = this.predictCtrl.y(x);
this.measurements.type("ctrl").variant("predicted").position('upstream').value(cCtrl);
//this.logger.debug(`Calculated ctrl: ${cCtrl} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
return cCtrl;
if(!this.hasCurve) {
this.predictCtrl.currentX = x;
const cCtrl = this.predictCtrl.y(x);
this.measurements.type("ctrl").variant("predicted").position('upstream').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);
return 0;
}