Skip to content

Commit be35ec9

Browse files
authored
Merge pull request #125 from JuliaControl/essups
Add constructor to override matrices in ExtendedStateSpace
2 parents a23715f + bdaedd0 commit be35ec9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/ExtendedStateSpace.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,26 @@ end
633633
_I2mat(M,nx) = M
634634
_I2mat(i::UniformScaling,nx) = i(nx)
635635

636+
"""
637+
ExtendedStateSpace(s::ExtendedStateSpace; A, B1, B2, C1, C2, D11, D12, D21, D22, kwargs...)
638+
639+
Create an [`ExtendedStateSpace`](@ref) from an existing one, with the option to override the matrices.
640+
"""
641+
function ExtendedStateSpace(s::ExtendedStateSpace;
642+
A = s.A,
643+
B1 = s.B1,
644+
B2 = s.B2,
645+
C1 = s.C1,
646+
C2 = s.C2,
647+
D11 = s.D11,
648+
D12 = s.D12,
649+
D21 = s.D21,
650+
D22 = s.D22,
651+
kwargs...
652+
)
653+
ss(A, B1, B2, C1, C2; D11, D12, D21, D22, Ts = s.timeevol, kwargs...)
654+
end
655+
636656
# ```math
637657
# \\begin{bmatrix}
638658
# A & I & B \\\\

src/lqg.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ function LQGProblem(P::ExtendedStateSpace)
179179
end
180180

181181
function ControlSystemsBase.kalman(l::LQGProblem; direct = false)
182-
@unpack A, C2, B1, R1, qR, B2, R2, SR = l
182+
(; A, C2, B1, R1, qR, B2, R2, SR) = l
183183
# We do not apply the transformation D21*R2*D21' since when the user has provided an ESS, R2 == D21*D21', and when the user provides covariance matrices, R2 is provided directly.
184184
K = kalman(l.timeevol, A, C2, Hermitian(B1*R1*B1' + qR * B2 * B2'), R2, SR; direct)
185185
end
186186

187187
function ControlSystemsBase.lqr(l::LQGProblem)
188-
@unpack A, B2, C1, Q1, qQ, C2, Q2, SQ = l
188+
(; A, B2, C1, Q1, qQ, C2, Q2, SQ) = l
189189
L = lqr(l.timeevol, A, B2, Hermitian(C1'Q1*C1 + qQ * C2'C2), Q2, SQ)
190190
end
191191

@@ -292,7 +292,7 @@ system_mapping(Ce) == -C
292292
Please note, without the reference pre-filter, the DC gain from references to controlled outputs may not be identity. If a vector of output indices is provided through the keyword argument `z`, the closed-loop system from state reference `xᵣ` to outputs `z` is returned as a second return argument. The inverse of the DC-gain of this closed-loop system may be useful to compensate for the DC-gain of the controller.
293293
"""
294294
function extended_controller(l::LQGProblem, L::AbstractMatrix = lqr(l), K::AbstractMatrix = kalman(l); z::Union{Nothing, AbstractVector} = nothing)
295-
P = system_mapping(l)
295+
P = system_mapping(l, identity)
296296
A,B,C,D = ssdata(P)
297297
Ac = A - B*L - K*C + K*D*L # 8.26b
298298
(; nx, nu, ny) = P

0 commit comments

Comments
 (0)