Commit 262fa824 authored by Jacob Wikmark's avatar Jacob Wikmark
Browse files
parents 0c96577f 1ebd5b6c
......@@ -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
......
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
......
......@@ -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)
......
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