diff --git a/src/DoubleTank.jl b/src/DoubleTank.jl index c65da02848fea6427c1d2aeae0cfa72eb7ff9e6a..7a2781c6e43717563ce3660f0c63c49fae0f13d0 100644 --- a/src/DoubleTank.jl +++ b/src/DoubleTank.jl @@ -11,6 +11,12 @@ const venturimax = 14.0 using Parameters +#struct BC + #ar::Array{Float64, 1} +#end + +#bc = BC([]) + #Change later ############################################################ using LabConnections.Computer @@ -107,7 +113,7 @@ function Pump(stream) pid.K = 0.21 pid.Ti = 0.06 pid.b = 0.0 - pid.h = 0.01 #change to 0.01 later + pid.h = 0.01 Pump(pid.h, stream, 0.0, 0.0, pid, [venturimin, venturimax], AnalogInput10V(4), AnalogOutput10V(0)) end @@ -123,6 +129,7 @@ function initialize(p::Pump) @async while true @periodically p.h begin #normalized venturi + #push!(bc.ar, time()) venturi = (read(p.measure)-p.venturirange[1])/(p.venturirange[2]-p.venturirange[1]) flow = sqrt(max(venturi,0.0)) p.v = p.pid(p.u, flow, (1,1,0)) @@ -161,10 +168,12 @@ end """ -Calibrates the tanks. Sets the pump to max for caltime seconds, during which the flow is measured calpts times. The tank voltage is then measured, when they are presumably full. The pump is then set to min and the flow is again measured calpts time. The tank voltage is then again measured, when they're presumably empty. These values are then used to set the parameters for the DoubleTank measure function and the DoubleTank.pump controller. +Calibrates the tanks. Sets the pump to max for filltime seconds, during which the flow is measured calpts times. The tank voltage is then measured, when they are presumably full. The pump is then set to min for emptytime and the flow is again measured calpts time. The tank voltage is then again measured, when they're presumably empty. These values are then used to set the parameters for the DoubleTank measure function and the DoubleTank.pump controller. """ function calibrate(p::DoubleTank) - caltime = 40 + print("Calibrating...\n") + filltime = 40 + emptytime = 30 calpts = 20 #Override pump control @@ -175,7 +184,7 @@ function calibrate(p::DoubleTank) send(c, 10.0) #just a number > 10 for i in 1:calpts - sleep(caltime/calpts) + sleep(filltime/calpts) measurements[i] = measure(p.pump) end fulltanks = read.(p.measure) @@ -187,7 +196,7 @@ function calibrate(p::DoubleTank) send(c, 0.0) for i in 1:calpts - sleep(caltime/calpts) + sleep(emptytime/calpts) measurements[i] = measure(p.pump) end emptytanks = read.(p.measure) @@ -205,6 +214,7 @@ function calibrate(p::DoubleTank) #Return pump control p.pump.control = c + print("Finished calibration\n") nothing end @@ -214,8 +224,8 @@ end function measure(p::DoubleTank) #This should give an array of two values in the range [0,1] - minv = [p.lowrange[1], p.uprange[1]] - maxv = [p.lowrange[2], p.uprange[2]] + minv = [p.uprange[1], p.lowrange[1]] + maxv = [p.uprange[2], p.lowrange[2]] clamp.((read.(p.measure)-minv)./(maxv-minv), 0.0, 1.0) end diff --git a/src/tankdemo.jl b/src/tankdemo.jl index ae8d0021fea554af32964777c96ece08f8c26509..58787efaf41decd1b6857b920d379bf75a34096c 100644 --- a/src/tankdemo.jl +++ b/src/tankdemo.jl @@ -1,9 +1,9 @@ -using InteractNext, Plots, LabProcesses, LabGUI +using InteractNext, WebIO, Plots, LabProcesses, LabGUI include("tankgraphic.jl") include("DoubleTank.jl") include("tanklabgui.jl") -const simulated = true +const simulated = false const webservice = true #Just for testing diff --git a/src/tanklabgui.jl b/src/tanklabgui.jl index 7804572aa0cb666062231cb8bebaf56fc765760c..48e9cdd9e1d4263fa93cd13a8c16ceba7973d298 100644 --- a/src/tanklabgui.jl +++ b/src/tanklabgui.jl @@ -28,9 +28,14 @@ function makegui(P, plottingframerate = 10, guiframerate = 10) rbox in textbox(" r "), expcsv in button("Export Data") + rv = obs(r)[] if !endswith(rbox, ".") && rbox != "0" try - obs(r).val = parse(Float64, rbox) + #obs(r).val = parse(Float64, rbox) + rv = parse(Float64, rbox) + end + if 0.0<rv<1.0 + obs(r).val = rv end end Node(:div)