@@ -106,9 +106,9 @@ function getinfo(mpc::PredictiveController{NT}) where NT<:Real
106106 info = Dict {Symbol, Union{JuMP._SolutionSummary, Vector{NT}, NT}} ()
107107 Ŷ, x̂, u = similar (mpc. Ŷop), similar (mpc. estim. x̂), similar (mpc. estim. lastu0)
108108 Ŷ, 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
110110 Ȳ, Ū = similar (Ŷ), similar (U)
111- J = obj_nonlinprog! (Ȳ, Ū, u, mpc, mpc. estim. model, Ŷ, mpc. ΔŨ)
111+ J = obj_nonlinprog! (Ȳ, Ū, mpc, mpc. estim. model, Ŷ, mpc. ΔŨ)
112112 info[:ΔU ] = mpc. ΔŨ[1 : mpc. Hc* mpc. estim. model. nu]
113113 info[:ϵ ] = isinf (mpc. C) ? NaN : mpc. ΔŨ[end ]
114114 info[:J ] = J
@@ -155,6 +155,7 @@ They are computed with these equations using in-place operations:
155155```
156156"""
157157function initpred! (mpc:: PredictiveController , model:: LinModel , d, ym, D̂, R̂y, R̂u)
158+ mul! (mpc. T_lastu, mpc. T, mpc. estim. lastu0 .+ model. uop)
158159 ŷ, F, q̃, p = mpc. ŷ, mpc. F, mpc. q̃, mpc. p
159160 ŷ .= evalŷ (mpc. estim, ym, d)
160161 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,
177178 p .= dot (C_y, mpc. M_Hp, C_y)
178179 if ~ mpc. noR̂u
179180 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
182182 mpc. q̃ .+ = lmul! (2 , (mpc. L_Hp* mpc. S̃)' * C_u)
183183 mpc. p .+ = dot (C_y, mpc. L_Hp, C_u)
184184 end
@@ -195,6 +195,7 @@ Init `ŷ, Ŷop, d0, D̂0` matrices when model is not a [`LinModel`](@ref).
195195[`InternalModel`](@ref).
196196"""
197197function initpred! (mpc:: PredictiveController , model:: SimModel , d, ym, D̂, R̂y, R̂u)
198+ mul! (mpc. T_lastu, mpc. T, mpc. estim. lastu0 .+ model. uop)
198199 mpc. ŷ .= evalŷ (mpc. estim, ym, d)
199200 predictstoch! (mpc, mpc. estim, d, ym) # init mpc.Ŷop for InternalModel
200201 if model. nd ≠ 0
@@ -256,10 +257,9 @@ function linconstraint!(mpc::PredictiveController, model::LinModel)
256257 fx̂ .+ = mul! (fx̂_LHS, mpc. con. gx̂, mpc. d0)
257258 fx̂ .+ = mul! (fx̂_LHS, mpc. con. jx̂, mpc. D̂0)
258259 end
259- T_lastu = mpc. T* (mpc. estim. lastu0 .+ model. uop)
260260 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
263263 - mpc. con. ΔŨmin
264264 + mpc. con. ΔŨmax
265265 - mpc. con. Ymin + mpc. F
273273
274274" Set `b` excluding predicted output constraints when `model` is not a [`LinModel`](@ref)."
275275function linconstraint! (mpc:: PredictiveController , model:: SimModel )
276- T_lastu = mpc. T* (mpc. estim. lastu0 .+ model. uop)
277276 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
280279 - mpc. con. ΔŨmin
281280 + mpc. con. ΔŨmax
282281 ]
@@ -331,23 +330,20 @@ function predict!(
331330end
332331
333332"""
334- obj_nonlinprog!( _ , _ , u , mpc::PredictiveController, model::LinModel, Ŷ, ΔŨ)
333+ obj_nonlinprog!( _ , _ , mpc::PredictiveController, model::LinModel, Ŷ, ΔŨ)
335334
336335Nonlinear programming objective function when `model` is a [`LinModel`](@ref).
337336
338337The function is called by the nonlinear optimizer of [`NonLinMPC`](@ref) controllers. It can
339338also 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.
342340"""
343341function obj_nonlinprog! (
344- _ , _ , u , mpc:: PredictiveController , model:: LinModel , Ŷ, ΔŨ:: Vector{NT}
342+ _ , _ , mpc:: PredictiveController , model:: LinModel , Ŷ, ΔŨ:: Vector{NT}
345343) where {NT<: Real }
346344 J = obj_quadprog (ΔŨ, mpc. H̃, mpc. q̃) + mpc. p[]
347345 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
351347 UE = [U; U[(end - model. nu + 1 ): end ]]
352348 ŶE = [mpc. ŷ; Ŷ]
353349 J += mpc. E* mpc. JE (UE, ŶE, mpc. D̂E)
@@ -356,14 +352,14 @@ function obj_nonlinprog!(
356352end
357353
358354"""
359- obj_nonlinprog!(Ȳ, Ū, u, mpc::PredictiveController, model::SimModel, Ŷ, ΔŨ)
355+ obj_nonlinprog!(Ȳ, Ū, mpc::PredictiveController, model::SimModel, Ŷ, ΔŨ)
360356
361357Nonlinear programming objective function when `model` is not a [`LinModel`](@ref). The
362358function `dot(x, A, x)` is a performant way of calculating `x'*A*x`. This method mutates
363359`Ȳ` and `Ū` vector arguments (output and input setpoint tracking error, respectively).
364360"""
365361function obj_nonlinprog! (
366- Ȳ, Ū, u, mpc:: PredictiveController , model:: SimModel , Ŷ, ΔŨ:: Vector{NT}
362+ Ȳ, Ū, mpc:: PredictiveController , model:: SimModel , Ŷ, ΔŨ:: Vector{NT}
367363) where {NT<: Real }
368364 # --- output setpoint tracking term ---
369365 Ȳ .= mpc. R̂y .- Ŷ
@@ -372,9 +368,7 @@ function obj_nonlinprog!(
372368 JΔŨ = dot (ΔŨ, mpc. Ñ_Hc, ΔŨ)
373369 # --- input over prediction horizon ---
374370 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
378372 end
379373 # --- input setpoint tracking term ---
380374 if ! mpc. noR̂u
0 commit comments