From 13f51edaf86d0e37af0efd10d703c48e2ed83873 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Tue, 13 Sep 2022 13:17:46 +0200 Subject: [PATCH 1/4] update docstring formatting --- src/glover_mcfarlane.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/glover_mcfarlane.jl b/src/glover_mcfarlane.jl index 5580644b..9e4a6934 100644 --- a/src/glover_mcfarlane.jl +++ b/src/glover_mcfarlane.jl @@ -68,12 +68,11 @@ Skogestad gives the following general advice: of methods available including normalization with respect to the magnitude of the maximum or average value of the signal in question. If one is to go straight to a design the following variation has proved useful in practice: - (a) The outputs are scaled such that equal magnitudes of cross-coupling into each + - The outputs are scaled such that equal magnitudes of cross-coupling into each of the outputs is equally undesirable. - (b) Each input is scaled by a given percentage (say 10%) of its expected range + - Each input is scaled by a given percentage (say 10%) of its expected range of operation. That is, the inputs are scaled to reflect the relative actuator - capabilities. An example of this type of scaling is given in the aero-engine - case study of Chapter 12. + capabilities. 2. Order the inputs and outputs so that the plant is as diagonal as possible. The relative gain array [`rga`](@ref) can be useful here. The purpose of this pseudo-diagonalization is to ease the design of the pre- and post-compensators which, for simplicity, will From 0986331cc159dc5e43e466f9560665d7f071d592 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Wed, 14 Sep 2022 15:22:17 +0200 Subject: [PATCH 2/4] fix noncommutative multiplication of named system with scalar --- src/named_systems2.jl | 11 ++++++++++- test/test_named_systems2.jl | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/named_systems2.jl b/src/named_systems2.jl index d59f17b9..593d0dd1 100644 --- a/src/named_systems2.jl +++ b/src/named_systems2.jl @@ -252,8 +252,17 @@ function Base.:*(s1::Number, s2::NamedStateSpace{T, S}) where {T <: CS.TimeEvolu ) end +function Base.:*(s1::NamedStateSpace{T, S}, s2::Number) where {T <: CS.TimeEvolution, S} + return NamedStateSpace{T,S}( + s1.sys*s2, + s1.x, + [Symbol(string(u)*"_scaled") for u in s1.u], + s1.y, + ) +end + function Base.:/(s::NamedStateSpace{T, S}, n::Number) where {T <: CS.TimeEvolution, S} - (1/n)*s + s*(1/n) end ## diff --git a/test/test_named_systems2.jl b/test/test_named_systems2.jl index c19fb83c..cc20cbb3 100644 --- a/test/test_named_systems2.jl +++ b/test/test_named_systems2.jl @@ -77,11 +77,18 @@ s2 = named_ss(G2, x = [:z], u = [:u2], y=[:y2]) @test s12.C == G12.C @test s12.D == G12.D - G3 = 2*G2 - @test ss(G3) == 2*ss(G2) - - G3 = G2/2.0 - @test ss(G3) == ss(G2)/2.0 + G3 = 2*s2 + @test ss(G3) == 2*ss(s2) + @test G3.u == s2.u + @test G3.y != s2.y + + G3 = s2*2 + @test ss(G3) == ss(s2)*2 + @test G3.u != s2.u + @test G3.y == s2.y + + G3 = s2/2.0 + @test ss(G3) == ss(s2)/2.0 @test_throws ArgumentError s1*s1 end From 161a7dafd0cef8aa44f471a1dc1badfa1ee77c05 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Wed, 14 Sep 2022 15:23:00 +0200 Subject: [PATCH 3/4] improve some docstrings and error messages --- src/named_systems2.jl | 6 ++++-- src/reduction.jl | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/named_systems2.jl b/src/named_systems2.jl index 593d0dd1..af049207 100644 --- a/src/named_systems2.jl +++ b/src/named_systems2.jl @@ -363,6 +363,8 @@ Addition and subtraction nodes are achieved by creating a linear combination nod - `z1`: outputs (can overlap with `y1`) - `verbose`: Issue warnings for signals that have no connection +Note: Positive feedback is used, controllers that are intended to be connected with negative feedback must thus be negated. + Example: The following complicated feedback interconnection @@ -413,9 +415,9 @@ function connect(systems; u1::Vector{Symbol}, y1::Vector{Symbol}, w1::Vector{Sym if verbose leftover_inputs = setdiff(full.u, [u1; w1]) - isempty(leftover_inputs) || @warn("The following inputs were unconnected $leftover_inputs") + isempty(leftover_inputs) || @warn("The following inputs were unconnected $leftover_inputs, ignore this warning if you rely on prefix matching") leftover_outputs = setdiff(full.y, z1 == (:) ? y1 : [y1; z1]) - isempty(leftover_outputs) || @warn("The following outputs were unconnected $leftover_outputs") + isempty(leftover_outputs) || @warn("The following outputs were unconnected $leftover_outputs, ignore this warning if you rely on prefix matching") end diff --git a/src/reduction.jl b/src/reduction.jl index ea22e593..e36f0d25 100644 --- a/src/reduction.jl +++ b/src/reduction.jl @@ -1,7 +1,7 @@ using ControlSystemsBase: ssdata """ - sysr, hs = frequency_weighted_reduction(G, Wo, Wi; residual=true) + sysr, hs = frequency_weighted_reduction(G, Wo, Wi, r=nothing; residual=true) Find Gr such that ||Wₒ(G-Gr)Wᵢ||∞ is minimized. For a realtive reduction, set Wo = inv(G) and Wi = I. @@ -16,6 +16,19 @@ Ref: Andras Varga and Brian D.O. Anderson, "Accuracy enhancing methods for the f https://elib.dlr.de/11746/1/varga_cdc01p2.pdf Note: This function only handles exponentially stable models. To reduce unstable and marginally stable models, decompose the system into stable and unstable parts using [`stab_unstab`](@ref), reduce the stable part and then add the unstable part back. + +# Example: +The following example performs reduction with a frequency focus between frequencies `w1` and `w2`. +```julia +using DSP +w1 = 1e-4 +w2 = 1e-1 +wmax = 1 +fc = DSP.analogfilter(DSP.Bandpass(w1, w2, fs=wmax), DSP.Butterworth(2)) +tfc = DSP.PolynomialRatio(fc) +W = tf(DSP.coefb(tfc), DSP.coefa(tfc)) +rsys, hs = frequency_weighted_reduction(sys, W, 1) +``` """ function frequency_weighted_reduction(G, Wo, Wi, r=nothing; residual=true, atol=sqrt(eps()), rtol=1e-3) iscontinuous(G) || error("Discrete systems not supported yet.") From f651fddf3083993b626fdf0685f4dc4b5e539e2a Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Wed, 14 Sep 2022 15:23:12 +0200 Subject: [PATCH 4/4] extend additional methods for named ss --- src/named_systems2.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/named_systems2.jl b/src/named_systems2.jl index af049207..7413a095 100644 --- a/src/named_systems2.jl +++ b/src/named_systems2.jl @@ -668,4 +668,11 @@ for fun in [:baltrunc, :balreal] msys, rest... = CS.$(fun)(sys.sys, args...; kwargs...) named_ss(msys; sys.u, sys.y), rest... end +end + +for fun in [:baltrunc2, :baltrunc_coprime] + @eval function $(fun)(sys::NamedStateSpace, args...; kwargs...) + msys, rest... = $(fun)(sys.sys, args...; kwargs...) + named_ss(msys; sys.u, sys.y), rest... + end end \ No newline at end of file