@@ -106,9 +106,9 @@ function getinfo(mpc::PredictiveController{NT}) where NT<:Real
106
106
info = Dict {Symbol, Union{JuMP._SolutionSummary, Vector{NT}, NT}} ()
107
107
Ŷ, x̂, u = similar (mpc. Ŷop), similar (mpc. estim. x̂), similar (mpc. estim. lastu0)
108
108
Ŷ, x̂end = predict! (Ŷ, x̂, u, mpc, mpc. estim. model, mpc. ΔŨ)
109
- U = mpc. S̃* mpc. ΔŨ + mpc. T * (mpc . estim . lastu0 + mpc . estim . model . uop)
109
+ U = mpc. S̃* mpc. ΔŨ + mpc. T_lastu
110
110
Ȳ, Ū = similar (Ŷ), similar (U)
111
- J = obj_nonlinprog! (Ȳ, Ū, u, mpc, mpc. estim. model, Ŷ, mpc. ΔŨ)
111
+ J = obj_nonlinprog! (Ȳ, Ū, mpc, mpc. estim. model, Ŷ, mpc. ΔŨ)
112
112
info[:ΔU ] = mpc. ΔŨ[1 : mpc. Hc* mpc. estim. model. nu]
113
113
info[:ϵ ] = isinf (mpc. C) ? NaN : mpc. ΔŨ[end ]
114
114
info[:J ] = J
@@ -155,6 +155,7 @@ They are computed with these equations using in-place operations:
155
155
```
156
156
"""
157
157
function initpred! (mpc:: PredictiveController , model:: LinModel , d, ym, D̂, R̂y, R̂u)
158
+ mul! (mpc. T_lastu, mpc. T, mpc. estim. lastu0 .+ model. uop)
158
159
ŷ, F, q̃, p = mpc. ŷ, mpc. F, mpc. q̃, mpc. p
159
160
ŷ .= evalŷ (mpc. estim, ym, d)
160
161
predictstoch! (mpc, mpc. estim, d, ym) # init mpc.Ŷop for InternalModel
@@ -177,8 +178,7 @@ function initpred!(mpc::PredictiveController, model::LinModel, d, ym, D̂, R̂y,
177
178
p .= dot (C_y, mpc. M_Hp, C_y)
178
179
if ~ mpc. noR̂u
179
180
mpc. R̂u .= R̂u
180
- lastu = mpc. estim. lastu0 + model. uop
181
- C_u = mpc. T* lastu - mpc. R̂u
181
+ C_u = mpc. T_lastu .- mpc. R̂u
182
182
mpc. q̃ .+ = lmul! (2 , (mpc. L_Hp* mpc. S̃)' * C_u)
183
183
mpc. p .+ = dot (C_y, mpc. L_Hp, C_u)
184
184
end
@@ -195,6 +195,7 @@ Init `ŷ, Ŷop, d0, D̂0` matrices when model is not a [`LinModel`](@ref).
195
195
[`InternalModel`](@ref).
196
196
"""
197
197
function initpred! (mpc:: PredictiveController , model:: SimModel , d, ym, D̂, R̂y, R̂u)
198
+ mul! (mpc. T_lastu, mpc. T, mpc. estim. lastu0 .+ model. uop)
198
199
mpc. ŷ .= evalŷ (mpc. estim, ym, d)
199
200
predictstoch! (mpc, mpc. estim, d, ym) # init mpc.Ŷop for InternalModel
200
201
if model. nd ≠ 0
@@ -256,10 +257,9 @@ function linconstraint!(mpc::PredictiveController, model::LinModel)
256
257
fx̂ .+ = mul! (fx̂_LHS, mpc. con. gx̂, mpc. d0)
257
258
fx̂ .+ = mul! (fx̂_LHS, mpc. con. jx̂, mpc. D̂0)
258
259
end
259
- T_lastu = mpc. T* (mpc. estim. lastu0 .+ model. uop)
260
260
mpc. con. b .= [
261
- - mpc. con. Umin + T_lastu
262
- + mpc. con. Umax - T_lastu
261
+ - mpc. con. Umin + mpc . T_lastu
262
+ + mpc. con. Umax - mpc . T_lastu
263
263
- mpc. con. ΔŨmin
264
264
+ mpc. con. ΔŨmax
265
265
- mpc. con. Ymin + mpc. F
273
273
274
274
" Set `b` excluding predicted output constraints when `model` is not a [`LinModel`](@ref)."
275
275
function linconstraint! (mpc:: PredictiveController , model:: SimModel )
276
- T_lastu = mpc. T* (mpc. estim. lastu0 .+ model. uop)
277
276
mpc. con. b .= [
278
- - mpc. con. Umin + T_lastu
279
- + mpc. con. Umax - T_lastu
277
+ - mpc. con. Umin + mpc . T_lastu
278
+ + mpc. con. Umax - mpc . T_lastu
280
279
- mpc. con. ΔŨmin
281
280
+ mpc. con. ΔŨmax
282
281
]
@@ -331,23 +330,20 @@ function predict!(
331
330
end
332
331
333
332
"""
334
- obj_nonlinprog!( _ , _ , u , mpc::PredictiveController, model::LinModel, Ŷ, ΔŨ)
333
+ obj_nonlinprog!( _ , _ , mpc::PredictiveController, model::LinModel, Ŷ, ΔŨ)
335
334
336
335
Nonlinear programming objective function when `model` is a [`LinModel`](@ref).
337
336
338
337
The function is called by the nonlinear optimizer of [`NonLinMPC`](@ref) controllers. It can
339
338
also be called on any [`PredictiveController`](@ref)s to evaluate the objective function `J`
340
- at specific input increments `ΔŨ` and predictions `Ŷ` values. This method mutate `u`
341
- argument.
339
+ at specific input increments `ΔŨ` and predictions `Ŷ` values.
342
340
"""
343
341
function obj_nonlinprog! (
344
- _ , _ , u , mpc:: PredictiveController , model:: LinModel , Ŷ, ΔŨ:: Vector{NT}
342
+ _ , _ , mpc:: PredictiveController , model:: LinModel , Ŷ, ΔŨ:: Vector{NT}
345
343
) where {NT<: Real }
346
344
J = obj_quadprog (ΔŨ, mpc. H̃, mpc. q̃) + mpc. p[]
347
345
if ! iszero (mpc. E)
348
- lastu = u
349
- lastu .= mpc. estim. lastu0 .+ model. uop
350
- U = mpc. S̃* ΔŨ + mpc. T* lastu
346
+ U = mpc. S̃* ΔŨ .+ mpc. T_lastu
351
347
UE = [U; U[(end - model. nu + 1 ): end ]]
352
348
ŶE = [mpc. ŷ; Ŷ]
353
349
J += mpc. E* mpc. JE (UE, ŶE, mpc. D̂E)
@@ -356,14 +352,14 @@ function obj_nonlinprog!(
356
352
end
357
353
358
354
"""
359
- obj_nonlinprog!(Ȳ, Ū, u, mpc::PredictiveController, model::SimModel, Ŷ, ΔŨ)
355
+ obj_nonlinprog!(Ȳ, Ū, mpc::PredictiveController, model::SimModel, Ŷ, ΔŨ)
360
356
361
357
Nonlinear programming objective function when `model` is not a [`LinModel`](@ref). The
362
358
function `dot(x, A, x)` is a performant way of calculating `x'*A*x`. This method mutates
363
359
`Ȳ` and `Ū` vector arguments (output and input setpoint tracking error, respectively).
364
360
"""
365
361
function obj_nonlinprog! (
366
- Ȳ, Ū, u, mpc:: PredictiveController , model:: SimModel , Ŷ, ΔŨ:: Vector{NT}
362
+ Ȳ, Ū, mpc:: PredictiveController , model:: SimModel , Ŷ, ΔŨ:: Vector{NT}
367
363
) where {NT<: Real }
368
364
# --- output setpoint tracking term ---
369
365
Ȳ .= mpc. R̂y .- Ŷ
@@ -372,9 +368,7 @@ function obj_nonlinprog!(
372
368
JΔŨ = dot (ΔŨ, mpc. Ñ_Hc, ΔŨ)
373
369
# --- input over prediction horizon ---
374
370
if ! mpc. noR̂u || ! iszero (mpc. E)
375
- lastu = u
376
- lastu .= mpc. estim. lastu0 .+ model. uop
377
- U = mpc. S̃* ΔŨ + mpc. T* lastu
371
+ U = mpc. S̃* ΔŨ + mpc. T_lastu
378
372
end
379
373
# --- input setpoint tracking term ---
380
374
if ! mpc. noR̂u
0 commit comments