Skip to content

Commit a2b5d53

Browse files
committed
generalize also extended controller
1 parent 88ac73b commit a2b5d53

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/lqg.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ function extended_controller(K::AbstractStateSpace)
271271
end
272272

273273
"""
274+
extended_controller(P::StateSpace, L, K; z = nothing)
274275
extended_controller(l::LQGProblem, L = lqr(l), K = kalman(l); z = nothing)
275276
276277
Returns a statespace system representing the controller that is obtained when state-feedback `u = L(xᵣ-x̂)` is combined with a Kalman filter with gain `K` that produces state estimates x̂. The controller is an instance of `ExtendedStateSpace` where `C2 = -L, D21 = L` and `B2 = K`.
@@ -291,8 +292,7 @@ system_mapping(Ce) == -C
291292
292293
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.
293294
"""
294-
function extended_controller(l::LQGProblem, L::AbstractMatrix = lqr(l), K::AbstractMatrix = kalman(l); z::Union{Nothing, AbstractVector} = nothing)
295-
P = system_mapping(l, identity)
295+
function extended_controller(P::AbstractStateSpace, L::AbstractMatrix, K::AbstractMatrix; z::Union{Nothing, AbstractVector} = nothing)
296296
A,B,C,D = ssdata(P)
297297
Ac = A - B*L - K*C + K*D*L # 8.26b
298298
(; nx, nu, ny) = P
@@ -302,7 +302,7 @@ function extended_controller(l::LQGProblem, L::AbstractMatrix = lqr(l), K::Abstr
302302
D21 = L # L*xᵣ # should be D21?
303303
C2 = -L # - L*x̂
304304
C1 = zeros(0, nx)
305-
Ce0 = ss(Ac, B1, B2, C1, C2; D21, Ts = l.timeevol)
305+
Ce0 = ss(Ac, B1, B2, C1, C2; D21, Ts = P.timeevol)
306306
if z === nothing
307307
return Ce0
308308
end
@@ -313,6 +313,11 @@ function extended_controller(l::LQGProblem, L::AbstractMatrix = lqr(l), K::Abstr
313313
end
314314

315315

316+
function extended_controller(l::LQGProblem, L::AbstractMatrix = lqr(l), K::AbstractMatrix = kalman(l); kwargs...)
317+
P = system_mapping(l, identity)
318+
extended_controller(P, L, K; kwargs...)
319+
end
320+
316321
"""
317322
observer_controller(l::LQGProblem, L = lqr(l), K = kalman(l))
318323
@@ -377,7 +382,8 @@ function ff_controller(sys::AbstractStateSpace, L, K, Lr = nothing; comp_dc = tr
377382
if comp_dc
378383
if Lr === nothing
379384
Cfb = observer_controller(sys, L, K)
380-
Lr = pinv(dcgain(feedback(sys*Cfb)))
385+
Cff0 = ss(I(sys.nu), sys.timeevol) - ss(Ac, Be, Cc, Dc, sys.timeevol)
386+
Lr = pinv(dcgain(feedback(sys, Cfb)*Cff0))
381387
end
382388
Bc = Be*Lr
383389
return Lr - ss(Ac, Bc, Cc, Dc, sys.timeevol)

0 commit comments

Comments
 (0)