@@ -120,8 +120,8 @@ function getinfo(mpc::PredictiveController{NT}) where NT<:Real
120
120
Ȳ, Ū = similar (mpc. Yop), similar (mpc. Uop)
121
121
Ŷe, Ue = Vector {NT} (undef, nŶe), Vector {NT} (undef, nUe)
122
122
Ŷ0, x̂0end = predict! (Ŷ0, x̂0, x̂0next, u0, û0, mpc, model, mpc. ΔŨ)
123
- Ŷe, Ue = extended_predictions! (Ŷe, Ue , Ū, mpc, model, Ŷ0, mpc. ΔŨ)
124
- J = obj_nonlinprog! (Ȳ, Ū, mpc, model, Ŷe, Ue , mpc. ΔŨ)
123
+ Ue, Ŷe = extended_predictions! (Ue, Ŷe , Ū, mpc, model, Ŷ0, mpc. ΔŨ)
124
+ J = obj_nonlinprog! (Ȳ, Ū, mpc, model, Ue, Ŷe , mpc. ΔŨ)
125
125
U = Ū
126
126
U .= @views Ue[1 : end - model. nu]
127
127
Ŷ = Ȳ
@@ -362,28 +362,28 @@ function predict!(Ŷ0, x̂0, x̂0next, u0, û0, mpc::PredictiveController, mod
362
362
end
363
363
364
364
"""
365
- extended_predictions!(Ŷe, Ue , Ū, mpc, model, Ŷ0, ΔŨ) -> Ŷe, Ue
365
+ extended_predictions!(Ue, Ŷe , Ū, mpc, model, Ŷ0, ΔŨ) -> Ŷe, Ue
366
366
367
- Compute the extended predictions `Ŷe ` and `Ue` for the nonlinear optimization.
367
+ Compute the extended vectors `Ue ` and `Ŷe` and for the nonlinear optimization.
368
368
369
- The function mutates `Ŷe `, `Ue ` and `Ū` in arguments, without assuming any initial values.
369
+ The function mutates `Ue `, `Ŷe ` and `Ū` in arguments, without assuming any initial values.
370
370
"""
371
- function extended_predictions! (Ŷe, Ue , Ū, mpc, model, Ŷ0, ΔŨ)
371
+ function extended_predictions! (Ue, Ŷe , Ū, mpc, model, Ŷ0, ΔŨ)
372
372
ny, nu = model. ny, model. nu
373
- # --- extended output predictions Ŷe = [ŷ(k); Ŷ] ---
374
- Ŷe[1 : ny] .= mpc. ŷ
375
- Ŷe[ny+ 1 : end ] .= Ŷ0 .+ mpc. Yop
376
373
# --- extended manipulated inputs Ue = [U; u(k+Hp-1)] ---
377
374
U0 = Ū
378
375
U0 .= mul! (U0, mpc. S̃, ΔŨ) .+ mpc. T_lastu0
379
376
Ue[1 : end - nu] .= U0 .+ mpc. Uop
380
377
# u(k + Hp) = u(k + Hp - 1) since Δu(k+Hp) = 0 (because Hc ≤ Hp):
381
378
Ue[end - nu+ 1 : end ] .= @views Ue[end - 2 nu+ 1 : end - nu]
382
- return Ŷe, Ue
379
+ # --- extended output predictions Ŷe = [ŷ(k); Ŷ] ---
380
+ Ŷe[1 : ny] .= mpc. ŷ
381
+ Ŷe[ny+ 1 : end ] .= Ŷ0 .+ mpc. Yop
382
+ return Ue, Ŷe
383
383
end
384
384
385
385
"""
386
- obj_nonlinprog!( _ , _ , mpc::PredictiveController, model::LinModel, Ŷe, Ue , ΔŨ)
386
+ obj_nonlinprog!( _ , _ , mpc::PredictiveController, model::LinModel, Ue, Ŷe , ΔŨ)
387
387
388
388
Nonlinear programming objective function when `model` is a [`LinModel`](@ref).
389
389
@@ -392,23 +392,23 @@ also be called on any [`PredictiveController`](@ref)s to evaluate the objective
392
392
at specific `Ue`, `Ŷe` and `ΔŨ`, values. It does not mutate any argument.
393
393
"""
394
394
function obj_nonlinprog! (
395
- _, _, mpc:: PredictiveController , model:: LinModel , Ŷe, Ue , ΔŨ:: AbstractVector{NT}
395
+ _, _, mpc:: PredictiveController , model:: LinModel , Ue, Ŷe , ΔŨ:: AbstractVector{NT}
396
396
) where NT <: Real
397
397
JQP = obj_quadprog (ΔŨ, mpc. H̃, mpc. q̃) + mpc. r[]
398
- E_JE = obj_econ! (Ue, Ŷe, mpc, model )
398
+ E_JE = obj_econ (mpc, model, Ue, Ŷe )
399
399
return JQP + E_JE
400
400
end
401
401
402
402
"""
403
- obj_nonlinprog!(Ȳ, Ū, mpc::PredictiveController, model::SimModel, Ŷe, Ue , ΔŨ)
403
+ obj_nonlinprog!(Ȳ, Ū, mpc::PredictiveController, model::SimModel, Ue, Ŷe , ΔŨ)
404
404
405
405
Nonlinear programming objective method when `model` is not a [`LinModel`](@ref). The
406
406
function `dot(x, A, x)` is a performant way of calculating `x'*A*x`. This method mutates
407
407
`Ȳ` and `Ū` arguments, without assuming any initial values (it recuperates the values in
408
408
`Ŷe` and `Ue` arguments).
409
409
"""
410
410
function obj_nonlinprog! (
411
- Ȳ, Ū, mpc:: PredictiveController , model:: SimModel , Ŷe, Ue , ΔŨ:: AbstractVector{NT}
411
+ Ȳ, Ū, mpc:: PredictiveController , model:: SimModel , Ue, Ŷe , ΔŨ:: AbstractVector{NT}
412
412
) where NT<: Real
413
413
nu, ny = model. nu, model. ny
414
414
# --- output setpoint tracking term ---
@@ -426,12 +426,12 @@ function obj_nonlinprog!(
426
426
JR̂u = 0.0
427
427
end
428
428
# --- economic term ---
429
- E_JE = obj_econ! (Ue, Ŷe, mpc, model )
429
+ E_JE = obj_econ (mpc, model, Ue, Ŷe )
430
430
return JR̂y + JΔŨ + JR̂u + E_JE
431
431
end
432
432
433
433
" By default, the economic term is zero."
434
- obj_econ! ( _ , _ , :: PredictiveController , :: SimModel ) = 0.0
434
+ obj_econ ( :: PredictiveController , :: SimModel , _ , _ ) = 0.0
435
435
436
436
@doc raw """
437
437
optim_objective!(mpc::PredictiveController) -> ΔŨ
0 commit comments