# Interface implementation Ball And Beam ==================================================== export BallAndBeam, BallAndBeamSimulator, BallAndBeamType struct BallAndBeam <: PhysicalProcess h::Float64 end BallAndBeam() = BallAndBeam(0.01) struct BallAndBeamSimulator <: SimulatedProcess h::Float64 end BallAndBeamSimulator() = BallAndBeamSimulator(0.01) const BallAndBeamType = Union{BallAndBeam, BallAndBeamSimulator} num_outputs(p::BallAndBeamType) = 2 num_inputs(p::BallAndBeamType) = 1 outputrange(p::BallAndBeamType) = [(-10,10),(-1,1)] # Beam angle, Ball position inputrange(p::BallAndBeamType) = [(-10,10)] isstable(p::BallAndBeamType) = false isasstable(p::BallAndBeamType) = false sampletime(p::BallAndBeamType) = p.h control(p::BallAndBeam, u) = ccall((:comedi_write, comedipath),Int32, (Int32,Int32,Int32,Int32),0,1,1,num2io(u[1])) measure(p::BallAndBeam) = io2num(ccall((:comedi_read,comedipath), Int32, (Int32,Int32,Int32), 0,0,0)) control(p::BallAndBeamSimulator, u) = error("Not yet implemented") 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::BallAndBeam) = ccall((:comedi_start, comedipath),Int32,(Int32,), 0) finalize(p::BallAndBeam) = (control(p,0);ccall((:comedi_stop, comedipath),Int32,(Int32,), 0)) initialize(p::BallAndBeamSimulator) = nothing finalize(p::BallAndBeamSimulator) = nothing