@@ -95,31 +95,31 @@ ManualEstimator estimator with a sample time Ts = 0.5 s, LinModel and:
95
95
the minimal required information to construct any [`PredictiveController`](@ref) object:
96
96
97
97
```jldoctest
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]')
120
- end
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]')
120
+ end;
121
121
122
- julia> YandŶ = man_sim! ()
122
+ julia> YandŶ = man_sim()
123
123
2×5 Matrix{Float64}:
124
124
0.0 0.239713 0.227556 0.157837 0.0986288
125
125
-1.41242e-19 0.238713 0.226556 0.156837 0.0976288
0 commit comments