@@ -221,3 +221,60 @@ function validate_args(estim::StateEstimator, u, ym, d)
221221 nym = estim. nym
222222 size (ym) ≠ (nym,) && throw (DimensionMismatch (" ym size $(size (ym)) ≠ meas. output size ($nym ,)" ))
223223end
224+
225+ """
226+ setstate!(estim::StateEstimator, x̂)
227+
228+ Set `estim.x̂` states to values specified by `x̂`.
229+ """
230+ function setstate! (estim:: StateEstimator , x̂)
231+ size (x̂) == (estim. nx̂,) || error (" x̂ size must be $((estim. nx̂,)) " )
232+ estim. x̂[:] = x̂
233+ return estim
234+ end
235+
236+ """
237+ setmodel!(estim::StateEstimator, model::LinModel) -> estim
238+
239+ Set `estim.model` state-space matrices and operating points to `model` values.
240+
241+ Not supported by [`Luenberger`](@ref) and [`SteadyKalmanFilter`](@ref) estimators, use the
242+ time-varying [`KalmanFilter`](@ref) instead. The matrix dimensions and sample time must stay
243+ the same. The observability and controllability of the new augmented model is not verified.
244+ """
245+ function setmodel! (estim:: StateEstimator , model:: LinModel )
246+ validate_model (estim, model)
247+ estim. model. A .= model. A
248+ estim. model. Bu .= model. Bu
249+ estim. model. C .= model. C
250+ estim. model. Bd .= model. Bd
251+ estim. model. Dd .= model. Dd
252+ estim. model. uop .= model. uop
253+ estim. model. yop .= model. yop
254+ estim. model. dop .= model. dop
255+ setmodel_estimator! (estim, model)
256+ return estim
257+ end
258+
259+ " Validate the dimensions and sample time of `model` against `estim.model`."
260+ function validate_model (estim:: StateEstimator , model:: LinModel )
261+ model. Ts == estim. model. Ts || throw (ArgumentError (" model.Ts must be $(estim. model. Ts) s" ))
262+ model. nu == estim. model. nu || throw (ArgumentError (" model.nu must be $(estim. model. nu) " ))
263+ model. nx == estim. model. nx || throw (ArgumentError (" model.nx must be $(estim. model. nx) " ))
264+ model. ny == estim. model. ny || throw (ArgumentError (" model.ny must be $(estim. model. ny) " ))
265+ model. nd == estim. model. nd || throw (ArgumentError (" model.nd must be $(estim. model. nd) " ))
266+ end
267+
268+ " Update the augmented model matrices of `estim` by default."
269+ function setmodel_estimator! (estim:: StateEstimator , model:: LinModel )
270+ As, Cs_u, Cs_y = estim. As, estim. Cs_u, estim. Cs_y
271+ Â, B̂u, Ĉ, B̂d, D̂d = augment_model (model, As, Cs_u, Cs_y, verify_obsv= false )
272+ estim. Â .= Â
273+ estim. B̂u .= B̂u
274+ estim. Ĉ .= Ĉ
275+ estim. B̂d .= B̂d
276+ estim. D̂d .= D̂d
277+ estim. Ĉm .= @views Ĉ[estim. i_ym, :]
278+ estim. D̂dm .= @views D̂d[estim. i_ym, :]
279+ return nothing
280+ end
0 commit comments