forked from RnD/machineGroupControl
added testfile fixing bugs
This commit is contained in:
@@ -1,28 +1,4 @@
|
||||
/**
|
||||
* @file machine.js
|
||||
*
|
||||
* Permission is hereby granted to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to use it for personal
|
||||
* or non-commercial purposes, with the following restrictions:
|
||||
*
|
||||
* 1. **No Copying or Redistribution**: The Software or any of its parts may not
|
||||
* be copied, merged, distributed, sublicensed, or sold without explicit
|
||||
* prior written permission from the author.
|
||||
*
|
||||
* 2. **Commercial Use**: Any use of the Software for commercial purposes requires
|
||||
* a valid license, obtainable only with the explicit consent of the author.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Ownership of this code remains solely with the original author. Unauthorized
|
||||
* use of this Software is strictly prohibited.
|
||||
*
|
||||
* @summary A class to interact and manipulate machines with a non-euclidian curve
|
||||
* @description A class to interact and manipulate machines with a non-euclidian curve
|
||||
* @module machineGroup
|
||||
@@ -252,13 +228,11 @@ class MachineGroup {
|
||||
//machineId = parseInt(machineId);
|
||||
|
||||
const state = machines[machineId].state.getCurrentState();
|
||||
|
||||
const validSourceForMode = machines[machineId].isValidSourceForMode("parent", "auto");
|
||||
const validActionForMode = machines[machineId].isValidActionForMode("execSequence", "auto");
|
||||
|
||||
|
||||
// Reasons why a machine is not valid for the combination
|
||||
if( state === "off" || state === "coolingdown" || state === "stopping" || state === "emergencystop" || !validSourceForMode || !validActionForMode){
|
||||
if( state === "off" || state === "coolingdown" || state === "stopping" || state === "emergencystop" || !validActionForMode){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -353,10 +327,6 @@ class MachineGroup {
|
||||
}
|
||||
|
||||
// -------- Mode and Input Management -------- //
|
||||
isValidSourceForMode(source, mode) {
|
||||
const allowedSourcesSet = this.config.mode.allowedSources[mode] || [];
|
||||
return allowedSourcesSet.has(source);
|
||||
}
|
||||
|
||||
isValidActionForMode(action, mode) {
|
||||
const allowedActionsSet = this.config.mode.allowedActions[mode] || [];
|
||||
@@ -531,10 +501,9 @@ class MachineGroup {
|
||||
filterOutUnavailableMachines(list) {
|
||||
const newList = list.filter(({ id, machine }) => {
|
||||
const state = machine.state.getCurrentState();
|
||||
const validSourceForMode = machine.isValidSourceForMode("parent", "auto");
|
||||
const validActionForMode = machine.isValidActionForMode("execSequence", "auto");
|
||||
|
||||
return !(state === "off" || state === "coolingdown" || state === "stopping" || state === "emergencystop" || !validSourceForMode || !validActionForMode);
|
||||
return !(state === "off" || state === "coolingdown" || state === "stopping" || state === "emergencystop" || !validActionForMode);
|
||||
});
|
||||
return newList;
|
||||
}
|
||||
@@ -806,12 +775,6 @@ class MachineGroup {
|
||||
|
||||
async handleInput(source, Qd, powerCap = Infinity, priorityList = null) {
|
||||
|
||||
|
||||
if (!this.isValidSourceForMode(source, this.mode)) {
|
||||
this.logger.warn(`Invalid source ${source} for mode ${this.mode}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const scaling = this.scaling;
|
||||
const mode = this.mode;
|
||||
let rawInput = Qd;
|
||||
@@ -848,6 +811,10 @@ class MachineGroup {
|
||||
case "optimalcontrol":
|
||||
await this.optimalControl(Qd,powerCap);
|
||||
break;
|
||||
|
||||
default:
|
||||
this.logger.warn(`${mode} is not a valid mode.`);
|
||||
break;
|
||||
}
|
||||
|
||||
//recalc distance from BEP
|
||||
@@ -857,8 +824,8 @@ class MachineGroup {
|
||||
|
||||
}
|
||||
|
||||
setMode(source,mode) {
|
||||
this.isValidSourceForMode(source, mode) ? this.mode = mode : this.logger.warn(`Invalid source ${source} for mode ${mode}`);
|
||||
setMode(mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
getOutput() {
|
||||
@@ -1009,7 +976,7 @@ async function makeMachines(){
|
||||
mg.machines[1].childRegistrationUtils.registerChild(pt1, "downstream");
|
||||
mg.machines[2].childRegistrationUtils.registerChild(pt1, "downstream");
|
||||
|
||||
mg.setMode("parent","prioritycontrol");
|
||||
//mg.setMode("prioritycontrol");
|
||||
mg.setScaling("normalized");
|
||||
|
||||
const absMax = mg.dynamicTotals.flow.max;
|
||||
@@ -1047,9 +1014,9 @@ async function makeMachines(){
|
||||
/*
|
||||
for(let demand = 0 ; demand <= 100 ; demand += 1){
|
||||
//set pressure
|
||||
|
||||
console.log("------------------------------------");
|
||||
|
||||
console.log(`processing demand of ${demand}`);
|
||||
|
||||
await mg.handleInput("parent",demand);
|
||||
console.log(mg.machines[1].state.getCurrentState());
|
||||
console.log(mg.machines[2].state.getCurrentState());
|
||||
@@ -1071,4 +1038,4 @@ async function makeMachines(){
|
||||
|
||||
makeMachines();
|
||||
|
||||
*/
|
||||
//*/
|
||||
Reference in New Issue
Block a user