From 6b5890998c25367cfe1ba9f50b50442293bb0e3b Mon Sep 17 00:00:00 2001 From: Nils Olsson Date: Sat, 31 Jul 2021 00:58:57 -0700 Subject: [PATCH] Update --- myps/src/lexer/mod.rs | 3 +- .../factory/furnace/display-actual.myps | 0 .../{gas.myps => furnace/furnace.myps} | 26 ++-- myps/test-scripts/factory/furnace/input.myps | 12 ++ .../{gas-test.myps => furnace/progress.myps} | 43 +++--- .../factory/furnace/validator-dispatcher.myps | 28 ++++ myps/test-scripts/factory/gas.myps2 | 131 ------------------ 7 files changed, 80 insertions(+), 163 deletions(-) create mode 100644 myps/test-scripts/factory/furnace/display-actual.myps rename myps/test-scripts/factory/{gas.myps => furnace/furnace.myps} (95%) create mode 100644 myps/test-scripts/factory/furnace/input.myps rename myps/test-scripts/factory/{gas-test.myps => furnace/progress.myps} (67%) create mode 100644 myps/test-scripts/factory/furnace/validator-dispatcher.myps delete mode 100644 myps/test-scripts/factory/gas.myps2 diff --git a/myps/src/lexer/mod.rs b/myps/src/lexer/mod.rs index d2b2a19..f016f87 100644 --- a/myps/src/lexer/mod.rs +++ b/myps/src/lexer/mod.rs @@ -19,7 +19,8 @@ pub fn lex_string(source: String) -> MypsResult { } pub fn lex_file + std::fmt::Debug>(path: P) -> MypsResult { - let f = File::open(path.into()).unwrap(); + let path_string = format!("{:?}", path); + let f = File::open(path.into()).expect(&path_string); let f = BufReader::new(f); let lines = f.lines().collect::, _>>().unwrap(); lex_lines(lines.into_iter()) diff --git a/myps/test-scripts/factory/furnace/display-actual.myps b/myps/test-scripts/factory/furnace/display-actual.myps new file mode 100644 index 0000000..e69de29 diff --git a/myps/test-scripts/factory/gas.myps b/myps/test-scripts/factory/furnace/furnace.myps similarity index 95% rename from myps/test-scripts/factory/gas.myps rename to myps/test-scripts/factory/furnace/furnace.myps index 2e2eeba..105402d 100644 --- a/myps/test-scripts/factory/gas.myps +++ b/myps/test-scripts/factory/furnace/furnace.myps @@ -1,9 +1,11 @@ -furnace = d0 -tankC = d1 -tankH = d2 -nCPump = d3 -nHPump = d4 -nIAnlzr = d5 +#furnace = d0 +#nIAnlzr = d5 + +tankC = d0 +tankH = d1 +nCPump = d2 +nHPump = d3 +progressDest = d4 def vF = 1000 # furnace volume def R = 8.314 # universal gas consant @@ -15,14 +17,14 @@ def nCfactor = (6200) / 6000 def nHfactor = (6200) / 6000 # PD coefficients and minimum error (perhaps adjust) -def kPF = 0.06 -def kDF = 0.03 +def kPF = 0.09 +def kDF = 0.06 -def kPC = 0.06 -def kDC = 0.03 +def kPC = 0.09 +def kDC = 0.06 -def kPH = 0.06 -def kDH = 0.03 +def kPH = 0.09 +def kDH = 0.06 def ERRORF = 0.01 def ERRORC = 0.03 diff --git a/myps/test-scripts/factory/furnace/input.myps b/myps/test-scripts/factory/furnace/input.myps new file mode 100644 index 0000000..7a3a0ba --- /dev/null +++ b/myps/test-scripts/factory/furnace/input.myps @@ -0,0 +1,12 @@ +tTSDial = d0 +tTMDial = d1 +tTLDial = d2 +pTSDial = d3 +pTMDial = d4 +pTLDial = d5 + +loop: + yield() + tT = (tTSDial.Setting + 10 * tTMDial.Setting + 100* tTLDial.Setting) + pT = (pTSDial.Setting + 10 * pTMDial.Setting + 100* pTLDial.Setting) * 1000 + db.Setting = tT + pT diff --git a/myps/test-scripts/factory/gas-test.myps b/myps/test-scripts/factory/furnace/progress.myps similarity index 67% rename from myps/test-scripts/factory/gas-test.myps rename to myps/test-scripts/factory/furnace/progress.myps index 6996535..5184af7 100644 --- a/myps/test-scripts/factory/gas-test.myps +++ b/myps/test-scripts/factory/furnace/progress.myps @@ -1,9 +1,7 @@ furnace = d0 tankC = d1 tankH = d2 -eFdest = d3 -eCdest = d4 -eHdest = d5 +progressDest = d3 def vF = 1000 def R = 8.314 @@ -15,10 +13,26 @@ def ERRORF = 0.01 def ERRORC = 0.03 def ERRORH = 0.03 +eFdest.Mode = 1 # percentages +eCdest.Mode = 1 +eHdest.Mode = 1 + +db.Setting = 0 loop: yield() input = db.Setting - if input > 0: + haveInput = input > 0 + + eFdest.On = haveInput + eCdest.On = haveInput + eHdest.On = haveInput + + fix nR, nHI, nCI + if haveInput: + eFdest.Setting = 0 + eCdest.Setting = 0 + eHdest.Setting = 0 + input = trunc(input) tT = (input % 1000) * 10 pT = trunc(input / 1000) * 100 @@ -37,13 +51,10 @@ loop: nCI = nI - nHI fix rF = nF - nR - nC = nCfactor * tankC.TotalMoles fix rC = nC - nCI - nH = nHfactor * tankH.TotalMoles fix rH = nH - nHI - tag PDLoop: yield() nF = furnace.TotalMoles @@ -54,17 +65,11 @@ loop: eC = nC - rC eH = nH - rH - FNotDone = (eF > ERRORF) - CNotDone = (eC > ERRORC) - HNotDone = (eH > ERRORH) + eFdest.Setting = (1 - eF / nR ) + eCdest.Setting = (1 - eC / nCI) + eHdest.Setting = (1 - eH / nHI) - eFdest.Setting = FNotDone ? eF : 0 - #eFdest.On = FNotDone ? eF : 0 - eCdest.Setting = FNotDone ? eC : 0 - #eCdest.On = FNotDone ? eC : 0 - eHdest.Setting = CNotDone ? eH : 0 - #eHdest.On = CNotDone ? eH : 0 + loop = eF > ERRORF or eC > ERRORC or eH > ERRORH + bnez(loop, PDLoop) - bnez(FNotDone, PDLoop) - bnez(CNotDone, PDLoop) - bnez(HNotDone, PDLoop) + db.Setting = 0 diff --git a/myps/test-scripts/factory/furnace/validator-dispatcher.myps b/myps/test-scripts/factory/furnace/validator-dispatcher.myps new file mode 100644 index 0000000..ec93f6e --- /dev/null +++ b/myps/test-scripts/factory/furnace/validator-dispatcher.myps @@ -0,0 +1,28 @@ +inputControl = d0 +tTDisp = d1 +pTDisp = d2 +tankC = d3 +tankH = d4 +furnaceControl = d5 + +def GREEN = 2 +def GRAY = 1 + +loop: + yield() + input = inputControl.Setting + tT = (input % 1000) * 10 + pT = trunc(input / 1000) * 100 + tC = tankC.Temperature + tH = tankH.Temperature + tValid = tC < tT and tT < tH + pValid = 0 < pT and pT < 60000 + + tTDisp.Setting = tT + pTDisp.Setting = pT + tTDisp.Color = tValid ? GREEN : GRAY + pTDisp.Color = pValid ? GREEN : GRAY + + #if tValid and db.Setting != 0: + # if dse(furnaceControl): + # furnaceControl.Setting = input \ No newline at end of file diff --git a/myps/test-scripts/factory/gas.myps2 b/myps/test-scripts/factory/gas.myps2 deleted file mode 100644 index 6d73967..0000000 --- a/myps/test-scripts/factory/gas.myps2 +++ /dev/null @@ -1,131 +0,0 @@ -furnace = d0 -tankC = d1 -tankH = d2 -nCPump = d3 -nHPump = d4 -nIAnlzr = d5 - -def vF = 1000 # furnace volume -def R = 8.314 # universal gas consant -def dt = 0.5 # time step - -# Source volume-mole factor (adjust per setup) -# e.g. 6100 = 1 furnace (6000) + 1 pipe (100) L -def vCFactor = (6100) / 6000 -def vHFactor = (6100) / 6000 - -# PD coefficients and minimum error (perhaps adjust) -def kPF = 0.06 -def kDF = 0.02 -def kPC = 0.06 -def kDC = 0.02 -def kPH = 0.06 -def kDH = 0.02 -def ERRORF = 0.03 -def ERRORC = 0.03 -def ERRORH = 0.03 - -# Input target temperatre/pressure format: PPPTTT -# ``` -# input = db.Setting -# tT = input % 1000 * 10 K -# input = trunc(input / 1000) -# pT = input * 100 kPa -# ``` -# e.g. 500050 -> tT = 50*10 = 500 K, pT = 500*100 = 50,000 kPa -loop: - yield() - input = db.Setting - if input < 0: - db.Setting = 0 - elif input > 0: - # unpack input temperature and pressure - input = trunc(input) - tT = (input % 1000) * 10 - pT = trunc(input / 1000) * 100 - - # (a) read furnace moles and temperature (nF/tF) - fix nF = furnace.TotalMoles - tF = furnace.Temperature - - # (b) read tank temperatures - tC = tankC.Temperature - tH = tankH.Temperature - - # (d) calculate moles to remove and add from C and H (nR/nC/nH) - fix nCI, nHI # TODO: Scopes need to be restricted better... - tag partD: - nT = pT*vF/(R*tT) - tTnT = tT*nT - nRC = (tTnT-tH*nT)/(tH-tF)+nF - nRH = (tTnT-tC*nT)/(tC-tF)+nF - nR = max(0, max(nRC, nRH)) - nD = nF-nR - nI = nT-nD - tI = (tTnT-tF*nD)/nI - nHI = (nI*(tC-tI))/(tC-tH) # nHI - nCI = nI-nHI # nCI - - # (e) remove nR, mix nC and nH - tag parthE: - fix nC = vCFactor * tankC.TotalMoles # calc C moles - fix nH = vHFactor * tankH.TotalMoles # calc H moles - - rF = nF - nR # calc F target (rF) - rC = nC - nCI # calc C target (rC - rH = nH - nHI # calc H target (rH) - - yield() - nCPump.On = 1 - nCPump.Setting = 0 - nHPump.On = 1 - nHPump.Setting = 0 - fix eF = nF - rF # fix F error (nF - rF) - fix eC = nC - rC # fix C error (nC - rC) - fix eH = nH - rH # fix H error (nH - rH) - fix eFPrev = 0 # fix F error (prev) - fix eCPrev = 0 # fix C error (prev) - fix eHPrev = 0 # fix H error (prev) - while eF > 0.1 or eC > 0.1 or eH > 0.1: - if eF > ERRORF: - uF = (kPF * eF) + (kDF * (eF - eFPrev) / dt) - furnace.SettingOutput = uF # set furnace out - else: - furnace.SettingOutput = 0 - furnace.SettingInput = 100 - - if eC > ERRORC: - uC = (kPC * eC) + (kDC * (eC - eCPrev) / dt) - nCPump.Setting = uC # set C pump - - if eH > ERRORH: - uH = (kPH * eH) + (kDH * (eH - eHPrev) / dt) - nHPump.Setting = uH # set H pump - - eFPrev = eF # save F error - eCPrev = eC # save C error - eHPrev = eH # save H error - - yield() - if eF > ERRORF: - nF = furnace.TotalMoles.avg - eF = nF - rF - - if eC > ERRORC: - nC = vCFactor * tankC.TotalMoles - eC = nC - rC - - if eH > ERRORH: - nH = vHFactor * tankH.TotalMoles - eH = nH - rH - nCPump.On = 0 - nHPump.On = 0 - - # (f) input the nC and nH gas (can the necessary run time be calculated?) - furnace.SettingInput = 100 - while nIAnlzr.TotalMoles.avg > 0: - yield() - furnace.SettingInput = 0 - - # (?) enjoy - db.Setting = 0