You don’t need a ‘goto’ when the next line is the one noted by the goto.
Also is see values getting evaluated which will not, such as in State 1... Bain Marie comparison > 243 will never be executed because the Vapor temp lines before it will since its comparison values are lower. Make sense?
I would eschew the idea of state machines ala BCS which duplicate code to make your script efficient. Create one loop that runs and calls sections depending on the section.
1 - got it...
2 - yep, I see that, I was originally measuring two different temps, but when I change one to be the same as the other, I did not catch that, thank you.
3 - I tried to do one loop, but ran into some roadblocks
I have streamlined it here:
Code:
new value StopTemp
new string CurrentState
StopTemp = 207
stop "CoolDownTimer"
reset "CoolDownTimer"
restart "Total Runtime"
// Enable all devices needed
"9kW 0" Enabled = true
"9kW 1" Enabled = true
"9kW 2" Enabled = true
"9kW 3" Enabled = true
"Agitator" Enabled = true
"Bain Marie" Enabled = true
"Boiler Temp" Enabled = true
"Vapor Temp 1" Enabled = true
"Vapor Temp 2" Enabled = true
"PC Water IN" Enabled = true
"PC Water OUT" Enabled = true
"PC HX Return" Enabled = true
"RC Water IN" Enabled = true
"RC Water OUT" Enabled = true
"PC Pump" Enabled = true
"PC Fan" Enabled = true
"RC Pump" Enabled = true
"RC Fan" Enabled = true
"AlarmOut 1" Enabled = true
"Running" Enabled = true
// start the still run
"Running" State = on
[State0]
CurrentState = "Heat_36kW"
"9kW 0" State = on
sleep 1000 // pause before energizing another contactor
"9kW 1" State = on
sleep 1000 // pause before energizing another contactor
"9kW 2" State = on
sleep 1000 // pause before energizing another contactor
"9kW 3" State = on
sleep 1000 // pause before energizing Agitator
"Agitator" State = on
[State1]
if "Vapor Temp 1" Value >= 170 // exit to distilling state
goto State5
endif
if "Bain Marie" Value < 240 // exit to State2 when BM temp reaches 240 (~1 Bar)
goto State1
endif
[State2]
"9kW 3" State = off
CurrentState = "Heat_27kW"
if "Vapor Temp 1" Value >= 170 // exit to distilling state
goto State5
endif
if "Bain Marie" Value < 241 // exit to State3 when BM temp reaches 241 (~1 Bar)
goto State2
endif
[State3]
"9kW 2" State = off
CurrentState = "Heat_18kW"
if "Vapor Temp 1" Value >= 170 // exit to distilling state
goto State5
endif
if "Bain Marie" Value < 241 // exit to State4 when BM temp reaches 241 (~1 Bar)
goto State3
endif
[State4]
"9kW 1" State = off
CurrentState = "Heat_9kW"
if "Vapor Temp 1" Value >= 170 // exit to distilling state
goto State5
endif
if "Bain Marie" Value >= 243 // shut off all heat if BM temp gets too high
"Alarm 1" Active = true
goto CoolDown
endif
[State5]
CurrentState = "Distill"
"PC Pump" State = on
"PC Fan" State = on
"RC Pump" State = on
"RC Fan" State = on
if "Vapor Temp 1" Value >= StopTemp // exit to cooldown state
goto CoolDown
endif
if "Bain Marie" Value >= 243 // shut off all heat if BM temp gets too high
"Alarm 1" Active = true
goto CoolDown
endif
goto State5
[CoolDown]
CurrentState = "CoolDown"
"9kW 0" State = off
"9kW 1" State = off
"9kW 2" State = off
"9kW 3" State = off
restart "CoolDownTimer"
wait "CoolDownTimer" Value > 00:05:00 // waits until the timer exceeds 5 minutes
//Turn off Cooling
"PC Pump" State = off
"PC Fan" State = off
"RC Pump" State = off
"RC Fan" State = off
"Agitator" State = off
// Disable all outputs
"9kW 0" Enabled = false
"9kW 1" Enabled = false
"9kW 2" Enabled = false
"9kW 3" Enabled = false
"Agitator" Enabled = false
"PC Pump" Enabled = false
"PC Fan" Enabled = false
"RC Pump" Enabled = false
"RC Fan" Enabled = false
"AlarmOut 1" Enabled = false
"Running" Enabled = false
stop "Still Run Script"