diff --git a/REQUIRE b/REQUIRE index 137767a42af4a6bc4e8d823feb3bedec27ee23b2..9ed6efef4f9e6feb03749a321624534cca49d017 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1,2 @@ julia 0.6 +ControlSystems diff --git a/src/controllers.jl b/src/controllers.jl index c9cd61749d7e6086aa4b105170343e8e9ecc3fb3..80b00daacc24e6af7e12dcd95e633f0a79d25ed8 100644 --- a/src/controllers.jl +++ b/src/controllers.jl @@ -8,7 +8,6 @@ Perform control experiemnt where the feedback and feedforward controllers are gi `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_2DOF(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10, reference = t->sign(sin(2π*t))) h = sampletime(P) diff --git a/src/utilities.jl b/src/utilities.jl index 86be3b8488ed97877433c2d52b430795ec582b03..a8cb718cf5dc65090056f3e31fc6e79e606ffae0 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -1,4 +1,4 @@ -export periodically +export periodically, init_sysfilter, sysfilter! """ @periodically(h, body) @@ -12,3 +12,23 @@ macro periodically(h, body) sleep(max(0,$h-execution_time)) end end + +""" + state = init_sysfilter(sys::StateSpace) +Use together with [`sysfilter!`](@ref) +""" +function init_sysfilter(sys::StateSpace) + zeros(sys.nx,1) +end + +""" + output = sysfilter!(state, sys::StateSpace, input) +Returns the filtered output `y` in `y = Cx+Du, x'=Ax+Bu` + +This function is used to implement control loops where a signal is filtered through a +dynamical system, i.e., `U(z) = C(z)E(z)`. Initialize `state` using [`init_sysfilter`](@ref). +""" +function sysfilter!(state, sys::StateSpace, input) + state .= sys.A*state + sys.B*input + output = sys.C*state + sys.D*input +end