Skip to content

Commit e3bf80c

Browse files
committed
added: additional Âe arg ing MHE gc function
1 parent 26bae7a commit e3bf80c

1 file changed

Lines changed: 28 additions & 27 deletions

File tree

‎src/estimator/mhe/construct.jl‎

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ however, since it minimizes the following objective function at each discrete ti
282282
```
283283
subject to [`setconstraint!`](@ref) bounds and the custom nonlinear inequality constraints:
284284
```math
285-
\mathbf{g_c}(\mathbf{X̂_e, V̂_e, Ŵ_e, U_e, Y_e^m, D_e, P̄, x̄, p}, ε) ≤ \mathbf{0}
285+
\mathbf{g_c}(\mathbf{X̂_e, Â_e, V̂_e, Ŵ_e, U_e, Y_e^m, D_e, P̄, x̄, p}, ε) ≤ \mathbf{0}
286286
```
287287
and in which the arrival costs are evaluated from the states estimated at time ``k-N_k``:
288288
```math
@@ -309,13 +309,13 @@ The chosen [`TranscriptionMethod`](@ref) determines the content of the decision
309309
and ``\mathbf{Ŵ}``). The vectors ``\mathbf{Ŵ}`` and ``\mathbf{V̂}`` respectively encompass
310310
the estimated process noises ``\mathbf{ŵ}(k-j+p)`` and sensor noises ``\mathbf{v̂}(k-j+1)``
311311
from ``j=N_k`` to ``1``. The arguments of ``\mathbf{g_c}`` include the extended vectors of
312-
the estimated states ``\mathbf{X̂_e}``, estimated sensor noises ``\mathbf{V̂_e}``, estimated
313-
process noises ``\mathbf{Ŵ_e}``, manipulated inputs ``\mathbf{U_e}``, measured outputs
314-
``\mathbf{Y_e^m}`` and measured disturbances ``\mathbf{D_e}``. The Extended Help details all
315-
these vectors, the slack variable ``ε`` and the estimation of the covariance at arrival
316-
``\mathbf{P̂}_{k-N_k}(k-N_k+p)``. If the keyword argument `direct=true` (default value), the
317-
constant ``p=0`` in the equations above, and the MHE is in the current form. Else ``p=1``,
318-
leading to the prediction form.
312+
the estimated states ``\mathbf{X̂_e}``, estimated algebraic variables ``\mathbf{Â_e}``,
313+
estimated sensor noises ``\mathbf{V̂_e}``, estimated process noises ``\mathbf{Ŵ_e}``,
314+
manipulated inputs ``\mathbf{U_e}``, measured outputs ``\mathbf{Y_e^m}`` and measured
315+
disturbances ``\mathbf{D_e}``. The Extended Help details all these vectors, the slack
316+
variable ``ε`` and the estimation of the covariance at arrival ``\mathbf{P̂}_{k-N_k}(k-N_k+p)``.
317+
If the keyword argument `direct=true` (default value), the constant ``p=0`` in the equations
318+
above, and the MHE is in the current form. Else ``p=1``, leading to the prediction form.
319319
320320
See [`UnscentedKalmanFilter`](@ref) for details on the augmented process model and
321321
``\mathbf{R̂}, \mathbf{Q̂}`` covariances. This estimator allocates a fair amount of memory
@@ -352,9 +352,9 @@ at each time step for the optimization.
352352
- `σPint_ym_0=fill(1,sum(nint_ym))` or *`sigmaPint_ym_0`* : same than `σP_0` but for the unmeasured
353353
disturbances at measured outputs ``\mathbf{P_{int_{ym}}}(0)`` (composed of integrators).
354354
- `Cwt=Inf` : slack variable weight ``C``, default to `Inf` meaning hard constraints only.
355-
- `gc=(_,_,_,_,_,_,_,_,_,_,_)->nothing` or `gc!` : custom nonlinear inequality constraint function
356-
``\mathbf{g_c}(\mathbf{X̂_e, V̂_e, Ŵ_e, U_e, Y_e^m, D_e, P̄, x̄, p}, ε)``, mutating or not
357-
(details in Extended Help).
355+
- `gc=(_,_,_,_,_,_,_,_,_,_,_,_)->nothing` or `gc!` : custom nonlinear inequality constraint function
356+
``\mathbf{g_c}(\mathbf{X̂_e, Â_e, V̂_e, Ŵ_e, U_e, Y_e^m, D_e, P̄, x̄, p}, ε)``, mutating or
357+
not (details in Extended Help).
358358
- `nc=0` : number of custom nonlinear inequality constraints.
359359
- `p=model.p` : ``\mathbf{g_c}`` functions parameter ``\mathbf{p}`` (any type).
360360
- `transcription=default_transcription(model)` : a [`TranscriptionMethod`](@ref) object,
@@ -463,6 +463,7 @@ MovingHorizonEstimator estimator with a sample time Ts = 5.0 s:
463463
| ARGUMENT | SIZE | FIRST SAMPLE | LAST SAMPLE | MISSING SAMPLES |
464464
| :--------------- | :-------------- | :-------------- | :-------------- | :----------------- |
465465
| ``\mathbf{X̂_e}`` | `((Nk+1)*nx̂,)` | ``k - N_k + p`` | ``k + p`` | — |
466+
| ``\mathbf{Â_e}`` | `((Nk+1)*na,)` | ``k - N_k + p`` | ``k + p`` | — |
466467
| ``\mathbf{V̂_e}`` | `((Nk+1)*nym,)` | ``k - N_k + p`` | ``k + p`` | ``k - N_k, k + 1`` |
467468
| ``\mathbf{Ŵ_e}`` | `((Nk+1)*nx̂,)` | ``k - N_k + p`` | ``k + p`` | ``k + p`` |
468469
| ``\mathbf{U_e}`` | `((Nk+1)*nu,)` | ``k - N_k + p`` | ``k + p`` | ``k + p`` |
@@ -474,13 +475,13 @@ MovingHorizonEstimator estimator with a sample time Ts = 5.0 s:
474475
| ``ε`` | `()` | — | — | — |
475476
476477
If `LHS` represents the result of the left-hand side in the inequality
477-
``\mathbf{g_c}(\mathbf{X̂_e, V̂_e, Ŵ_e, U_e, Y_e^m, D_e, P̄, x̄, p}, ε) ≤ \mathbf{0}``,
478+
``\mathbf{g_c}(\mathbf{X̂_e, Â_e, V̂_e, Ŵ_e, U_e, Y_e^m, D_e, P̄, x̄, p}, ε) ≤ \mathbf{0}``,
478479
the function `gc` can be implemented in two possible ways:
479480
480-
1. **Non-mutating function** (out-of-place): define it as `gc(X̂e, V̂e, Ŵe, Ue, Yem, De,
481+
1. **Non-mutating function** (out-of-place): define it as `gc(X̂e, Âe, V̂e, Ŵe, Ue, Yem, De,
481482
P̄, x̄, p, ε) -> LHS`. This syntax is simple and intuitive but it allocates more memory.
482-
2. **Mutating function** (in-place): define it as `gc!(LHS, X̂e, V̂e, Ŵe, Ue, Yem, De, P̄,
483-
x̄, p, ε) -> nothing`. This syntax reduces the allocations and potentially the
483+
2. **Mutating function** (in-place): define it as `gc!(LHS, X̂e, Âe, V̂e, Ŵe, Ue, Yem, De,
484+
P̄, x̄, p, ε) -> nothing`. This syntax reduces the allocations and potentially the
484485
computational burden as well.
485486
486487
The keyword argument `nc` is the number of elements in `LHS`, and `gc!`, an alias for
@@ -490,7 +491,7 @@ MovingHorizonEstimator estimator with a sample time Ts = 5.0 s:
490491
on the state estimate at the beginning of the window ``k-N_k+p``, that is, in the past.
491492
It is not the same as the current estimate covariance ``\mathbf{P̂}_k(k)``, a value not
492493
computed by the MHE (contrarily to e.g. the [`KalmanFilter`](@ref)). Three keyword
493-
arguments specify its initial value with ``\mathbf{P̂_i} = \mathrm{diag}\{ \mathbf{P}(0),
494+
arguments specify its initial value with ``\mathbf{P̂_i} = \mathrm{diag}\{ \mathbf{P}(0),
494495
\mathbf{P_{int_{u}}}(0), \mathbf{P_{int_{ym}}}(0) \}``. The initial state estimate
495496
``\mathbf{x̂_i}`` can be manually specified with [`setstate!`](@ref), or automatically
496497
with [`initstate!`](@ref) for [`LinModel`](@ref). Note the MHE with ``p=0`` is slightly
@@ -566,7 +567,7 @@ function MovingHorizonEstimator(
566567
sigmaPint_ym_0 = fill(1, max(sum(nint_ym), 0)),
567568
sigmaQint_ym = fill(1, max(sum(nint_ym), 0)),
568569
Cwt::Real = Inf,
569-
gc!::Function = (_,_,_,_,_,_,_,_,_,_,_) -> nothing,
570+
gc!::Function = (_,_,_,_,_,_,_,_,_,_,_,_) -> nothing,
570571
gc ::Function = gc!,
571572
nc ::Int = 0,
572573
p = model.p,
@@ -600,7 +601,7 @@ end
600601
@doc raw"""
601602
MovingHorizonEstimator(
602603
model, He, i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂, Cwt=Inf;
603-
gc!=(_,_,_,_,_,_,_,_,_,_,_) -> nothing,
604+
gc!=(_,_,_,_,_,_,_,_,_,_,_,_) -> nothing,
604605
gc=gc!,
605606
nc=0,
606607
transcription=default_transcription(model),
@@ -620,7 +621,7 @@ argument. If `isnothing(P̂_0)`, its value will be fetch in `covestim.cov.P̂`.
620621
"""
621622
function MovingHorizonEstimator(
622623
model::SM, He, i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂, Cwt=Inf;
623-
gc!::Function = (_,_,_,_,_,_,_,_,_,_,_) -> nothing,
624+
gc!::Function = (_,_,_,_,_,_,_,_,_,_,_,_) -> nothing,
624625
gc ::Function = gc!,
625626
nc = 0,
626627
p = model.p,
@@ -707,29 +708,29 @@ function validate_gc_mhe(NT, gc)
707708
ismutating = hasmethod(
708709
gc,
709710
Tuple{
710-
# LHS, , X̂e , V̂e , Ŵe
711-
Vector{NT}, Vector{NT}, Vector{NT}, Vector{NT},
711+
# LHS, , X̂e , Âe , V̂e , Ŵe
712+
Vector{NT}, Vector{NT}, Vector{NT}, Vector{NT}, Vector{NT},
712713
# Ue , Yem , De , P̄ , x̄ , p , ε
713714
Vector{NT}, Vector{NT}, Vector{NT}, AbstractMatrix{NT}, Vector{NT}, Any, NT
714715
}
715716
)
716717
isnonmutating = hasmethod(
717718
gc,
718719
Tuple{
719-
# X̂e , V̂e , Ŵe
720-
Vector{NT}, Vector{NT}, Vector{NT},
720+
# X̂e , Âe , V̂e , Ŵe
721+
Vector{NT}, Vector{NT}, Vector{NT}, Vector{NT},
721722
# Ue , Yem , De , P̄ , x̄ , p , ε
722723
Vector{NT}, Vector{NT}, Vector{NT}, AbstractMatrix{NT}, Vector{NT}, Any, NT
723724
}
724725
)
725726
if !(ismutating || isnonmutating)
726727
error(
727728
"the custom constraint function has no method with type signature "*
728-
"gc(X̂e::Vector{$(NT)}, V̂e::Vector{$(NT)}, Ŵe::Vector{$(NT)}, "*
729+
"gc(X̂e::Vector{$(NT)}, Âe::Vector{$(NT)}, V̂e::Vector{$(NT)}, Ŵe::Vector{$(NT)}, "*
729730
"Ue::Vector{$(NT)}, Yem::Vector{$(NT)}, De::Vector{$(NT)}, "*
730731
"P̄::Vector{$(NT)}, x̄::Vector{$(NT)}, p::Any, ϵ::$(NT)) "*
731732
"or mutating form gc!(LHS::Vector{$(NT)}, "*
732-
"X̂e::Vector{$(NT)}, V̂e::Vector{$(NT)}, Ŵe::Vector{$(NT)}, "*
733+
"X̂e::Vector{$(NT)}, Âe::Vector{$(NT)}, V̂e::Vector{$(NT)}, Ŵe::Vector{$(NT)}, "*
733734
"Ue::Vector{$(NT)}, Yem::Vector{$(NT)}, De::Vector{$(NT)}, "*
734735
"P̄::Vector{$(NT)}, x̄::Vector{$(NT)}, p::Any, ϵ::$(NT))"
735736
)
@@ -743,8 +744,8 @@ function get_mutating_gc_mhe(NT, gc)
743744
gc! = if ismutating_gc
744745
gc
745746
else
746-
function gc!(LHS, X̂e, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, p, ϵ)
747-
LHS .= gc(X̂e, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, p, ϵ)
747+
function gc!(LHS, X̂e, Âe, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, p, ϵ)
748+
LHS .= gc(X̂e, Âe, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, p, ϵ)
748749
return nothing
749750
end
750751
end

0 commit comments

Comments
 (0)