From 264a54637d52f820b34cae66f551dc85bef9933e Mon Sep 17 00:00:00 2001 From: Jacob Wikmark <jacob@wikmark.se> Date: Tue, 13 Mar 2018 14:13:28 +0100 Subject: [PATCH] documentation, minor fixes --- src/tanklabgui.jl | 64 +++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/src/tanklabgui.jl b/src/tanklabgui.jl index b9542fa..41019d1 100644 --- a/src/tanklabgui.jl +++ b/src/tanklabgui.jl @@ -1,4 +1,9 @@ -function makegui(P, plottingframerate = 10, guiframerate = 10) +""" +makegui(P, run_process, plottingframerate = 10, guiframerate = 10) + +Used to create a gui for the tanklab, returns the gui, the responder (to be served as a web app) and the controller. The plottingframerate and guiframerate determine the bandwidth required for the app. More than 20fps may be more than the plotting method can handle. +""" +function makegui(P, run_process, plottingframerate = 10, guiframerate = 10) tankpid = PID() boundsupper = (0,1) boundslower = (-2,2) @@ -6,9 +11,14 @@ function makegui(P, plottingframerate = 10, guiframerate = 10) gui = GUI() ptfr = 3.8 #pump to flow ratio, approximate + + """ + We have below 4 construct calls which produce all widgets and graphics for the gui. Two are used to create the graphics and use dummy widgets (used to animate the graphics). Two are used to create the widgets, and use dummy graphics. These graphics must be manually added to the gui DOM or the widgets won't function. Widgets must also be included in the gui DOM but calling the gui() function will take care of this as long as the widgets containers are added to the GUI. + """ #This allows external access to the r value, the rbox string is parsed into this value rcont, dummygraphic1 = @construct for r in slider(0.0:0.01:1.0) + Node(:div) end @@ -28,31 +38,32 @@ function makegui(P, plottingframerate = 10, guiframerate = 10) rbox in textbox(" r "), expcsv in button("Export Data") - rv = obs(r)[] + tankpid.K = K + tankpid.Ti = Ti + tankpid.Td = Td + + rv = observe(r)[] if !endswith(rbox, ".") && rbox != "0" try - #obs(r).val = parse(Float64, rbox) rv = parse(Float64, rbox) end if 0.0<rv<1.0 - obs(r).val = rv + observe(r).val = rv end end - Node(:div) + Node(:div) #empty node end widgets, graphic1 = @construct for svgdummy in checkbox(false, label="This button does nothing") - tankpid.K = obs(K)[] - tankpid.Ti = obs(Ti)[] - tankpid.Td = obs(Td)[] - - if obs(tankno)[]=="Upper" - tankg = tank_construct(measure(P)..., obs(u)[]*ptfr, 1, obs(r).val) - elseif obs(tankno)[]=="Lower" - tankg = tank_construct(measure(P)..., obs(u)[]*ptfr, 2, obs(r).val) + + + if observe(tankno)[]=="Upper" + tankg = tank_construct(measure(P)..., observe(u)[]*ptfr, 1, observe(r).val) + elseif observe(tankno)[]=="Lower" + tankg = tank_construct(measure(P)..., observe(u)[]*ptfr, 2, observe(r).val) else - tankg = tank_construct(measure(P)..., obs(u)[]*ptfr) + tankg = tank_construct(measure(P)..., observe(u)[]*ptfr) end Node(:div, tankg, id="tanks", attributes=tankattr) end @@ -60,6 +71,7 @@ function makegui(P, plottingframerate = 10, guiframerate = 10) glnv = (0:maxplotlength)*P.h w2, graphic2 = @construct for plotdummy in checkbox(false, label="This button does nothing") + dataln = length(gui.data[1]) if dataln>maxplotlength start = dataln-maxplotlength @@ -78,25 +90,34 @@ function makegui(P, plottingframerate = 10, guiframerate = 10) #-----------------------------------------------# #This should only exist in the simulated version# - on(obs(run)) do val + on(observe(run)) do val if val==1 - @async prbs_experiment(P, gui, tankpid) + @async run_process(P, gui, tankpid) else - obs(run).listeners[end] = x ->() + observe(run).listeners[end] = x ->() end end #-----------------------------------------------# # And this should only exist in the real version# - on(obs(cali)) do val + on(observe(cali)) do val calibrate(P) end #-----------------------------------------------# - on(obs(expcsv)) do val - writecsv("datatanklab.csv", - [gui.data[1] gui.data[2] gui.data[3] gui.data[4] gui.data[5] gui.data[6]]) + on(observe(expcsv)) do val + f = open("datatanklab.csv", "w") + writedlm(f, ["t" "y" "r" "P" "I" "D" "Tot"], ',') + writedlm(f, [gui.data[7] gui.data[1] gui.data[2] gui.data[3] gui.data[4] gui.data[5] gui.data[6]], ',') + close(f) print("Data exported to datatanklab.csv\n") end + on(observe(mode)) do val + if val=="Manual" + observe(u)[] = observe(u)[] + end + end + + # Below is the construction of the gui DOM LabGUI.set!(gui, widgets) add!(gui, rcont) add!(gui, w0) @@ -145,6 +166,7 @@ function makegui(P, plottingframerate = 10, guiframerate = 10) LabGUI.animate(gui, :svgdummy, 1/guiframerate) LabGUI.animate(gui, :plotdummy, 1/plottingframerate) + function responder(req) @async (sleep(1); gui[:rbox] = "0.5") #Inits r textbox, must be done after dom is loaded in browser gui() -- GitLab