|
| 1 | +""" |
| 2 | + ssrand(T::Type, ny::Int, nu::Int, nstates::Int; proper=false, stable=true, Ts=nothing) |
| 3 | +
|
| 4 | +Returns a random `StateSpace` model with `ny` outputs, `nu` inputs, and `nstates` states, |
| 5 | +whose matrix elements are normally distributed. |
| 6 | +
|
| 7 | +It is possible to specify if the system should be `proper` or `stable`. |
| 8 | +
|
| 9 | +Specify a sample time `Ts` to obtain a discrete-time system. |
| 10 | +""" |
| 11 | +function ssrand(T::Type, ny::Int, nu::Int, nstates::Int; proper=false, stable=true, Ts=nothing) |
| 12 | + A = randn(T, nstates, nstates) |
| 13 | + if stable |
| 14 | + Λ = eigvals(A) |
| 15 | + A = isnothing(Ts) ? A - 1.1*maximum(real(Λ))*I : A*0.9/maximum(abs.(Λ)) |
| 16 | + end |
| 17 | + |
| 18 | + B = randn(T, nstates, nu) |
| 19 | + C = randn(T, ny, nstates) |
| 20 | + D = (proper ? zeros(T, ny, nu) : randn(T, ny, nu)) |
| 21 | + return isnothing(Ts) ? StateSpace(A, B, C, D) : StateSpace(A, B, C, D, Ts) |
| 22 | +end |
| 23 | +ssrand(ny::Int, nu::Int, nstates::Int; kwargs...) = ssrand(Float64, ny::Int, nu::Int, nstates::Int; kwargs...) |
| 24 | +ssrand(n; kwargs...) = ssrand(n, n, 2*n; kwargs...) |
| 25 | +ssrand(T::Type, n; kwargs...) = ssrand(T, n, n, 2*n; kwargs...) |
| 26 | + |
| 27 | + |
| 28 | +""" |
| 29 | + systemdepot(sysname::String; Ts=nothing, kwargs...) |
| 30 | +
|
| 31 | +Convenience function for setting up some different systems |
| 32 | +that are commonly used as examples in the control literature. |
| 33 | +
|
| 34 | +Change the default parameter values by using keyword arguments. |
| 35 | +
|
| 36 | +SISO systems |
| 37 | +============ |
| 38 | +1) `fo` First-order system `1/(sT+1)` |
| 39 | +2) `fotd` First-order system with time-delay `exp(-sτ)/(sT+1)` |
| 40 | +3) `sotd` Second-order non-resonant system with time-delay `exp(-sτ)/(sT+1)/(sT2 + 1)` |
| 41 | +4) `resonant` Second-order resonant systems `ω0^2/(s^2 + 2ζ*ω0*s + ω0^2)` |
| 42 | +
|
| 43 | +MIMO systems |
| 44 | +============ |
| 45 | +5) `woodberry` Wood--Berry distillation column |
| 46 | +6) `doylesat` Doyle's spinning body example |
| 47 | +""" |
| 48 | +function systemdepot(sysname::String; Ts=nothing, kwargs...) |
| 49 | + if sysname == "woodberry" # The Wood--Berry distillation column |
| 50 | + sys = woodberry(;kwargs...) |
| 51 | + elseif sysname == "fotd" |
| 52 | + sys = fotd(;kwargs...) |
| 53 | + elseif sysname == "sotd" |
| 54 | + sys = sotd(;kwargs...) |
| 55 | + elseif sysname == "fo" |
| 56 | + sys = first_order_system(;kwargs...) |
| 57 | + elseif sysname == "resonant" |
| 58 | + sys = resonant(;kwargs...) |
| 59 | + elseif sysname == "doylesat" |
| 60 | + sys = doylesat(;kwargs...) |
| 61 | + else |
| 62 | + error("Unknown system name: $sysname") |
| 63 | + end |
| 64 | + |
| 65 | + if isnothing(Ts) |
| 66 | + return sys |
| 67 | + else |
| 68 | + Tsc2d(sys, Ts) |
| 69 | + end |
| 70 | +end |
| 71 | + |
| 72 | +first_order_system(;T=1) = ss(-1/T, 1, 1/T, 0) |
| 73 | +fotd(;T=1, τ=1) = ss(-1/T, 1, 1/T, 0) * delay(τ) |
| 74 | +sotd(;T=1, T2=10, τ=1) = ss(-1/T, 1, 1/T, 0)*ss(-1/T2, 1, 1/T2, 0)*delay(τ) |
| 75 | +resonant(;ω0=1, ζ=0.25) = ss([-ζ -ω0; ω0 -ζ], [ω0; 0], [0 ω0], 0) # QUESTION: Is this the form that we like? Perhhaps not. |
| 76 | + |
| 77 | + |
| 78 | +""" |
| 79 | +Doyle's spinning body (satellite) example |
| 80 | +====================== |
| 81 | +A classic example that illustrates that robustness analysis of MIMO systems |
| 82 | +is more involved than for SISO systems. |
| 83 | +
|
| 84 | +*References:* |
| 85 | +
|
| 86 | +**Zhou, K., J. C. Doyle, and K. Glover**, Robust and optimal control, |
| 87 | +Prentice hall (NJ), 1996. |
| 88 | +
|
| 89 | +**Skogestad, S, and I. Postlethwaite**, Multivariable feedback control: |
| 90 | +analysis and design, Wiley (NY), 2007. |
| 91 | +""" |
| 92 | +doylesat(;a=10) = ss([0 a; -a 0], I(2), [1 a; -a 1], 0) |
| 93 | + |
| 94 | + |
| 95 | +""" |
| 96 | +Wood--Berry distillation column |
| 97 | +====================== |
| 98 | +A classic example from the literature on process control of MIMO process. |
| 99 | +
|
| 100 | +*References:* |
| 101 | +
|
| 102 | +**Wood, R. K., and M. W. Berry**, Terminal composition control of a binary |
| 103 | +distillation column, Chemical Engineering Science, 28.9, 1973, pp. 1707-1717. |
| 104 | +
|
| 105 | +""" |
| 106 | +function woodberry() |
| 107 | + s = tf("s") |
| 108 | + return [12.8/(1 + 16.7*s)*delay(1.0) -18.9/(1 + 21*s) * delay(3.0) |
| 109 | + 6.6/(1 + 10.9*s) * delay(7.0) -19.4/(1 + 14.4*s) * delay(3.0)] |
| 110 | +end |
0 commit comments