forked from RnD/rotatingMachine
bug fixes
This commit is contained in:
@@ -63,6 +63,9 @@ class Machine {
|
|||||||
this.model = machineConfig.asset.model; // Get the model from the machineConfig
|
this.model = machineConfig.asset.model; // Get the model from the machineConfig
|
||||||
this.curve = this.model ? loadCurve(this.model) : null;
|
this.curve = this.model ? loadCurve(this.model) : null;
|
||||||
|
|
||||||
|
//Always initialize config first
|
||||||
|
this.config = this.configUtils.initConfig(machineConfig);
|
||||||
|
|
||||||
if (!this.model || !this.curve) {
|
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.`);
|
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
|
// Set prediction objects to null to prevent method calls
|
||||||
@@ -73,13 +76,17 @@ class Machine {
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
this.hasCurve = true;
|
this.hasCurve = true;
|
||||||
|
this.config = this.configUtils.updateConfig(this.config, {
|
||||||
|
asset: { ...this.config.asset, machineCurve: this.curve }
|
||||||
|
});
|
||||||
machineConfig = { ...machineConfig, asset: { ...machineConfig.asset, machineCurve: this.curve } }; // Merge curve into machineConfig
|
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.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.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.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.state = new state(stateConfig, this.logger); // Init State manager and pass logger
|
||||||
this.errorMetrics = new nrmse(errorMetricsConfig, this.logger);
|
this.errorMetrics = new nrmse(errorMetricsConfig, this.logger);
|
||||||
|
|
||||||
@@ -244,6 +251,8 @@ class Machine {
|
|||||||
throw new Error("Invalid setpoint: Setpoint must be a non-negative number.");
|
throw new Error("Invalid setpoint: Setpoint must be a non-negative number.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.info(`Setting setpoint to ${setpoint}. Current position: ${this.state.getCurrentPosition()}`);
|
||||||
|
|
||||||
// Move to the desired setpoint
|
// Move to the desired setpoint
|
||||||
await this.state.moveTo(setpoint);
|
await this.state.moveTo(setpoint);
|
||||||
|
|
||||||
@@ -254,7 +263,7 @@ class Machine {
|
|||||||
|
|
||||||
// Calculate flow based on current pressure and position
|
// Calculate flow based on current pressure and position
|
||||||
calcFlow(x) {
|
calcFlow(x) {
|
||||||
if(!this.hasCurve) {
|
if(this.hasCurve) {
|
||||||
const state = this.state.getCurrentState();
|
const state = this.state.getCurrentState();
|
||||||
|
|
||||||
if (!["operational", "accelerating", "decelerating"].includes(state)) {
|
if (!["operational", "accelerating", "decelerating"].includes(state)) {
|
||||||
@@ -279,7 +288,7 @@ class Machine {
|
|||||||
|
|
||||||
// Calculate power based on current pressure and position
|
// Calculate power based on current pressure and position
|
||||||
calcPower(x) {
|
calcPower(x) {
|
||||||
if(!this.hasCurve) {
|
if(this.hasCurve) {
|
||||||
const state = this.state.getCurrentState();
|
const state = this.state.getCurrentState();
|
||||||
if (!["operational", "accelerating", "decelerating"].includes(state)) {
|
if (!["operational", "accelerating", "decelerating"].includes(state)) {
|
||||||
this.measurements.type("power").variant("predicted").position('upstream').value(0);
|
this.measurements.type("power").variant("predicted").position('upstream').value(0);
|
||||||
@@ -302,7 +311,7 @@ class Machine {
|
|||||||
|
|
||||||
// calculate the power consumption using only flow and pressure
|
// calculate the power consumption using only flow and pressure
|
||||||
inputFlowCalcPower(flow) {
|
inputFlowCalcPower(flow) {
|
||||||
if(!this.hasCurve) {
|
if(this.hasCurve) {
|
||||||
|
|
||||||
this.predictCtrl.currentX = flow;
|
this.predictCtrl.currentX = flow;
|
||||||
const cCtrl = this.predictCtrl.y(flow);
|
const cCtrl = this.predictCtrl.y(flow);
|
||||||
@@ -320,7 +329,7 @@ class Machine {
|
|||||||
|
|
||||||
// Function to predict control value for a desired flow
|
// Function to predict control value for a desired flow
|
||||||
calcCtrl(x) {
|
calcCtrl(x) {
|
||||||
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('upstream').value(cCtrl);
|
||||||
@@ -407,7 +416,7 @@ class Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get
|
// get
|
||||||
const upstreamFlow = this.measurements.type('pressure').variant('measured').position('upstream').getCurrentValue();
|
const upstreamFlow = this.measurements.type('flow').variant('measured').position('upstream').getCurrentValue();
|
||||||
|
|
||||||
// Only upstream => might still accept it, but warn
|
// Only upstream => might still accept it, but warn
|
||||||
if (upstreamFlow != null) {
|
if (upstreamFlow != null) {
|
||||||
@@ -416,7 +425,7 @@ class Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get
|
// get
|
||||||
const downstreamFlow = this.measurements.type('pressure').variant('measured').position('downstream').getCurrentValue();
|
const downstreamFlow = this.measurements.type('flow').variant('measured').position('downstream').getCurrentValue();
|
||||||
|
|
||||||
// Only downstream => might still accept it, but warn
|
// Only downstream => might still accept it, but warn
|
||||||
if (downstreamFlow != null) {
|
if (downstreamFlow != null) {
|
||||||
@@ -450,6 +459,7 @@ class Machine {
|
|||||||
if (this.state.getCurrentState() == "operational" || this.state.getCurrentState() == "accelerating" || this.state.getCurrentState() == "decelerating") {
|
if (this.state.getCurrentState() == "operational" || this.state.getCurrentState() == "accelerating" || this.state.getCurrentState() == "decelerating") {
|
||||||
// put value in measurements
|
// put value in measurements
|
||||||
this.measurements.type("pressure").variant("measured").position(position).value(value);
|
this.measurements.type("pressure").variant("measured").position(position).value(value);
|
||||||
|
this.logger.debug(`Updated measured pressure: ${value} at position: ${position}`);
|
||||||
//when measured pressure gets updated we need some logic to fetch the relevant value which could be downstream or differential pressure
|
//when measured pressure gets updated we need some logic to fetch the relevant value which could be downstream or differential pressure
|
||||||
const pressure = this.getMeasuredPressure();
|
const pressure = this.getMeasuredPressure();
|
||||||
//update the flow power and cog
|
//update the flow power and cog
|
||||||
|
|||||||
Reference in New Issue
Block a user