1+ struct ManualEstimator{NT<: Real , SM<: SimModel } <: StateEstimator{NT}
2+ model:: SM
3+ lastu0:: Vector{NT}
4+ x̂op :: Vector{NT}
5+ f̂op :: Vector{NT}
6+ x̂0 :: Vector{NT}
7+ i_ym:: Vector{Int}
8+ nx̂ :: Int
9+ nym:: Int
10+ nyu:: Int
11+ nxs:: Int
12+ As :: Matrix{NT}
13+ Cs_u:: Matrix{NT}
14+ Cs_y:: Matrix{NT}
15+ nint_u :: Vector{Int}
16+ nint_ym:: Vector{Int}
17+ Â :: Matrix{NT}
18+ B̂u :: Matrix{NT}
19+ Ĉ :: Matrix{NT}
20+ B̂d :: Matrix{NT}
21+ D̂d :: Matrix{NT}
22+ Ĉm :: Matrix{NT}
23+ D̂dm :: Matrix{NT}
24+ direct:: Bool
25+ corrected:: Vector{Bool}
26+ buffer:: StateEstimatorBuffer{NT}
27+ function ManualEstimator {NT} (
28+ model:: SM , i_ym, nint_u, nint_ym
29+ ) where {NT<: Real , SM<: SimModel{NT} }
30+ nu, ny, nd, nk = model. nu, model. ny, model. nd, model. nk
31+ nym, nyu = validate_ym (model, i_ym)
32+ As, Cs_u, Cs_y, nint_u, nint_ym = init_estimstoch (model, i_ym, nint_u, nint_ym)
33+ nxs = size (As, 1 )
34+ nx̂ = model. nx + nxs
35+ Â, B̂u, Ĉ, B̂d, D̂d, x̂op, f̂op = augment_model (model, As, Cs_u, Cs_y)
36+ Ĉm, D̂dm = Ĉ[i_ym, :], D̂d[i_ym, :]
37+ lastu0 = zeros (NT, nu)
38+ x̂0 = [zeros (NT, model. nx); zeros (NT, nxs)]
39+ direct = false
40+ corrected = [true ]
41+ buffer = StateEstimatorBuffer {NT} (nu, nx̂, nym, ny, nd, nk)
42+ return new {NT, SM} (
43+ model,
44+ lastu0, x̂op, f̂op, x̂0,
45+ i_ym, nx̂, nym, nyu, nxs,
46+ As, Cs_u, Cs_y, nint_u, nint_ym,
47+ Â, B̂u, Ĉ, B̂d, D̂d, Ĉm, D̂dm,
48+ direct, corrected,
49+ buffer
50+ )
51+ end
52+ end
53+
54+ @doc raw """
55+ ManualEstimator(model::SimModel; <keyword arguments>)
56+
57+ Construct a manual state estimator for `model` ([`LinModel`](@ref) or [`NonLinModel`](@ref)).
58+
59+ This [`StateEstimator`](@ref) type allows the construction of [`PredictiveController`](@ref)
60+ objects but turns off the built-in state estimation. The user must manually provides the
61+ estimate ``\m athbf{x̂}_{k}(k)`` or ``\m athbf{x̂}_{k-1}(k)`` through [`setstate!`](@ref) at
62+ each time step. Calling [`preparestate!`](@ref) and [`updatestate!`](@ref) will not modify
63+ the estimate. See Extended Help for usage examples.
64+
65+ # Arguments
66+ - `model::SimModel` : (deterministic) model for the estimations.
67+ - `i_ym=1:model.ny` : `model` output indices that are measured ``\m athbf{y^m}``, the rest
68+ are unmeasured ``\m athbf{y^u}``.
69+ - `nint_u=0`: integrator quantity for the stochastic model of the unmeasured disturbances at
70+ the manipulated inputs (vector), use `nint_u=0` for no integrator (see Extended Help).
71+ - `nint_ym=default_nint(model,i_ym,nint_u)` : same than `nint_u` but for the unmeasured
72+ disturbances at the measured outputs, use `nint_ym=0` for no integrator (see Extended Help).
73+
74+ # Examples
75+ ```jldoctest
76+ julia> model = LinModel([tf(3, [30, 1]); tf(-2, [5, 1])], 0.5);
77+
78+ julia> estim = ManualEstimator(model, nint_ym=0) # disable augmentation with integrators
79+ ManualEstimator estimator with a sample time Ts = 0.5 s, LinModel and:
80+ 1 manipulated inputs u (0 integrating states)
81+ 2 estimated states x̂
82+ 2 measured outputs ym (0 integrating states)
83+ 0 unmeasured outputs yu
84+ 0 measured disturbances d
85+ ```
86+
87+ # Extended Help
88+ !!! details "Extended Help"
89+ A first use case is a linear predictive controller based on nonlinear state estimation.
90+ The [`ManualEstimator`](@ref) serves as a wrapper to provide the minimal required
91+ information to construct a [`PredictiveController`](@ref). e.g.:
92+
93+ ```julia
94+ a=1
95+ ```
96+ """
97+ function ManualEstimator (
98+ model:: SM ;
99+ i_ym:: AbstractVector{Int} = 1 : model. ny,
100+ nint_u :: IntVectorOrInt = 0 ,
101+ nint_ym:: IntVectorOrInt = default_nint (model, i_ym, nint_u),
102+ ) where {NT<: Real , SM<: SimModel{NT} }
103+ return ManualEstimator {NT} (model, i_ym, nint_u, nint_ym)
104+ end
105+
106+ """
107+ update_estimate!(estim::ManualEstimator, y0m, d0, u0)
108+
109+ Do nothing for [`ManualEstimator`](@ref).
110+ """
111+ update_estimate! (estim:: ManualEstimator , y0m, d0, u0) = nothing
0 commit comments