Skip to content

Commit 1a9b1b2

Browse files
committed
simplify partition of NamedSS
1 parent 88375fc commit 1a9b1b2

File tree

3 files changed

+45
-49
lines changed

3 files changed

+45
-49
lines changed

src/hinfinity_design.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,17 @@ function hinfsynthesize(
193193
else
194194
# Return and empty controller, empty gain γ
195195
@warn "No feasible γ found, returning an empty controller. Try increasing the interval from the default `interval = (0, 20)` or change the scaling method using `method = :SVD`"
196-
K = ss(0.0)
196+
K = ss(zeros(P.nu, P.ny))
197197
γ = Inf
198198
end
199199
if hp
200200
bf(x) = T.(x)
201201
mats = bf.(ssdata(K))
202202
K = ss(mats..., K.timeevol)
203203
end
204+
if P.sys isa NamedStateSpace
205+
K = named_ss(K, u=P.y, y=P.u, x=Symbol.("K" .* string.(P.sys.x)))
206+
end
204207
if check
205208
γactual = hinfnorm2(lft(P, K))[1]::T
206209
# NOTE: this check can erroneosly indicate numerical problems if Rtrans21 != 1. This may happen for method = :QR, in which case γactual ≈ γFeasible / Rtrans21

src/named_systems2.jl

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -945,57 +945,50 @@ function named_ss(sys::ExtendedStateSpace{T}, name="";
945945
end
946946

947947

948-
function partition(P::NamedStateSpace; u=nothing, y=nothing,
949-
w = nothing,
950-
z = nothing,
951-
B1 = nothing,
952-
B2 = nothing,
953-
C1 = nothing,
954-
C2 = nothing,
955-
D11 = nothing,
956-
D12 = nothing,
957-
D21 = nothing,
958-
D22 = nothing,
948+
function partition(P::NamedStateSpace; u=Symbol[], y=Symbol[],
949+
w = Symbol[],
950+
z = Symbol[],
951+
# B1 = nothing,
952+
# B2 = nothing,
953+
# C1 = nothing,
954+
# C2 = nothing,
955+
# D11 = nothing,
956+
# D12 = nothing,
957+
# D21 = nothing,
958+
# D22 = nothing,
959959
)
960-
if w === nothing
961-
inds = names2indices(u, P.u)
962-
w = setdiff(1:P.nu, inds)
963-
u = inds
960+
if isempty(w)
961+
w = setdiff(P.u, u)
964962
end
965-
if z === nothing
966-
inds = names2indices(y, P.y)
967-
z = setdiff(1:P.ny, inds)
968-
y = inds
963+
if isempty(z)
964+
z = setdiff(P.y, y)
969965
end
970-
if u === nothing
971-
inds = names2indices(w, P.u)
972-
u = setdiff(1:P.nu, inds)
973-
w = inds
966+
if isempty(u)
967+
u = setdiff(P.u, w)
974968
end
975-
if y === nothing
976-
inds = names2indices(z, P.y)
977-
y = setdiff(1:P.ny, inds)
978-
z = inds
969+
if isempty(y)
970+
y = setdiff(P.y, z)
979971
end
980-
u = names2indices(identity.(u), P.u)
981-
y = names2indices(identity.(y), P.y)
982-
z = names2indices(identity.(z), P.y)
983-
w = names2indices(identity.(w), P.u)
984-
u = vcat(u)
985-
y = vcat(y)
986-
z = vcat(z)
987-
w = vcat(w)
988-
ss(P.A,
989-
B1 === nothing ? P.B[:, w] : B1,
990-
B2 === nothing ? P.B[:, u] : B2,
991-
C1 === nothing ? P.C[z, :] : C1,
992-
C2 === nothing ? P.C[y, :] : C2 ,
993-
D11 === nothing ? P.D[z, w] : D11,
994-
D12 === nothing ? P.D[z, u] : D12,
995-
D21 === nothing ? P.D[y, w] : D21,
996-
D22 === nothing ? P.D[y, u] : D22,
997-
P.timeevol
998-
)
972+
# u = names2indices(identity.(u), P.u)
973+
# y = names2indices(identity.(y), P.y)
974+
# z = names2indices(identity.(z), P.y)
975+
# w = names2indices(identity.(w), P.u)
976+
# u = vcat(u)
977+
# y = vcat(y)
978+
# z = vcat(z)
979+
# w = vcat(w)
980+
# ss(P.A,
981+
# B1 === nothing ? P.B[:, w] : B1,
982+
# B2 === nothing ? P.B[:, u] : B2,
983+
# C1 === nothing ? P.C[z, :] : C1,
984+
# C2 === nothing ? P.C[y, :] : C2 ,
985+
# D11 === nothing ? P.D[z, w] : D11,
986+
# D12 === nothing ? P.D[z, u] : D12,
987+
# D21 === nothing ? P.D[y, w] : D21,
988+
# D22 === nothing ? P.D[y, u] : D22,
989+
# P.timeevol
990+
# )
991+
ExtendedStateSpace(P, w, u, z, y)
999992
end
1000993

1001994
function CS.c2d(s::NamedStateSpace{Continuous}, Ts::Real, method::Symbol = :zoh, args...;

test/test_manual_hinf.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using RobustAndOptimalControl, ControlSystemsBase, Plots
1+
using RobustAndOptimalControl, ControlSystemsBase, Plots, Test
22
P = named_ss(ss(tf(1, [1, 0.1, 1])), :P)
33
We = named_ss(makeweight(10, 1, 0.1), :We, u=:y, y=:e) # We care a lot about the error on low frequencies
44
Wu = named_ss(0.01makeweight(1e-3, 10, 10), :Wu, u=:Wu, y=:uw) # Above ω=100, we want to limit the control effort
@@ -30,7 +30,7 @@ G = connect([P,We,Wu,Wd,sumP,split_u], connections; z1, w1)
3030

3131
Gsyn = partition(G, u = [:u], y = [:y]) # You can provide either u or w, and either y or z
3232
K, γ, info = hinfsynthesize(Gsyn, γrel=1.001, interval = (0.1, 20), transform=false)
33-
33+
@test K.u == [:y]
3434

3535
Gsyn2 = hinfpartition(P, We, Wu, [])
3636
K2, γ2 = hinfsynthesize(Gsyn2, γrel=1.001, interval = (0.1, 20), transform=false)

0 commit comments

Comments
 (0)