Commit 264a5463 authored by Jacob Wikmark's avatar Jacob Wikmark
Browse files

documentation, minor fixes

parent 0e06fc60
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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment