@@ -115,7 +115,7 @@ function getinfo(estim::MovingHorizonEstimator{NT}) where NT<:Real
115115 info = Dict {Symbol, Any} ()
116116 V̂, X̂0 = similar (estim. Y0m[1 : nym* Nk]), similar (estim. X̂0[1 : nx̂* Nk])
117117 û0, k0, ŷ0 = buffer. û, buffer. k, buffer. ŷ
118- V̂, X̂0 = predict ! (V̂, X̂0, û0, k0, ŷ0, estim, model, estim. Z̃)
118+ V̂, X̂0 = predict_mhe ! (V̂, X̂0, û0, k0, ŷ0, estim, model, estim. Z̃)
119119 x̂0arr = @views estim. Z̃[nx̃- nx̂+ 1 : nx̃]
120120 x̄ = estim. x̂0arr_old - x̂0arr
121121 X̂0 = [x̂0arr; X̂0]
@@ -418,7 +418,7 @@ function optim_objective!(estim::MovingHorizonEstimator{NT}) where NT<:Real
418418 # --------- update estimate -----------------------
419419 û0, ŷ0, k0 = buffer. û, buffer. ŷ, buffer. k
420420 estim. Ŵ[1 : nŵ* Nk] .= @views estim. Z̃[nx̃+ 1 : nx̃+ nŵ* Nk] # update Ŵ with optimum for warm-start
421- V̂, X̂0 = predict ! (V̂, X̂0, û0, k0, ŷ0, estim, model, estim. Z̃)
421+ V̂, X̂0 = predict_mhe ! (V̂, X̂0, û0, k0, ŷ0, estim, model, estim. Z̃)
422422 x̂0next = @views X̂0[end - nx̂+ 1 : end ]
423423 estim. x̂0 .= x̂0next
424424 return estim. Z̃
@@ -461,7 +461,7 @@ function set_warmstart_mhe!(V̂, X̂0, estim::MovingHorizonEstimator{NT}, Z̃var
461461 # --- process noise estimates Ŵ ---
462462 Z̃s[nx̃+ 1 : end ] = estim. Ŵ
463463 # verify definiteness of objective function:
464- V̂, X̂0 = predict ! (V̂, X̂0, û0, k0, ŷ0, estim, model, Z̃s)
464+ V̂, X̂0 = predict_mhe ! (V̂, X̂0, û0, k0, ŷ0, estim, model, Z̃s)
465465 Js = obj_nonlinprog! (x̄, estim, model, V̂, Z̃s)
466466 if ! isfinite (Js)
467467 Z̃s[nx̃+ 1 : end ] = 0
@@ -578,16 +578,22 @@ function obj_nonlinprog!(
578578 return dot (x̄, invP̄, x̄) + dot (Ŵ, invQ̂_Nk, Ŵ) + dot (V̂, invR̂_Nk, V̂) + Jϵ
579579end
580580
581- """
582- predict !(V̂, X̂0, û0, k0, ŷ0 , estim::MovingHorizonEstimator, model::LinModel, Z̃) -> V̂, X̂0
581+ @doc raw """
582+ predict_mhe !(V̂, X̂0, _, _, _ , estim::MovingHorizonEstimator, model::LinModel, Z̃) -> V̂, X̂0
583583
584584Compute the `V̂` vector and `X̂0` vectors for the `MovingHorizonEstimator` and `LinModel`.
585585
586- The function mutates `V̂`, `X̂0`, `û0` and `ŷ0` vector arguments. The vector `V̂` is the
587- estimated sensor noises from ``k-N_k+1`` to ``k``. The `X̂0` vector is estimated states from
588- ``k-N_k+2`` to ``k+1``.
586+ The function mutates `V̂` and `X̂0` vector arguments. The vector `V̂` is the estimated sensor
587+ noises from ``k-N_k+1`` to ``k``. The `X̂0` vector is estimated states from ``k-N_k+2`` to
588+ ``k+1``. The computations are (by truncating the matrices when `N_k < H_e`):
589+ ```math
590+ \b egin{aligned}
591+ \m athbf{V̂} &= \m athbf{Ẽ Z̃} + \m athbf{F} \\
592+ \m athbf{X̂_0} &= \m athbf{Ẽ_x̂ Z̃} + \m athbf{F_x̂}
593+ \e nd{aligned}
594+ ```
589595"""
590- function predict ! (V̂, X̂0, _ , _ , _ , estim:: MovingHorizonEstimator , :: LinModel , Z̃)
596+ function predict_mhe ! (V̂, X̂0, _ , _ , _ , estim:: MovingHorizonEstimator , :: LinModel , Z̃)
591597 nϵ, Nk = estim. nϵ, estim. Nk[]
592598 nX̂, nŴ, nYm = estim. nx̂* Nk, estim. nx̂* Nk, estim. nym* Nk
593599 nZ̃ = nϵ + estim. nx̂ + nŴ
@@ -596,8 +602,16 @@ function predict!(V̂, X̂0, _ , _ , _ , estim::MovingHorizonEstimator, ::LinMod
596602 return V̂, X̂0
597603end
598604
599- " Compute the two vectors when `model` is not a `LinModel`."
600- function predict! (V̂, X̂0, û0, k0, ŷ0, estim:: MovingHorizonEstimator , model:: SimModel , Z̃)
605+ @doc raw """
606+ predict_mhe!(V̂, X̂0, û0, k0, ŷ0, estim::MovingHorizonEstimator, model::SimModel, Z̃) -> V̂, X̂0
607+
608+ Compute the vectors when `model` is *not* a [`LinModel`](@ref).
609+
610+ The function mutates `V̂`, `X̂0`, `û0` and `ŷ0` vector arguments. The augmented model of
611+ [`f̂!`](@ref) and [`ĥ!`](@ref) is called recursively in a `for` loop from ``j=1`` to ``N_k``,
612+ and by adding the estimated process noise ``\m athbf{ŵ}``.
613+ """
614+ function predict_mhe! (V̂, X̂0, û0, k0, ŷ0, estim:: MovingHorizonEstimator , model:: SimModel , Z̃)
601615 nϵ, Nk = estim. nϵ, estim. Nk[]
602616 nu, nd, nx̂, nŵ, nym = model. nu, model. nd, estim. nx̂, estim. nx̂, estim. nym
603617 nx̃ = nϵ + nx̂
@@ -646,18 +660,18 @@ The method mutates all the arguments before `estim` argument.
646660"""
647661function update_prediction! (V̂, X̂0, û0, k0, ŷ0, g, estim:: MovingHorizonEstimator , Z̃)
648662 model = estim. model
649- V̂, X̂0 = predict ! (V̂, X̂0, û0, k0, ŷ0, estim, model, Z̃)
663+ V̂, X̂0 = predict_mhe ! (V̂, X̂0, û0, k0, ŷ0, estim, model, Z̃)
650664 ϵ = getϵ (estim, Z̃)
651- g = con_nonlinprog ! (g, estim, model, X̂0, V̂, ϵ)
665+ g = con_nonlinprog_mhe ! (g, estim, model, X̂0, V̂, ϵ)
652666 return nothing
653667end
654668
655669"""
656- con_nonlinprog !(g, estim::MovingHorizonEstimator, model::SimModel, X̂0, V̂, ϵ)
670+ con_nonlinprog_mhe !(g, estim::MovingHorizonEstimator, model::SimModel, X̂0, V̂, ϵ) -> g
657671
658- Nonlinear constrains for [`MovingHorizonEstimator`](@ref).
672+ Compute nonlinear constrains `g` in-place for [`MovingHorizonEstimator`](@ref).
659673"""
660- function con_nonlinprog ! (g, estim:: MovingHorizonEstimator , :: SimModel , X̂0, V̂, ϵ)
674+ function con_nonlinprog_mhe ! (g, estim:: MovingHorizonEstimator , :: SimModel , X̂0, V̂, ϵ)
661675 nX̂con, nX̂ = length (estim. con. X̂0min), estim. nx̂ * estim. Nk[]
662676 nV̂con, nV̂ = length (estim. con. V̂min), estim. nym* estim. Nk[]
663677 for i in eachindex (g)
@@ -684,7 +698,7 @@ function con_nonlinprog!(g, estim::MovingHorizonEstimator, ::SimModel, X̂0, V̂
684698end
685699
686700" No nonlinear constraints if `model` is a [`LinModel`](@ref), return `g` unchanged."
687- con_nonlinprog ! (g, :: MovingHorizonEstimator , :: LinModel , _ , _ , _ ) = g
701+ con_nonlinprog_mhe ! (g, :: MovingHorizonEstimator , :: LinModel , _ , _ , _ ) = g
688702
689703" Throw an error if P̂ != nothing."
690704function setstate_cov! (:: MovingHorizonEstimator , P̂)
0 commit comments