Commit 845f8d94 authored by Jacob Wikmark (projekt Fredrik Bagge)'s avatar Jacob Wikmark (projekt Fredrik Bagge)
Browse files

labfixes

parent bf1d3931
...@@ -11,6 +11,12 @@ const venturimax = 14.0 ...@@ -11,6 +11,12 @@ const venturimax = 14.0
using Parameters using Parameters
#struct BC
#ar::Array{Float64, 1}
#end
#bc = BC([])
#Change later #Change later
############################################################ ############################################################
using LabConnections.Computer using LabConnections.Computer
...@@ -107,7 +113,7 @@ function Pump(stream) ...@@ -107,7 +113,7 @@ function Pump(stream)
pid.K = 0.21 pid.K = 0.21
pid.Ti = 0.06 pid.Ti = 0.06
pid.b = 0.0 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)) Pump(pid.h, stream, 0.0, 0.0, pid, [venturimin, venturimax], AnalogInput10V(4), AnalogOutput10V(0))
end end
...@@ -123,6 +129,7 @@ function initialize(p::Pump) ...@@ -123,6 +129,7 @@ function initialize(p::Pump)
@async while true @async while true
@periodically p.h begin @periodically p.h begin
#normalized venturi #normalized venturi
#push!(bc.ar, time())
venturi = (read(p.measure)-p.venturirange[1])/(p.venturirange[2]-p.venturirange[1]) venturi = (read(p.measure)-p.venturirange[1])/(p.venturirange[2]-p.venturirange[1])
flow = sqrt(max(venturi,0.0)) flow = sqrt(max(venturi,0.0))
p.v = p.pid(p.u, flow, (1,1,0)) p.v = p.pid(p.u, flow, (1,1,0))
...@@ -161,10 +168,12 @@ end ...@@ -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) function calibrate(p::DoubleTank)
caltime = 40 print("Calibrating...\n")
filltime = 40
emptytime = 30
calpts = 20 calpts = 20
#Override pump control #Override pump control
...@@ -175,7 +184,7 @@ function calibrate(p::DoubleTank) ...@@ -175,7 +184,7 @@ function calibrate(p::DoubleTank)
send(c, 10.0) #just a number > 10 send(c, 10.0) #just a number > 10
for i in 1:calpts for i in 1:calpts
sleep(caltime/calpts) sleep(filltime/calpts)
measurements[i] = measure(p.pump) measurements[i] = measure(p.pump)
end end
fulltanks = read.(p.measure) fulltanks = read.(p.measure)
...@@ -187,7 +196,7 @@ function calibrate(p::DoubleTank) ...@@ -187,7 +196,7 @@ function calibrate(p::DoubleTank)
send(c, 0.0) send(c, 0.0)
for i in 1:calpts for i in 1:calpts
sleep(caltime/calpts) sleep(emptytime/calpts)
measurements[i] = measure(p.pump) measurements[i] = measure(p.pump)
end end
emptytanks = read.(p.measure) emptytanks = read.(p.measure)
...@@ -205,6 +214,7 @@ function calibrate(p::DoubleTank) ...@@ -205,6 +214,7 @@ function calibrate(p::DoubleTank)
#Return pump control #Return pump control
p.pump.control = c p.pump.control = c
print("Finished calibration\n")
nothing nothing
end end
...@@ -214,8 +224,8 @@ end ...@@ -214,8 +224,8 @@ end
function measure(p::DoubleTank) function measure(p::DoubleTank)
#This should give an array of two values in the range [0,1] #This should give an array of two values in the range [0,1]
minv = [p.lowrange[1], p.uprange[1]] minv = [p.uprange[1], p.lowrange[1]]
maxv = [p.lowrange[2], p.uprange[2]] maxv = [p.uprange[2], p.lowrange[2]]
clamp.((read.(p.measure)-minv)./(maxv-minv), 0.0, 1.0) clamp.((read.(p.measure)-minv)./(maxv-minv), 0.0, 1.0)
end end
......
This diff is collapsed.
using InteractNext, Plots, LabProcesses, LabGUI using InteractNext, WebIO, Plots, LabProcesses, LabGUI
include("tankgraphic.jl") include("tankgraphic.jl")
include("DoubleTank.jl") include("DoubleTank.jl")
include("tanklabgui.jl") include("tanklabgui.jl")
const simulated = true const simulated = false
const webservice = true const webservice = true
#Just for testing #Just for testing
......
...@@ -28,9 +28,14 @@ function makegui(P, plottingframerate = 10, guiframerate = 10) ...@@ -28,9 +28,14 @@ function makegui(P, plottingframerate = 10, guiframerate = 10)
rbox in textbox(" r "), rbox in textbox(" r "),
expcsv in button("Export Data") expcsv in button("Export Data")
rv = obs(r)[]
if !endswith(rbox, ".") && rbox != "0" if !endswith(rbox, ".") && rbox != "0"
try 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
end end
Node(:div) Node(:div)
......
Supports Markdown
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