diff --git a/REQUIRE b/REQUIRE index 9ed6efef4f9e6feb03749a321624534cca49d017..d5abd45daaab624c5b1cb14ccb404f76c0e1b6d6 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,3 @@ julia 0.6 ControlSystems +Parameters diff --git a/src/LabProcesses.jl b/src/LabProcesses.jl index fe1fd4492ed21c7cb927c0319afd1a5a0fcc111b..ed82dd2dc4c2c6da2bec510b13ef303199dbb0d6 100644 --- a/src/LabProcesses.jl +++ b/src/LabProcesses.jl @@ -7,7 +7,7 @@ end module LabProcesses -using ControlSystems, LabConnection.Computer +using ControlSystems, LabConnection.Computer, Parameters include("utilities.jl") diff --git a/src/interface_implementations/ballandbeam.jl b/src/interface_implementations/ballandbeam.jl index 5681bc8e6a27d2a7ebc15787dcb448f43f4319c4..db014af26b1858f5769459e5722bf9bbe1a5dbcd 100644 --- a/src/interface_implementations/ballandbeam.jl +++ b/src/interface_implementations/ballandbeam.jl @@ -11,11 +11,13 @@ export Beam, BeamSimulator, AbstractBeam, BallAndBeam, BallAndBeamSimulator, AbstractBeamOrBallAndBeam -struct Beam <: PhysicalProcess - h::Float64 - bias::Float64 +@with_kw struct Beam <: PhysicalProcess + h::Float64 = 0.01 + bias::Float64 = 0.0 + stream::LabStream = ComediStream() + measure::AnalogInput10V = AnalogInput10V(0) + control::AnalogOutput10V = AnalogOutput10V(1) end -Beam() = Beam(0.01, 0.0) include("define_beam_system.jl") const beam_system, nice_beam_controller = define_beam_system() @@ -27,24 +29,24 @@ struct BeamSimulator <: SimulatedProcess BeamSimulator(h::Real) = new(Float64(h), SysFilter(beam_system, h)) end -struct BallAndBeam <: PhysicalProcess - h::Float64 - bias::Float64 +@with_kw struct BallAndBeam <: PhysicalProcess + h::Float64 = 0.01 + bias::Float64 = 0.0 + stream::LabStream = ComediStream() + measure1::AnalogInput10V = AnalogInput10V(0) + measure2::AnalogInput10V = AnalogInput10V(1) + control::AnalogOutput10V = AnalogOutput10V(0) end -BallAndBeam() = BallAndBeam(0.01, 0.0) struct BallAndBeamSimulator <: SimulatedProcess h::Float64 s::SysFilter end - - const AbstractBeam = Union{Beam, BeamSimulator} const AbstractBallAndBeam = Union{BallAndBeam, BallAndBeamSimulator} const AbstractBeamOrBallAndBeam = Union{AbstractBeam, AbstractBallAndBeam} - num_outputs(p::AbstractBeam) = 1 num_outputs(p::AbstractBallAndBeam) = 2 num_inputs(p::AbstractBeamOrBallAndBeam) = 1 @@ -60,30 +62,21 @@ bias(p::BeamSimulator) = 0 bias(p::BallAndBeamSimulator) = 0 -control(p::AbstractBeamOrBallAndBeam, u) = ccall((:comedi_write, comedipath),Int32, - (Int32,Int32,Int32,Int32),0,1,1,num2io(u[1]+p.bias)) - -control(p::BeamSimulator, u) = p.s(u) - -control(p::BallAndBeamSimulator, u) = error("Not yet implemented") - -measure(p::Beam) = io2num(ccall((:comedi_read,comedipath), Int32, - (Int32,Int32,Int32), 0,0,0)) -measure(p::BallAndBeam) = [io2num(ccall((:comedi_read,comedipath), Int32, -(Int32,Int32,Int32), 0,0,i)) for i = 0:1] - -measure(p::BeamSimulator) = vecdot(p.s.sys.C,p.s.state) -measure(p::BallAndBeamSimulator) = error("Not yet implemented") +control(p::AbstractBeamOrBallAndBeam, u) = send(p.control,u) +control(p::BeamSimulator, u) = p.s(u) +control(p::BallAndBeamSimulator, u) = error("Not yet implemented") +measure(p::Beam) = read(p.measure) +measure(p::BallAndBeam) = [read(p.measure1), read(p.measure2)] +measure(p::BeamSimulator) = vecdot(p.s.sys.C,p.s.state) +measure(p::BallAndBeamSimulator) = error("Not yet implemented") -const comedipath = Pkg.dir("LabProcesses","c","comedi_bridge.so") -const conversion = 65535/20 -io2num(x) = x/conversion -10 # Converts from io to float -num2io(x) = round(Int32,x*100 + 2048) # Converts from regular number to io -initialize(p::AbstractBeamOrBallAndBeam) = ccall((:comedi_start, comedipath),Int32,(Int32,), 0) -finalize(p::AbstractBeamOrBallAndBeam) = (control(p,0);ccall((:comedi_stop, comedipath),Int32,(Int32,), 0)) -initialize(p::BallAndBeamSimulator) = nothing -finalize(p::BallAndBeamSimulator) = nothing -initialize(p::BeamSimulator) = p.s.state .*= 0 -finalize(p::BeamSimulator) = nothing +initialize(p::Beam) = init_devices!(p.stream, p.measure, p.control) +initialize(p::BallAndBeam) = init_devices!(p.stream, p.measure1, + p.measure2, p.control) +finalize(p::AbstractBeamOrBallAndBeam) = close(p.stream) +initialize(p::BallAndBeamSimulator) = nothing +finalize(p::BallAndBeamSimulator) = nothing +initialize(p::BeamSimulator) = p.s.state .*= 0 +finalize(p::BeamSimulator) = nothing