diff --git a/src/tankdemo.jl b/src/tankdemo.jl index e0ca0ccd6be5c64955409e7f0652882eae2104f6..616082afcc3707bb68d8207521c235eba59f25fe 100644 --- a/src/tankdemo.jl +++ b/src/tankdemo.jl @@ -31,43 +31,48 @@ function runprocess(;simulated=false, webservice=true, port=8000, σ = 0.001, du n = 1 LabProcesses.initialize(P) start_time = time() - for t in 0:P.h:duration - @periodically P.h begin - y = measure(P)[n] - r = gui[:r] - if gui[:tankno]=="Upper" - n = 1 - else - n = 2 - end - onv = Int.([gui[s]=="On" for s in [:pOn, :iOn, :dOn]]) - rv = pidcontroller(r, y, onv) - if gui[:mode]=="Automatic" - gui[:u] = clamp(round(rv,digits=2), 0, 1) #u's constructor has only a dummy graphic so this is fine - control(P, rv) - elseif gui[:mode]=="Manual" - control(P, gui[:u]) - #bumpless transfer: - if gui[:iOn]=="On" - pidcontroller.I = gui[:u]-(pidcontroller.Tot-pidcontroller.I) - end + for t in 0:P.h:20 + y = measure(P)[n] + r = gui[:r] + if gui[:tankno]=="Upper" + n = 1 + else + n = 2 + end + onv = Int.([gui[s]=="On" for s in [:pOn, :iOn, :dOn]]) + rv = pidcontroller(r, y, onv) + if gui[:mode]=="Automatic" + gui[:u] = clamp(round(rv,digits=2), 0, 1) #u's constructor has only a dummy graphic so this is fine + control(P, rv) + elseif gui[:mode]=="Manual" + control(P, gui[:u]) + #bumpless transfer: + if gui[:iOn]=="On" + pidcontroller.I = gui[:u]-(pidcontroller.Tot-pidcontroller.I) end - @show t # Not working without some print in the loop, not sure why... - push!(gui, y, 1) - push!(gui, r, 2) - push!(gui, pidcontroller.P, 3) - push!(gui, pidcontroller.I, 4) - push!(gui, pidcontroller.D, 5) - push!(gui, pidcontroller.Tot, 6) - push!(gui, t, 7) end + # @show t # Not working without some print in the loop, not sure why... + push!(gui, y, 1) + push!(gui, r, 2) + push!(gui, pidcontroller.P, 3) + push!(gui, pidcontroller.I, 4) + push!(gui, pidcontroller.D, 5) + push!(gui, pidcontroller.Tot, 6) + push!(gui, t, 7) + + end_time = time() + sleep_time = P.h + start_time - end_time + if sleep_time ≥ 0.001 + sleep(sleep_time) + end + start_time = end_time end println("The lab time is over, go home! 😊\n") #Easter egg, unlikely to be shown LabProcesses.finalize(P) end - g1, r1, tp = makegui(R, run_process, 1, 1) + g1, r1, tp = makegui(R, run_process, 10, 10) if webservice webio_serve(page("/", r1), port)