@@ -361,43 +361,16 @@ function validate_setpointdist(mpc::PredictiveController, ry, d, R̂y, D̂)
361361 size (D̂) ≠ (nd* Hp,) && error (" D̂ size $(size (D̂)) ≠ measured dist. size × Hp ($(nd* Hp) ,)" )
362362end
363363
364- """
365- getestimates!(mpc::PredictiveController, estim::StateEstimator) -> x̂d, x̂s, ŷ
366-
367- Get estimator output and split `x̂` into the deterministic `x̂d` and stochastic `x̂s` states.
368- """
369- function getestimates! (mpc:: PredictiveController , estim:: StateEstimator , ym , d)
370- nx = estim. model. nx
371- mpc. x̂d[:] = estim. x̂[1 : nx]
372- mpc. x̂s[:] = estim. x̂[nx+ 1 : end ]
373- mpc. ŷ[:] = evalŷ (estim, ym, d)
374- return mpc. x̂d, mpc. x̂s, mpc. ŷ
375- end
376-
377- """
378- getestimates!(mpc::PredictiveController, estim::InternalModel) -> x̂d, x̂s, ŷ
379-
380- Get the internal model deterministic `estim.x̂d` and stochastic `estim.x̂s` states.
381- """
382- function getestimates! (mpc:: PredictiveController , estim:: InternalModel , ym, d)
383- isnothing (ym) && error (" Predictive controllers with InternalModel need the measured " *
384- " outputs ym in keyword argument to compute control actions u" )
385- mpc. x̂d[:] = estim. x̂d
386- mpc. x̂s[:] = estim. x̂s
387- mpc. ŷ[:] = evalŷ (estim, ym, d)
388- return mpc. x̂d, mpc. x̂s, mpc. ŷ
389- end
390-
391364"""
392365 predictstoch!(mpc, estim::InternalModel, x̂s, d, ym )
393366
394367Use current measured outputs `ym` for prediction when `estim` is a [`InternalModel`](@ref).
395368"""
396369function predictstoch! (mpc, estim:: InternalModel , d, ym )
397- ŷd = h (estim. model, mpc . x̂d, d - estim. model. dop) + estim. model. yop
370+ ŷd = h (estim. model, estim . x̂d, d - estim. model. dop) + estim. model. yop
398371 ŷs = zeros (estim. model. ny)
399372 ŷs[estim. i_ym] = ym - ŷd[estim. i_ym] # ŷs=0 for unmeasured outputs
400- mpc. Ŷs[:] = mpc. Ks* mpc. x̂s + mpc. Ps* ŷs
373+ mpc. Ŷs[:] = mpc. Ks* mpc. estim . x̂s + mpc. Ps* ŷs
401374 return mpc. Ŷs
402375end
403376" Separate stochastic predictions are not needed if `estim` is not [`InternalModel`](@ref)."
571544
572545
573546@doc raw """
574- init_deterpred (estim::StateEstimator, ::LinModel, Hp, Hc) -> E, G, J, K, Q
547+ init_predmat (estim::StateEstimator, ::LinModel, Hp, Hc) -> E, G, J, K, Q
575548
576549Construct the prediction matrices for [`LinModel`](@ref) `model`.
577550
@@ -586,8 +559,9 @@ The linear model predictions are evaluated by :
586559where predicted outputs ``\m athbf{Ŷ}``, stochastic outputs ``\m athbf{Ŷ_s}``, and measured
587560disturbances ``\m athbf{D̂}`` are from ``k + 1`` to ``k + H_p``. Input increments
588561``\m athbf{ΔU}`` are from ``k`` to ``k + H_c - 1``. The vector ``\m athbf{x̂}_{k-1}(k)`` is the
589- state estimated at the last control period. Operating points on ``\m athbf{u}``,
590- ``\m athbf{d}`` and ``\m athbf{y}`` are omitted in above equations.
562+ state estimated at the last control period. The stochastic outputs ``\m athbf{Ŷ_s = 0}`` if
563+ `estim` is not a [`InternalModel`](@ref). Operating points on ``\m athbf{u}``, ``\m athbf{d}``
564+ and ``\m athbf{y}`` are omitted in above equations.
591565
592566# Extended Help
593567Using the augmented matrices ``\m athbf{Â, B̂_u, Ĉ, B̂_d, D̂_d}`` in `model` and the equation
@@ -632,7 +606,7 @@ matrices are computed by :
632606\e nd{aligned}
633607```
634608"""
635- function init_deterpred (estim:: StateEstimator , model:: LinModel , Hp, Hc) # TODO : RENAME THE FUNCTION!
609+ function init_predmat (estim:: StateEstimator , model:: LinModel , Hp, Hc)
636610 Â, B̂u, Ĉ, B̂d, D̂d = estim. Â, estim. B̂u, estim. Ĉ, estim. B̂d, estim. D̂d
637611 nu, nx̂, ny, nd = model. nu, estim. nx̂, model. ny, model. nd
638612 # Apow 3D array : Apow[:,:,1] = A^0, Apow[:,:,2] = A^1, ...
@@ -677,7 +651,7 @@ function init_deterpred(estim::StateEstimator, model::LinModel, Hp, Hc) #TODO: R
677651end
678652
679653" Return empty matrices if `model` is not a [`LinModel`](@ref)"
680- function init_deterpred (estim:: StateEstimator , model:: SimModel , Hp, Hc)
654+ function init_predmat (estim:: StateEstimator , model:: SimModel , Hp, Hc)
681655 nu, nx̂, nd = model. nu, estim. nx̂, model. nd
682656 E = zeros (0 , nu* Hc)
683657 G = zeros (0 , nd)
@@ -879,35 +853,6 @@ function relaxŶ(::SimModel, C, c_Ŷmin, c_Ŷmax, E)
879853 return A_Ŷmin, A_Ŷmax, Ẽ
880854end
881855
882- @doc raw """
883- init_stochpred(estim::StateEstimator, Hp) -> Ks, Ps
884-
885- Init the stochastic prediction matrix `Ks` from `estim` estimator for predictive control.
886-
887- ``\m athbf{K_s}`` is the prediction matrix of the stochastic model (composed exclusively of
888- integrators):
889- ```math
890- \m athbf{Ŷ_s} = \m athbf{K_s x̂_s}(k)
891- ```
892- The stochastic predictions ``\m athbf{Ŷ_s}`` are the integrator outputs from ``k+1`` to
893- ``k+H_p``. ``\m athbf{x̂_s}(k)`` is extracted from current estimates ``\m athbf{x̂}_{k-1}(k)``
894- with [`getestimates!`](@ref). The method also returns an empty ``\m athbf{P_s}`` matrix, since
895- it is useless except for [`InternalModel`](@ref) estimators.
896- """
897- function init_stochpred (estim:: StateEstimator , Hp)
898- As, Cs_y = estim. As, estim. Cs_y
899- nxs = estim. nxs
900- Ms = Matrix {Float64} (undef, Hp* nxs, nxs)
901- for i = 1 : Hp
902- iRow = (1 : nxs) .+ nxs* (i- 1 )
903- Ms[iRow, :] = As^ i
904- end
905- Js = repeatdiag (Cs_y, Hp)
906- Ks = Js* Ms
907- Ps = zeros (estim. model. ny* Hp, 0 )
908- return Ks, Ps
909- end
910-
911856@doc raw """
912857 init_stochpred(estim::InternalModel, Hp) -> Ks, Ps
913858
@@ -940,6 +885,9 @@ function init_stochpred(estim::InternalModel, Hp)
940885 end
941886 return Ks, Ps
942887end
888+ " Return empty matrices if `estim` is not a [`InternalModel`](@ref)."
889+ init_stochpred (:: StateEstimator , _ ) = Float64[;;], Float64[;;]
890+
943891
944892@doc raw """
945893 init_linconstraint(model::LinModel,
0 commit comments