@@ -103,24 +103,25 @@ julia> round.(getinfo(mpc)[:Ŷ], digits=3)
103103```
104104"""
105105function getinfo (mpc:: PredictiveController{NT} ) where NT<: Real
106+ model = mpc. estim. model
106107 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 )
108109 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. ΔŨ)
110111 U = mpc. S̃* mpc. ΔŨ + mpc. T_lastu
111112 Ȳ, Ū = 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]
114115 info[:ϵ ] = isinf (mpc. C) ? NaN : mpc. ΔŨ[end ]
115116 info[:J ] = J
116117 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
119120 info[:D̂ ] = mpc. D̂0 + mpc. Dop
120121 info[:ŷ ] = mpc. ŷ
121122 info[:Ŷ ] = Ŷ
122123 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
124125 info[:R̂y ] = mpc. R̂y
125126 info[:R̂u ] = mpc. R̂u
126127 info = addinfo! (info, mpc)
@@ -296,16 +297,14 @@ function linconstraint!(mpc::PredictiveController, ::SimModel)
296297end
297298
298299@doc raw """
299- predict!(Ŷ, x̂, _ , _ , mpc::PredictiveController, model::LinModel, ΔŨ) -> Ŷ, x̂end
300+ predict!(Ŷ, x̂, _ , _ , _ , mpc::PredictiveController, model::LinModel, ΔŨ) -> Ŷ, x̂end
300301
301302Compute the predictions `Ŷ` and terminal states `x̂end` if model is a [`LinModel`](@ref).
302303
303304The method mutates `Ŷ` and `x̂` vector arguments. The `x̂end` vector is used for
304305the terminal constraints applied on ``\m athbf{x̂}_{k-1}(k+H_p)``.
305306"""
306- function predict! (
307- Ŷ, x̂, _ , _ , mpc:: PredictiveController , :: LinModel , ΔŨ:: Vector{NT}
308- ) where {NT<: Real }
307+ function predict! (Ŷ, x̂, _ , _ , _ , mpc:: PredictiveController , :: LinModel , ΔŨ)
309308 # in-place operations to reduce allocations :
310309 Ŷ .= mul! (Ŷ, mpc. Ẽ, ΔŨ) .+ mpc. F
311310 x̂ .= mul! (x̂, mpc. con. ẽx̂, ΔŨ) .+ mpc. con. fx̂
@@ -314,15 +313,13 @@ function predict!(
314313end
315314
316315@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
318317
319318Compute both vectors if `model` is not a [`LinModel`](@ref).
320319
321- The method mutates `Ŷ`, `x̂`, `x̂next` and `u ` arguments.
320+ The method mutates `Ŷ`, `x̂`, `x̂next`, `u` and `û ` arguments.
322321"""
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 , ΔŨ)
326323 nu, ny, nd, Hp, Hc = model. nu, model. ny, model. nd, mpc. Hp, mpc. Hc
327324 u0 = u
328325 x̂ .= mpc. estim. x̂
@@ -332,7 +329,7 @@ function predict!(
332329 if j ≤ Hc
333330 u0 .+ = @views ΔŨ[(1 + nu* (j- 1 )): (nu* j)]
334331 end
335- f̂! (x̂next, mpc. estim, model, x̂, u0, d0)
332+ f̂! (x̂next, û, mpc. estim, model, x̂, u0, d0)
336333 x̂ .= x̂next
337334 d0 = @views mpc. D̂0[(1 + nd* (j- 1 )): (nd* j)]
338335 ŷ = @views Ŷ[(1 + ny* (j- 1 )): (ny* j)]
@@ -352,9 +349,7 @@ The function is called by the nonlinear optimizer of [`NonLinMPC`](@ref) control
352349also be called on any [`PredictiveController`](@ref)s to evaluate the objective function `J`
353350at specific input increments `ΔŨ` and predictions `Ŷ` values. It mutates the `U` argument.
354351"""
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 , Ŷ, ΔŨ)
358353 J = obj_quadprog (ΔŨ, mpc. H̃, mpc. q̃) + mpc. p[]
359354 if ! iszero (mpc. E)
360355 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
373368`U`, `Ȳ` and `Ū` arguments (input over `Hp`, and output and input setpoint tracking error,
374369respectively).
375370"""
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 , Ŷ, ΔŨ)
379372 # --- output setpoint tracking term ---
380373 Ȳ .= mpc. R̂y .- Ŷ
381374 JR̂y = dot (Ȳ, mpc. M_Hp, Ȳ)
0 commit comments