Skip to content

Commit 318c5d6

Browse files
committed
multiple dispatch on SimModels for initstate!
1 parent fc4f647 commit 318c5d6

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/estimator/internal_model.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ The deterministic state `estim.x̂d` initialization method is identical to
167167
"""
168168
function initstate!(estim::InternalModel, u, ym, d=Float64[])
169169
model = estim.model
170-
x̂d = isa(model, LinModel) ? steadystate(model, u, d) : estim.x̂[1:model.nx]
170+
x̂d = init_deterstate(model, estim, u, d)
171171
estim.x̂d[:] = x̂d
172172
# TODO: best method to initialize internal model stochastic states ? not sure...
173173
estim.x̂s[:] = zeros(estim.nxs)

src/predictive_control.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ function write_info!(mpc::LinMPC, ΔŨ, J, ŷs, Ŷs, lastu, F, ym, d)
849849
mpc.info.= mpc.*ΔŨ + F
850850
mpc.info.ŷs, mpc.info.Ŷs = ŷs, Ŷs
851851
end
852+
852853
"Evaluate current output of `InternalModel` estimator."
853854
eval_ŷ(estim::InternalModel, ym, d) = estim(ym, d)
854855
"Evaluate current output of the other `StateEstimator`s."

src/state_estim.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ f̂
207207
function initstate!(estim::StateEstimator, u, ym, d=Float64[])
208208
model = estim.model
209209
# --- deterministic model states ---
210-
x̂d = isa(model, LinModel) ? steadystate(model, u, d) : estim.x̂[1:model.nx]
210+
x̂d = init_deterstate(model, estim, u, d)
211211
# --- stochastic model states (integrators) ---
212212
ŷd = model.h(x̂d, d - model.dop) + model.yop
213213
ŷsm = ym - ŷd[estim.i_ym]
@@ -221,6 +221,11 @@ function initstate!(estim::StateEstimator, u, ym, d=Float64[])
221221
return estim.
222222
end
223223

224+
"Init deterministic state `x̂d` with steady-state value for `LinModel`."
225+
init_deterstate(model::LinModel, _ , u, d) = steadystate(model, u, d)
226+
"Keep current deterministic state unchanged for `NonLinModel`."
227+
init_deterstate(model::SimModel, estim, _, _) = estim.x̂[1:model.nx]
228+
224229
@doc raw"""
225230
evaloutput(estim::StateEstimator, d=Float64[])
226231

0 commit comments

Comments
 (0)