Skip to content

Commit 0a769ec

Browse files
committed
added support for integrating LinModel in initstate!
1 parent e3a871f commit 0a769ec

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"mathrm",
3737
"moveinput",
3838
"OSQP",
39+
"Penrose",
3940
"Plamondon",
4041
"quadprog",
4142
"repeatdiag",

src/sim_model.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ Omitting the operating points, the method evaluates the equilibrium ``\mathbf{x}
214214
\mathbf{x}(∞) = \mathbf{(I - A)^{-1}(B_u u + B_d d)}
215215
```
216216
with the manipulated inputs held constant at ``\mathbf{u}`` and, the measured disturbances,
217-
at ``\mathbf{d}``.
217+
at ``\mathbf{d}``. The Moore-Penrose pseudo-inverse evaluates ``\mathbf{(I - A)^{-1}``
218+
to support integrating `model` (integrator states will be 0).
218219
"""
219220
function steadystate(model::LinModel, u, d=Float64[])
220-
return (I - model.A) \ (model.Bu*(u - model.uop) + model.Bd*(d - model.dop))
221+
return pinv(I - model.A)*(model.Bu*(u - model.uop) + model.Bd*(d - model.dop))
221222
end
222223

223224

src/state_estim.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ Init `estim.x̂` states from current inputs `u`, measured outputs `ym` and distu
170170
171171
The method tries to find a good steady-state to initialize `estim.x̂` estimate :
172172
173-
- If `estim.model` is a non-integrating [`LinModel`](@ref), it evaluates `estim.model`
174-
steady-state with current inputs `u` and measured disturbances `d`, and saves the result
175-
to `estim.x̂[1:nx].`
173+
- If `estim.model` is a [`LinModel`](@ref), it evaluates `estim.model` steady-state with
174+
current inputs `u` and measured disturbances `d`, and saves the result to `estim.x̂[1:nx].`
176175
- Else, the current deterministic states `estim.x̂[1:nx]` are left unchanged (use
177176
[`setstate!`](@ref) to manually modify them).
178177
@@ -198,7 +197,7 @@ function initstate!(estim::StateEstimator, u, ym, d=Float64[])
198197
model = estim.model
199198
# --- deterministic model states ---
200199
x̂d = estim.x̂[1:model.nx]
201-
if isa(model, LinModel) && !any(abs.(eigvals(model.A)) .≈ 1)# non-integrating model only
200+
if isa(model, LinModel)
202201
# init deterministic state with steady-states at current input and disturbance :
203202
x̂d = steadystate(model, u, d)
204203
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ DocMeta.setdocmeta!(
2222
doctest(ModelPredictiveControl, testset="DocTest")
2323

2424

25-
end;
25+
end

0 commit comments

Comments
 (0)