# @with_kw allows specification of default values for fields. If none is given, this value must be supplied by the user. replaces many constructors that would otherwise only supply default values.
# Call constructor like Beam(bias=1.0) if you want a non-default value for bias
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.
"""
function calibrate(p::DoubleTank)
caltime=40
calpts=20
#Override pump control
c=p.pump.control
p.pump.control=nothing
measurements=zeros(1:calpts,Float64)
send(c,10.0)#just a number > 10
foriin1:calpts
sleep(caltime/calpts)
measurements[i]=measure(p.pump)
end
fulltanks=read.(p.measure)
venturimax=mean(measurements)
print("Upper Full Voltage: $(fulltanks[1])\n")
print("Lower Full Voltage: $(fulltanks[2])\n")
print("Venturi Avg max: $venturimax\n")
send(c,0.0)
foriin1:calpts
sleep(caltime/calpts)
measurements[i]=measure(p.pump)
end
emptytanks=read.(p.measure)
venturimin=mean(measurements)
print("Upper Empty Voltage: $(emptytanks[1])\n")
print("Lower Empty Voltage: $(emptytanks[2])\n")
print("Venturi Avg min: $venturimin\n")
p.uprange[1]=emptytanks[1]
p.uprange[2]=fulltanks[1]
p.lowrange[1]=emptytanks[2]
p.lowrange[2]=fulltanks[2]
p.pump.venturirange=[venturimin,venturimax]
#Return pump control
p.pump.control=c
nothing
end
function measure(p::DoubleTank)
#This should give an array of two values in the range [0,1]