@@ -115,7 +115,7 @@ function getinfo(estim::MovingHorizonEstimator{NT}) where NT<:Real
115
115
info = Dict {Symbol, Any} ()
116
116
V̂, X̂0 = similar (estim. Y0m[1 : nym* Nk]), similar (estim. X̂0[1 : nx̂* Nk])
117
117
û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̃)
119
119
x̂0arr = @views estim. Z̃[nx̃- nx̂+ 1 : nx̃]
120
120
x̄ = estim. x̂0arr_old - x̂0arr
121
121
X̂0 = [x̂0arr; X̂0]
@@ -418,7 +418,7 @@ function optim_objective!(estim::MovingHorizonEstimator{NT}) where NT<:Real
418
418
# --------- update estimate -----------------------
419
419
û0, ŷ0, k0 = buffer. û, buffer. ŷ, buffer. k
420
420
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̃)
422
422
x̂0next = @views X̂0[end - nx̂+ 1 : end ]
423
423
estim. x̂0 .= x̂0next
424
424
return estim. Z̃
@@ -461,7 +461,7 @@ function set_warmstart_mhe!(V̂, X̂0, estim::MovingHorizonEstimator{NT}, Z̃var
461
461
# --- process noise estimates Ŵ ---
462
462
Z̃s[nx̃+ 1 : end ] = estim. Ŵ
463
463
# 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)
465
465
Js = obj_nonlinprog! (x̄, estim, model, V̂, Z̃s)
466
466
if ! isfinite (Js)
467
467
Z̃s[nx̃+ 1 : end ] = 0
@@ -578,16 +578,22 @@ function obj_nonlinprog!(
578
578
return dot (x̄, invP̄, x̄) + dot (Ŵ, invQ̂_Nk, Ŵ) + dot (V̂, invR̂_Nk, V̂) + Jϵ
579
579
end
580
580
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
583
583
584
584
Compute the `V̂` vector and `X̂0` vectors for the `MovingHorizonEstimator` and `LinModel`.
585
585
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
+ ```
589
595
"""
590
- function predict ! (V̂, X̂0, _ , _ , _ , estim:: MovingHorizonEstimator , :: LinModel , Z̃)
596
+ function predict_mhe ! (V̂, X̂0, _ , _ , _ , estim:: MovingHorizonEstimator , :: LinModel , Z̃)
591
597
nϵ, Nk = estim. nϵ, estim. Nk[]
592
598
nX̂, nŴ, nYm = estim. nx̂* Nk, estim. nx̂* Nk, estim. nym* Nk
593
599
nZ̃ = nϵ + estim. nx̂ + nŴ
@@ -596,8 +602,16 @@ function predict!(V̂, X̂0, _ , _ , _ , estim::MovingHorizonEstimator, ::LinMod
596
602
return V̂, X̂0
597
603
end
598
604
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̃)
601
615
nϵ, Nk = estim. nϵ, estim. Nk[]
602
616
nu, nd, nx̂, nŵ, nym = model. nu, model. nd, estim. nx̂, estim. nx̂, estim. nym
603
617
nx̃ = nϵ + nx̂
@@ -646,18 +660,18 @@ The method mutates all the arguments before `estim` argument.
646
660
"""
647
661
function update_prediction! (V̂, X̂0, û0, k0, ŷ0, g, estim:: MovingHorizonEstimator , Z̃)
648
662
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̃)
650
664
ϵ = getϵ (estim, Z̃)
651
- g = con_nonlinprog ! (g, estim, model, X̂0, V̂, ϵ)
665
+ g = con_nonlinprog_mhe ! (g, estim, model, X̂0, V̂, ϵ)
652
666
return nothing
653
667
end
654
668
655
669
"""
656
- con_nonlinprog !(g, estim::MovingHorizonEstimator, model::SimModel, X̂0, V̂, ϵ)
670
+ con_nonlinprog_mhe !(g, estim::MovingHorizonEstimator, model::SimModel, X̂0, V̂, ϵ) -> g
657
671
658
- Nonlinear constrains for [`MovingHorizonEstimator`](@ref).
672
+ Compute nonlinear constrains `g` in-place for [`MovingHorizonEstimator`](@ref).
659
673
"""
660
- function con_nonlinprog ! (g, estim:: MovingHorizonEstimator , :: SimModel , X̂0, V̂, ϵ)
674
+ function con_nonlinprog_mhe ! (g, estim:: MovingHorizonEstimator , :: SimModel , X̂0, V̂, ϵ)
661
675
nX̂con, nX̂ = length (estim. con. X̂0min), estim. nx̂ * estim. Nk[]
662
676
nV̂con, nV̂ = length (estim. con. V̂min), estim. nym* estim. Nk[]
663
677
for i in eachindex (g)
@@ -684,7 +698,7 @@ function con_nonlinprog!(g, estim::MovingHorizonEstimator, ::SimModel, X̂0, V̂
684
698
end
685
699
686
700
" 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
688
702
689
703
" Throw an error if P̂ != nothing."
690
704
function setstate_cov! (:: MovingHorizonEstimator , P̂)
0 commit comments