Skip to content
Snippets Groups Projects
Commit 7144dbc5 authored by Fredrik Bagge Carlson's avatar Fredrik Bagge Carlson
Browse files

Implement LabConnection for ballandbeam

parent b8b24b14
No related branches found
No related tags found
No related merge requests found
julia 0.6 julia 0.6
ControlSystems ControlSystems
Parameters
...@@ -7,7 +7,7 @@ end ...@@ -7,7 +7,7 @@ end
module LabProcesses module LabProcesses
using ControlSystems, LabConnection.Computer using ControlSystems, LabConnection.Computer, Parameters
include("utilities.jl") include("utilities.jl")
......
...@@ -11,11 +11,13 @@ ...@@ -11,11 +11,13 @@
export Beam, BeamSimulator, AbstractBeam, BallAndBeam, BallAndBeamSimulator, AbstractBeamOrBallAndBeam export Beam, BeamSimulator, AbstractBeam, BallAndBeam, BallAndBeamSimulator, AbstractBeamOrBallAndBeam
struct Beam <: PhysicalProcess @with_kw struct Beam <: PhysicalProcess
h::Float64 h::Float64 = 0.01
bias::Float64 bias::Float64 = 0.0
stream::LabStream = ComediStream()
measure::AnalogInput10V = AnalogInput10V(0)
control::AnalogOutput10V = AnalogOutput10V(1)
end end
Beam() = Beam(0.01, 0.0)
include("define_beam_system.jl") include("define_beam_system.jl")
const beam_system, nice_beam_controller = define_beam_system() const beam_system, nice_beam_controller = define_beam_system()
...@@ -27,24 +29,24 @@ struct BeamSimulator <: SimulatedProcess ...@@ -27,24 +29,24 @@ struct BeamSimulator <: SimulatedProcess
BeamSimulator(h::Real) = new(Float64(h), SysFilter(beam_system, h)) BeamSimulator(h::Real) = new(Float64(h), SysFilter(beam_system, h))
end end
struct BallAndBeam <: PhysicalProcess @with_kw struct BallAndBeam <: PhysicalProcess
h::Float64 h::Float64 = 0.01
bias::Float64 bias::Float64 = 0.0
stream::LabStream = ComediStream()
measure1::AnalogInput10V = AnalogInput10V(0)
measure2::AnalogInput10V = AnalogInput10V(1)
control::AnalogOutput10V = AnalogOutput10V(0)
end end
BallAndBeam() = BallAndBeam(0.01, 0.0)
struct BallAndBeamSimulator <: SimulatedProcess struct BallAndBeamSimulator <: SimulatedProcess
h::Float64 h::Float64
s::SysFilter s::SysFilter
end end
const AbstractBeam = Union{Beam, BeamSimulator} const AbstractBeam = Union{Beam, BeamSimulator}
const AbstractBallAndBeam = Union{BallAndBeam, BallAndBeamSimulator} const AbstractBallAndBeam = Union{BallAndBeam, BallAndBeamSimulator}
const AbstractBeamOrBallAndBeam = Union{AbstractBeam, AbstractBallAndBeam} const AbstractBeamOrBallAndBeam = Union{AbstractBeam, AbstractBallAndBeam}
num_outputs(p::AbstractBeam) = 1 num_outputs(p::AbstractBeam) = 1
num_outputs(p::AbstractBallAndBeam) = 2 num_outputs(p::AbstractBallAndBeam) = 2
num_inputs(p::AbstractBeamOrBallAndBeam) = 1 num_inputs(p::AbstractBeamOrBallAndBeam) = 1
...@@ -60,29 +62,20 @@ bias(p::BeamSimulator) = 0 ...@@ -60,29 +62,20 @@ bias(p::BeamSimulator) = 0
bias(p::BallAndBeamSimulator) = 0 bias(p::BallAndBeamSimulator) = 0
control(p::AbstractBeamOrBallAndBeam, u) = ccall((:comedi_write, comedipath),Int32, control(p::AbstractBeamOrBallAndBeam, u) = send(p.control,u)
(Int32,Int32,Int32,Int32),0,1,1,num2io(u[1]+p.bias))
control(p::BeamSimulator, u) = p.s(u) control(p::BeamSimulator, u) = p.s(u)
control(p::BallAndBeamSimulator, u) = error("Not yet implemented") control(p::BallAndBeamSimulator, u) = error("Not yet implemented")
measure(p::Beam) = io2num(ccall((:comedi_read,comedipath), Int32, measure(p::Beam) = read(p.measure)
(Int32,Int32,Int32), 0,0,0)) measure(p::BallAndBeam) = [read(p.measure1), read(p.measure2)]
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::BeamSimulator) = vecdot(p.s.sys.C,p.s.state)
measure(p::BallAndBeamSimulator) = error("Not yet implemented") measure(p::BallAndBeamSimulator) = error("Not yet implemented")
const comedipath = Pkg.dir("LabProcesses","c","comedi_bridge.so") initialize(p::Beam) = init_devices!(p.stream, p.measure, p.control)
const conversion = 65535/20 initialize(p::BallAndBeam) = init_devices!(p.stream, p.measure1,
io2num(x) = x/conversion -10 # Converts from io to float p.measure2, p.control)
num2io(x) = round(Int32,x*100 + 2048) # Converts from regular number to io finalize(p::AbstractBeamOrBallAndBeam) = close(p.stream)
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 initialize(p::BallAndBeamSimulator) = nothing
finalize(p::BallAndBeamSimulator) = nothing finalize(p::BallAndBeamSimulator) = nothing
initialize(p::BeamSimulator) = p.s.state .*= 0 initialize(p::BeamSimulator) = p.s.state .*= 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment