diff --git a/src/LabProcesses.jl b/src/LabProcesses.jl index b64e23d7139d020b56bfdebaf79e3d92bfcdd355..9cfd41e35cda4745150f288d40adc19e93f49b8a 100644 --- a/src/LabProcesses.jl +++ b/src/LabProcesses.jl @@ -11,6 +11,7 @@ export num_outputs, include("utilities.jl") +include("controllers.jl") # Interface specification =================================================================== abstract type AbstractProcess end @@ -44,7 +45,7 @@ end const BallAndBeamType = Union{BallAndBeam, BallAndBeamSimulator} num_outputs(p::BallAndBeamType) = 2 num_inputs(p::BallAndBeamType) = 1 -outputrange(p::BallAndBeamType) = [(-10,10)] +outputrange(p::BallAndBeamType) = [(-10,10),(-1,1)] # Beam angle, Ball position inputrange(p::BallAndBeamType) = [(-10,10)] isstable(p::BallAndBeamType) = false sampletime(p::BallAndBeamType) = p.h @@ -63,7 +64,7 @@ io2num(x) = x/conversion -10 # Converts from io to float num2io(x) = round(Int32,x*100 + 2050) # Converts from regular number to io initialize(p::BallAndBeam) = ccall((:comedi_start, comedipath),Int32,(Int32,), 0) -finalize(p::BallAndBeam) = ccall((:comedi_stop, "../c/comedi_bridge.so"),Int32,(Int32,), 0) +finalize(p::BallAndBeam) = (control(P,0);ccall((:comedi_stop, "../c/comedi_bridge.so"),Int32,(Int32,), 0)) initialize(p::BallAndBeamSimulator) = nothing finalize(p::BallAndBeamSimulator) = nothing diff --git a/src/controllers.jl b/src/controllers.jl index ec62de6359bac5279120bf6fbe800e24b69d0449..c9cd61749d7e6086aa4b105170343e8e9ecc3fb3 100644 --- a/src/controllers.jl +++ b/src/controllers.jl @@ -1,14 +1,16 @@ +export run_control_2DOF + """ y,u,r = run_control(process, sysFB[, sysFF]; duration = 10, reference(t) = sign(sin(2π*t))) Perform control experiemnt where the feedback and feedforward controllers are given by -`sysFB` and `sysFF`, both of type `StateSpace`. See [`fbdesign`](@ref) [`ffdesign`](@ref). +`sysFB` and `sysFF`, both of type `StateSpace`. `reference` is a reference generating function that accepts a scalar `t` (time in seconds) and outputs a scalar `r`, default is `reference(t) = sign(sin(2π*t))`. The outputs `y,u,r` are the beam angle, control signal and reference respectively. """ -function run_control(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10, reference = t->sign(sin(2π*t))) +function run_control_2DOF(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10, reference = t->sign(sin(2π*t))) h = sampletime(P) y = zeros(0:h:duration) u = zeros(0:h:duration) @@ -36,7 +38,6 @@ function run_control(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10, ref control(P, u[i]) end end - control(P, 0) finalize(P) y,u,r end