@@ -103,24 +103,25 @@ julia> round.(getinfo(mpc)[:Ŷ], digits=3)
103
103
```
104
104
"""
105
105
function getinfo (mpc:: PredictiveController{NT} ) where NT<: Real
106
+ model = mpc. estim. model
106
107
info = Dict {Symbol, Union{JuMP._SolutionSummary, Vector{NT}, NT}} ()
107
- Ŷ, u = similar (mpc. Ŷop), similar (mpc . estim . lastu0 )
108
+ Ŷ, u, û = similar (mpc. Ŷop), similar (model . uop), similar (model . uop )
108
109
x̂, x̂next = similar (mpc. estim. x̂), similar (mpc. estim. x̂)
109
- Ŷ, x̂end = predict! (Ŷ, x̂, x̂next, u, mpc , mpc. estim . model, mpc. ΔŨ)
110
+ Ŷ, x̂end = predict! (Ŷ, x̂, x̂next, u, û , mpc, model, mpc. ΔŨ)
110
111
U = mpc. S̃* mpc. ΔŨ + mpc. T_lastu
111
112
Ȳ, Ū = similar (Ŷ), similar (U)
112
- J = obj_nonlinprog! (U, Ȳ, Ū, mpc, mpc . estim . model, Ŷ, mpc. ΔŨ)
113
- info[:ΔU ] = mpc. ΔŨ[1 : mpc. Hc* mpc . estim . model. nu]
113
+ J = obj_nonlinprog! (U, Ȳ, Ū, mpc, model, Ŷ, mpc. ΔŨ)
114
+ info[:ΔU ] = mpc. ΔŨ[1 : mpc. Hc* model. nu]
114
115
info[:ϵ ] = isinf (mpc. C) ? NaN : mpc. ΔŨ[end ]
115
116
info[:J ] = J
116
117
info[:U ] = U
117
- info[:u ] = info[:U ][1 : mpc . estim . model. nu]
118
- info[:d ] = mpc. d0 + mpc . estim . model. dop
118
+ info[:u ] = info[:U ][1 : model. nu]
119
+ info[:d ] = mpc. d0 + model. dop
119
120
info[:D̂ ] = mpc. D̂0 + mpc. Dop
120
121
info[:ŷ ] = mpc. ŷ
121
122
info[:Ŷ ] = Ŷ
122
123
info[:x̂end ] = x̂end
123
- info[:Ŷs ] = mpc. Ŷop - repeat (mpc . estim . model. yop, mpc. Hp) # Ŷop = Ŷs + Yop
124
+ info[:Ŷs ] = mpc. Ŷop - repeat (model. yop, mpc. Hp) # Ŷop = Ŷs + Yop
124
125
info[:R̂y ] = mpc. R̂y
125
126
info[:R̂u ] = mpc. R̂u
126
127
info = addinfo! (info, mpc)
@@ -296,16 +297,14 @@ function linconstraint!(mpc::PredictiveController, ::SimModel)
296
297
end
297
298
298
299
@doc raw """
299
- predict!(Ŷ, x̂, _ , _ , mpc::PredictiveController, model::LinModel, ΔŨ) -> Ŷ, x̂end
300
+ predict!(Ŷ, x̂, _ , _ , _ , mpc::PredictiveController, model::LinModel, ΔŨ) -> Ŷ, x̂end
300
301
301
302
Compute the predictions `Ŷ` and terminal states `x̂end` if model is a [`LinModel`](@ref).
302
303
303
304
The method mutates `Ŷ` and `x̂` vector arguments. The `x̂end` vector is used for
304
305
the terminal constraints applied on ``\m athbf{x̂}_{k-1}(k+H_p)``.
305
306
"""
306
- function predict! (
307
- Ŷ, x̂, _ , _ , mpc:: PredictiveController , :: LinModel , ΔŨ:: Vector{NT}
308
- ) where {NT<: Real }
307
+ function predict! (Ŷ, x̂, _ , _ , _ , mpc:: PredictiveController , :: LinModel , ΔŨ)
309
308
# in-place operations to reduce allocations :
310
309
Ŷ .= mul! (Ŷ, mpc. Ẽ, ΔŨ) .+ mpc. F
311
310
x̂ .= mul! (x̂, mpc. con. ẽx̂, ΔŨ) .+ mpc. con. fx̂
@@ -314,15 +313,13 @@ function predict!(
314
313
end
315
314
316
315
@doc raw """
317
- predict!(Ŷ, x̂, x̂next, u, mpc::PredictiveController, model::SimModel, ΔŨ) -> Ŷ, x̂end
316
+ predict!(Ŷ, x̂, x̂next, u, û, mpc::PredictiveController, model::SimModel, ΔŨ) -> Ŷ, x̂end
318
317
319
318
Compute both vectors if `model` is not a [`LinModel`](@ref).
320
319
321
- The method mutates `Ŷ`, `x̂`, `x̂next` and `u ` arguments.
320
+ The method mutates `Ŷ`, `x̂`, `x̂next`, `u` and `û ` arguments.
322
321
"""
323
- function predict! (
324
- Ŷ, x̂, x̂next, u, mpc:: PredictiveController , model:: SimModel , ΔŨ:: Vector{NT}
325
- ) where {NT<: Real }
322
+ function predict! (Ŷ, x̂, x̂next, u, û, mpc:: PredictiveController , model:: SimModel , ΔŨ)
326
323
nu, ny, nd, Hp, Hc = model. nu, model. ny, model. nd, mpc. Hp, mpc. Hc
327
324
u0 = u
328
325
x̂ .= mpc. estim. x̂
@@ -332,7 +329,7 @@ function predict!(
332
329
if j ≤ Hc
333
330
u0 .+ = @views ΔŨ[(1 + nu* (j- 1 )): (nu* j)]
334
331
end
335
- f̂! (x̂next, mpc. estim, model, x̂, u0, d0)
332
+ f̂! (x̂next, û, mpc. estim, model, x̂, u0, d0)
336
333
x̂ .= x̂next
337
334
d0 = @views mpc. D̂0[(1 + nd* (j- 1 )): (nd* j)]
338
335
ŷ = @views Ŷ[(1 + ny* (j- 1 )): (ny* j)]
@@ -352,9 +349,7 @@ The function is called by the nonlinear optimizer of [`NonLinMPC`](@ref) control
352
349
also be called on any [`PredictiveController`](@ref)s to evaluate the objective function `J`
353
350
at specific input increments `ΔŨ` and predictions `Ŷ` values. It mutates the `U` argument.
354
351
"""
355
- function obj_nonlinprog! (
356
- U , _ , _ , mpc:: PredictiveController , model:: LinModel , Ŷ, ΔŨ:: Vector{NT}
357
- ) where {NT<: Real }
352
+ function obj_nonlinprog! (U, _ , _ , mpc:: PredictiveController , model:: LinModel , Ŷ, ΔŨ)
358
353
J = obj_quadprog (ΔŨ, mpc. H̃, mpc. q̃) + mpc. p[]
359
354
if ! iszero (mpc. E)
360
355
U .= mul! (U, mpc. S̃, ΔŨ) .+ mpc. T_lastu
@@ -373,9 +368,7 @@ function `dot(x, A, x)` is a performant way of calculating `x'*A*x`. This method
373
368
`U`, `Ȳ` and `Ū` arguments (input over `Hp`, and output and input setpoint tracking error,
374
369
respectively).
375
370
"""
376
- function obj_nonlinprog! (
377
- U, Ȳ, Ū, mpc:: PredictiveController , model:: SimModel , Ŷ, ΔŨ:: Vector{NT}
378
- ) where {NT<: Real }
371
+ function obj_nonlinprog! (U, Ȳ, Ū, mpc:: PredictiveController , model:: SimModel , Ŷ, ΔŨ)
379
372
# --- output setpoint tracking term ---
380
373
Ȳ .= mpc. R̂y .- Ŷ
381
374
JR̂y = dot (Ȳ, mpc. M_Hp, Ȳ)
0 commit comments