Skip to content

Commit 47f4e58

Browse files
committed
type preserving -
1 parent 3fadfe2 commit 47f4e58

File tree

2 files changed

+53
-18
lines changed

2 files changed

+53
-18
lines changed

src/ExtendedStateSpace.jl

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ function ExtendedStateSpace(
169169
)
170170
end
171171

172+
"""
173+
ExtendedStateSpace(sys::AbstractStateSpace, w, u, z, y)
174+
175+
Create an [`ExtendedStateSpace`](@ref) from an existing state-space system with specified index vectors.
176+
177+
This constructor preserves the type of `sys` (e.g., `NamedStateSpace`).
178+
179+
# Arguments
180+
- `sys`: The underlying state-space system
181+
- `w`: Disturbance input indices (corresponds to B1)
182+
- `u`: Control input indices (corresponds to B2)
183+
- `z`: Performance output indices (corresponds to C1)
184+
- `y`: Measured output indices (corresponds to C2)
185+
"""
186+
function ExtendedStateSpace(sys::S, w::I, u::I, z::I, y::I) where {S<:AbstractStateSpace, I}
187+
TE = typeof(sys.timeevol)
188+
T = ControlSystemsBase.numeric_type(sys)
189+
ExtendedStateSpace{TE, T, S, I}(sys, w, u, z, y)
190+
end
191+
172192
"""
173193
ss(A, B1, B2, C1, C2, D11, D12, D21, D22 [, Ts])
174194
@@ -383,14 +403,29 @@ end
383403

384404
function Base.:*(s1::ExtendedStateSpace, s2::Number)
385405
A, B1, B2, C1, C2, D11, D12, D21, D22 = ssdata_e(s1)
406+
# The reason for only scaling one channel is the use in UncertainSS
386407
ss(A, s2*B1, B2, C1, C2, s2*D11, D12, s2*D21, D22, s1.timeevol)
408+
# ExtendedStateSpace(s1.sys*s2, s1.w, s1.u, s1.z, s1.y)
387409
end
388410

389411
function Base.:*(s2::Number, s1::ExtendedStateSpace)
390412
A, B1, B2, C1, C2, D11, D12, D21, D22 = ssdata_e(s1)
391413
ss(A, B1, B2, s2*C1, C2, s2*D11, s2*D12, D21, D22, s1.timeevol)
414+
# ExtendedStateSpace(s2*s1.sys, s1.w, s1.u, s1.z, s1.y)
392415
end
393416

417+
# function invert_mappings(s::ExtendedStateSpace)
418+
# # Reorder system: inputs [u; w] and outputs [y; z]
419+
# # This swaps the w↔u and z↔y mappings
420+
# (; w,u,z,y) = s
421+
# new_i = [u; w]
422+
# new_o = [y; z]
423+
# ExtendedStateSpace(s.sys, s.u, s.w, s.y, s.z)
424+
# # ExtendedStateSpace(s.sys[new_o, new_i], s.u, s.w, s.y, s.z)
425+
# # ExtendedStateSpace(s.sys[new_o, new_i], s.w, s.u, s.z, s.y)
426+
# end
427+
428+
394429
function invert_mappings(s::ExtendedStateSpace)
395430
A, B1, B2, C1, C2, D11, D12, D21, D22 = ssdata_e(s)
396431
ss(A, B2, B1, C2, C1, D22, D21, D12, D11, s.timeevol)
@@ -409,9 +444,9 @@ end
409444
# end
410445

411446
## NEGATION ##
412-
function Base.:-(sys::ST) where ST <: ExtendedStateSpace
413-
A, B1, B2, C1, C2, D11, D12, D21, D22 = ssdata_e(sys)
414-
ST(A, B1, B2, -C1, -C2, -D11, -D12, -D21, -D22, sys.timeevol)
447+
function Base.:-(sys::ExtendedStateSpace)
448+
# Negating a StateSpace negates C and D matrices, preserving the internal sys type
449+
ExtendedStateSpace(-sys.sys, sys.w, sys.u, sys.z, sys.y)
415450
end
416451

417452
#####################################################################

src/uncertainty_interface.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,21 @@ end
114114

115115
function Base.getproperty(sys::UncertainSS, s::Symbol)
116116
s fieldnames(typeof(sys)) && return getfield(sys, s)
117-
if s === :nz
118-
# return foldl((l, d)->l + size(d, 1), sys.Δ, init=0)
119-
return size(sys.C1, 1)
120-
elseif s === :nw
121-
# return foldl((l, d)->l + size(d, 2), sys.Δ, init=0)
122-
return size(sys.B1, 2)
123-
elseif s === :zinds
124-
return 1:sys.nz
125-
elseif s === :yinds
126-
return sys.nz .+ (1:size(sys.C2, 1))
127-
elseif s === :winds
128-
return 1:sys.nw
129-
elseif s === :uinds
130-
return sys.nw .+ (1:size(sys.B2, 2))
131-
elseif s ===:M
117+
# if s === :nz
118+
# # return foldl((l, d)->l + size(d, 1), sys.Δ, init=0)
119+
# return size(sys.C1, 1)
120+
# elseif s === :nw
121+
# # return foldl((l, d)->l + size(d, 2), sys.Δ, init=0)
122+
# return size(sys.B1, 2)
123+
# elseif s === :zinds
124+
# return 1:sys.nz
125+
# elseif s === :yinds
126+
# return sys.nz .+ (1:size(sys.C2, 1))
127+
# elseif s === :winds
128+
# return 1:sys.nw
129+
# elseif s === :uinds
130+
# return sys.nw .+ (1:size(sys.B2, 2))
131+
if s ===:M
132132
return sminreal(performance_mapping(sys.sys))
133133
# return sys.sys
134134
elseif s ===:delta

0 commit comments

Comments
 (0)