Skip to content

Commit 88ac73b

Browse files
committed
generalize ff_controller to accept any system
1 parent 7bab236 commit 88ac73b

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RobustAndOptimalControl"
22
uuid = "21fd56a4-db03-40ee-82ee-a87907bee541"
33
authors = ["Fredrik Bagge Carlson", "Marcus Greiff"]
4-
version = "0.4.44"
4+
version = "0.4.45"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/lqg.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,15 @@ function ControlSystemsBase.observer_controller(l::LQGProblem, L::AbstractMatrix
349349
ss(Ac, Bc, Cc, Dc, l.timeevol)
350350
end
351351

352+
352353
"""
354+
ff_controller(sys, L, K; comp_dc = true)
353355
ff_controller(l::LQGProblem, L = lqr(l), K = kalman(l))
354356
355357
Return the feedforward controller ``C_{ff}`` that maps references to plant inputs:
356358
``u = C_{fb}y + C_{ff}r``
357359
358-
The following should hold
360+
The following should hold for an LQGProblem `l`:
359361
```
360362
Cff = RobustAndOptimalControl.ff_controller(l)
361363
Cfb = observer_controller(l)
@@ -367,21 +369,28 @@ Note, if [`extended_controller`](@ref) is used, the DC-gain compensation above c
367369
368370
See also [`observer_controller`](@ref).
369371
"""
370-
function ff_controller(l::LQGProblem, L = lqr(l), K = kalman(l); comp_dc = true)
371-
Ae,Be,Ce,De = ssdata(system_mapping(l, identity))
372+
function ff_controller(sys::AbstractStateSpace, L, K, Lr = nothing; comp_dc = true)
373+
Ae,Be,Ce,De = ssdata(sys)
372374
Ac = Ae - Be*L - K*Ce + K*De*L # 8.26c
373375
Cc = L
374376
Dc = 0
375377
if comp_dc
376-
Lr = static_gain_compensation(l, L)
378+
if Lr === nothing
379+
Cfb = observer_controller(sys, L, K)
380+
Lr = pinv(dcgain(feedback(sys*Cfb)))
381+
end
377382
Bc = Be*Lr
378-
return Lr - ss(Ac, Bc, Cc, Dc, l.timeevol)
383+
return Lr - ss(Ac, Bc, Cc, Dc, sys.timeevol)
379384
else
380385
Bc = Be
381-
return I(size(Cc, 1)) - ss(Ac, Bc, Cc, Dc, l.timeevol)
386+
return I(size(Cc, 1)) - ss(Ac, Bc, Cc, Dc, sys.timeevol)
382387
end
383388
end
384389

390+
function ff_controller(l::LQGProblem, L = lqr(l), K = kalman(l); kwargs...)
391+
ff_controller(system_mapping(l, identity), L, K, static_gain_compensation(l, L); kwargs...)
392+
end
393+
385394
"""
386395
closedloop(l::LQGProblem, L = lqr(l), K = kalman(l))
387396

0 commit comments

Comments
 (0)