@@ -88,33 +88,38 @@ ManualEstimator estimator with a sample time Ts = 0.5 s, LinModel and:
8888# Extended Help
8989!!! details "Extended Help"
9090 A first use case is a linear predictive controller based on nonlinear state estimation,
91- for example a nonlinear [`MovingHorizonEstimator`](@ref) (MHE). The [`ManualEstimator`](@ref)
92- serves as a wrapper to provide the minimal required information to construct any
93- [`PredictiveController`](@ref) object, e.g.:
91+ for example a nonlinear [`MovingHorizonEstimator`](@ref) (MHE). Note that the model
92+ augmentation scheme with `nint_u` and `nint_ym` options must be identical for both
93+ [`StateEstimator`](@ref) objects (see [`SteadyKalmanFilter`](@ref) extended help for
94+ details on augmentation). The [`ManualEstimator`](@ref) serves as a wrapper to provide
95+ the minimal required information to construct any [`PredictiveController`](@ref) object:
96+
9497 ```jldoctest
95- f(x,u,_,_) = 0.5*sin.(x + u)
96- h(x,_,_) = x
97- model = NonLinModel(f, h, 10.0, 1, 1, 1, solver=nothing)
98- linModel = linearize(model, x=[0], u=[0])
99- man = ManualEstimator(linModel, nint_u=[1])
100- mpc = LinMPC(man)
101- estim = MovingHorizonEstimator(model, nint_u=[1], He=5)
102- estim = setconstraint!(estim, v̂min=[-0.001], v̂max=[0.001])
103- initstate!(estim, [0], [0])
104- y_data, ŷ_data = zeros(5), zeros(5)
105- for i=1:5
106- y = model() # simulated measurement
107- x̂ = preparestate!(estim, y) # correct nonlinear MHE state estimate
108- ŷ = estim() # nonlinear MHE estimated output
109- setstate!(mpc, x̂) # update MPC with the MHE corrected state
110- u = moveinput!(mpc, [0])
111- y_data[i], ŷ_data[i] = y[1], ŷ[1]
112- updatestate!(estim, u, y) # update nonlinear MHE estimation
113- updatestate!(model, u .+ 0.5) # update plant simulator with load disturbance
98+ julia> function man_sim!()
99+ f(x,u,_,_) = 0.5*sin.(x + u)
100+ h(x,_,_) = x
101+ model = NonLinModel(f, h, 10.0, 1, 1, 1, solver=nothing)
102+ linModel = linearize(model, x=[0], u=[0])
103+ man = ManualEstimator(linModel, nint_u=[1])
104+ mpc = LinMPC(man)
105+ estim = MovingHorizonEstimator(model, nint_u=[1], He=5)
106+ estim = setconstraint!(estim, v̂min=[-0.001], v̂max=[0.001])
107+ initstate!(estim, [0], [0])
108+ y_data, ŷ_data = zeros(5), zeros(5)
109+ for i=1:5
110+ y = model() # simulated measurement
111+ x̂ = preparestate!(estim, y) # correct nonlinear MHE state estimate
112+ ŷ = estim() # nonlinear MHE estimated output
113+ setstate!(mpc, x̂) # update MPC with the MHE corrected state
114+ u = moveinput!(mpc, [0])
115+ y_data[i], ŷ_data[i] = y[1], ŷ[1]
116+ updatestate!(estim, u, y) # update nonlinear MHE estimation
117+ updatestate!(model, u .+ 0.5) # update simulator with load disturbance
118+ end
119+ return collect([y_data ŷ_data]')
114120 end
115- YandŶ = collect([y_data ŷ_data]')
116121
117- # output
122+ julia> YandŶ = man_sim!()
118123 2×5 Matrix{Float64}:
119124 0.0 0.239713 0.227556 0.157837 0.0986288
120125 -1.41242e-19 0.238713 0.226556 0.156837 0.0976288
0 commit comments