82 lines
3.6 KiB
JavaScript
82 lines
3.6 KiB
JavaScript
|
|
// code is kopie van rotating machine specific class
|
|
|
|
//load local dependencies
|
|
const EventEmitter = require('events');
|
|
const {loadCurve,logger,configUtils,configManager,state, nrmse, MeasurementContainer, predict, interpolation , childRegistrationUtils} = require('generalFunctions');
|
|
const { name } = require('../../generalFunctions/src/convert/lodash/lodash._shimkeys');
|
|
|
|
class Monster {
|
|
|
|
/*------------------- Construct and set vars -------------------*/
|
|
constructor(machineConfig = {}, stateConfig = {}, errorMetricsConfig = {}) {
|
|
|
|
//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('monster'); // Load default config for monster ( use software type name ? )
|
|
this.configUtils = new configUtils(this.defaultConfig);
|
|
|
|
// Load a specific curve
|
|
this.model = machineConfig.asset.model; // Get the model from the machineConfig
|
|
this.curve = this.model ? loadCurve(this.model) : null;
|
|
|
|
//Init config and check if it is valid
|
|
this.config = this.configUtils.initConfig(machineConfig);
|
|
|
|
//add unique name for this node.
|
|
this.config = this.configUtils.updateConfig(this.config, {general:{name: this.config.functionality?.softwareType + "_" + machineConfig.general.id}}); // add unique name if not present
|
|
|
|
if (!this.model || !this.curve) {
|
|
this.logger.error(`${!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;
|
|
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
|
|
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);
|
|
|
|
// Initialize measurements
|
|
this.measurements = new MeasurementContainer();
|
|
this.interpolation = new interpolation();
|
|
|
|
this.flowDrift = null;
|
|
|
|
this.currentMode = this.config.mode.current;
|
|
this.currentEfficiencyCurve = {};
|
|
this.cog = 0;
|
|
this.NCog = 0;
|
|
this.cogIndex = 0;
|
|
this.minEfficiency = 0;
|
|
this.absDistFromPeak = 0;
|
|
this.relDistFromPeak = 0;
|
|
|
|
// When position state changes, update position
|
|
this.state.emitter.on("positionChange", (data) => {
|
|
this.logger.debug(`Position change detected: ${data}`);
|
|
this.updatePosition();
|
|
});
|
|
|
|
this.child = {}; // object to hold child information so we know on what to subscribe
|
|
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
|
|
|
|
}
|
|
}
|
|
|
|
module.exports = Monster;
|