Skip to content

Commit 27f980f

Browse files
committed
renamed : evalYhat to predict
1 parent 55d5a59 commit 27f980f

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

src/controller/nonlinmpc.jl

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct NonLinMPC{S<:StateEstimator, JEFunc<:Function} <: PredictiveController
7777
last_ΔŨ, last_C, last_Ŷ = nothing, nothing, nothing
7878
function Jfunc(ΔŨ::Float64...)
7979
if ΔŨ !== last_ΔŨ
80-
last_Ŷ = evalŶ(mpc, model, ΔŨ)
80+
last_Ŷ = predict(mpc, model, ΔŨ)
8181
last_C = con_nonlinprog(mpc, model, last_Ŷ, ΔŨ)
8282
last_ΔŨ = ΔŨ
8383
end
@@ -86,7 +86,7 @@ struct NonLinMPC{S<:StateEstimator, JEFunc<:Function} <: PredictiveController
8686
last_dΔŨ, last_dC, last_dŶ = nothing, nothing, nothing
8787
function Jfunc(dΔŨ::T...) where {T<:Real}
8888
if dΔŨ !== last_dΔŨ
89-
last_dŶ = evalŶ(mpc, model, dΔŨ)
89+
last_dŶ = predict(mpc, model, dΔŨ)
9090
last_dC = con_nonlinprog(mpc, model, last_dŶ, dΔŨ)
9191
last_dΔŨ = dΔŨ
9292
end
@@ -97,15 +97,15 @@ struct NonLinMPC{S<:StateEstimator, JEFunc<:Function} <: PredictiveController
9797
ncon = length(mpc.con.Ŷmin) + length(mpc.con.Ŷmax)
9898
function con_nonlinprog_i(i, ΔŨ::NTuple{N, Float64}) where {N}
9999
if ΔŨ !== last_ΔŨ
100-
last_Ŷ = evalŶ(mpc, model, ΔŨ)
100+
last_Ŷ = predict(mpc, model, ΔŨ)
101101
last_C = con_nonlinprog(mpc, model, last_Ŷ, ΔŨ)
102102
last_ΔŨ = ΔŨ
103103
end
104104
return last_C[i]
105105
end
106106
function con_nonlinprog_i(i, dΔŨ::NTuple{N, T}) where {N, T<:Real}
107107
if dΔŨ !== last_dΔŨ
108-
last_dŶ = evalŶ(mpc, model, dΔŨ)
108+
last_dŶ = predict(mpc, model, dΔŨ)
109109
last_dC = con_nonlinprog(mpc, model, last_dŶ, dΔŨ)
110110
last_dΔŨ = dΔŨ
111111
end
@@ -338,35 +338,4 @@ function con_nonlinprog(mpc::NonLinMPC, ::SimModel, Ŷ, ΔŨ::NTuple{N, T}) wh
338338
C_Ŷmax[isinf.(C_Ŷmax)] .= 0
339339
C = [C_Ŷmin; C_Ŷmax]
340340
return C
341-
end
342-
343-
344-
"""
345-
evalŶ(mpc::NonLinMPC, model::LinModel, x̂d, d0, D̂0, U0::Vector{T}) where {T}
346-
347-
Evaluate the outputs predictions ``\\mathbf{Ŷ}`` when `model` is a [`LinModel`](@ref).
348-
"""
349-
function evalŶ(mpc::NonLinMPC, ::LinModel, ΔŨ::NTuple{N, T}) where {N, T}
350-
ΔŨ = collect(ΔŨ) # convert NTuple to Vector
351-
return mpc.*ΔŨ + mpc.F
352-
end
353-
354-
"""
355-
evalŶ(mpc::NonLinMPC, model::SimModel, x̂d, d0, D̂0, U0::Vector{T}) where {T}
356-
357-
Evaluate ``\\mathbf{Ŷ}`` when `model` is not a [`LinModel`](@ref).
358-
"""
359-
function evalŶ(mpc::NonLinMPC, model::SimModel, ΔŨ::NTuple{N, T}) where {N, T}
360-
ΔŨ = collect(ΔŨ) # convert NTuple to Vector
361-
U0 = mpc.S̃_Hp*ΔŨ + mpc.T_Hp*(mpc.estim.lastu0)
362-
Ŷd = Vector{T}(undef, model.ny*mpc.Hp)
363-
x̂d::Vector{T} = copy(mpc.x̂d)
364-
d0 = mpc.d0
365-
for j=1:mpc.Hp
366-
u0 = U0[(1 + model.nu*(j-1)):(model.nu*j)]
367-
x̂d[:] = f(model, x̂d, u0, d0)
368-
d0 = mpc.D̂0[(1 + model.nd*(j-1)):(model.nd*j)]
369-
Ŷd[(1 + model.ny*(j-1)):(model.ny*j)] = h(model, x̂d, d0) + model.yop
370-
end
371-
return Ŷd + mpc.Ŷs
372341
end

src/predictive_control.jl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ Init linear model prediction matrices `F`, `q̃` and `p`.
347347
See [`init_deterpred`](@ref) and [`init_quadprog`](@ref) for the definition of the matrices.
348348
"""
349349
function initpred!(mpc::PredictiveController, model::LinModel, d, D̂, R̂y)
350-
mpc.F[:] = mpc.Kd*mpc.x̂d + mpc.Q*mpc.estim.lastu0 + mpc.Ŷs + mpc.Yop
350+
mpc.F[:] = mpc.Kd*mpc.x̂d + mpc.Q*mpc.estim.lastu0 + mpc.Yop + mpc.Ŷs
351351
if model.nd 0
352352
mpc.d0[:], mpc.D̂0[:] = d - model.dop, D̂ - mpc.Dop
353353
mpc.F[:] = mpc.F + mpc.G*mpc.d0 + mpc.J*mpc.D̂0
@@ -368,7 +368,7 @@ end
368368
@doc raw"""
369369
initpred!(mpc::PredictiveController, model::SimModel, d, D̂, Ŷs, R̂y )
370370
371-
Init `d0` and `D̂0` prediction matrices when model is not a [`LinModel`](@ref).
371+
Init `d0` and `D̂0` matrices when model is not a [`LinModel`](@ref).
372372
373373
`d0` and `D̂0` are the measured disturbances and its predictions without the operating points
374374
``\mathbf{d_{op}}``.
@@ -382,6 +382,36 @@ function initpred!(mpc::PredictiveController, model::SimModel, d, D̂, R̂y)
382382
return p
383383
end
384384

385+
"""
386+
predict(mpc::PredictiveController, model::LinModel, ΔŨ)
387+
388+
Evaluate the outputs predictions ``\\mathbf{Ŷ}`` when `model` is a [`LinModel`](@ref).
389+
"""
390+
function predict(mpc::PredictiveController, ::LinModel, ΔŨ::NTuple{N, T}) where {N, T}
391+
ΔŨ = collect(ΔŨ) # convert NTuple to Vector
392+
return mpc.*ΔŨ + mpc.F
393+
end
394+
395+
"""
396+
predict(mpc::PredictiveController, model::SimModel, ΔŨ)
397+
398+
Evaluate ``\\mathbf{Ŷ}`` when `model` is not a [`LinModel`](@ref).
399+
"""
400+
function predict(mpc::PredictiveController, model::SimModel, ΔŨ::NTuple{N, T}) where {N, T}
401+
ΔŨ = collect(ΔŨ) # convert NTuple to Vector
402+
U0 = mpc.S̃_Hp*ΔŨ + mpc.T_Hp*(mpc.estim.lastu0)
403+
Ŷd = Vector{T}(undef, model.ny*mpc.Hp)
404+
x̂d::Vector{T} = copy(mpc.x̂d)
405+
d0 = mpc.d0
406+
for j=1:mpc.Hp
407+
u0 = U0[(1 + model.nu*(j-1)):(model.nu*j)]
408+
x̂d[:] = f(model, x̂d, u0, d0)
409+
d0 = mpc.D̂0[(1 + model.nd*(j-1)):(model.nd*j)]
410+
Ŷd[(1 + model.ny*(j-1)):(model.ny*j)] = h(model, x̂d, d0) + model.yop
411+
end
412+
return Ŷd + mpc.Ŷs
413+
end
414+
385415
@doc raw"""
386416
linconstraint!(mpc::PredictiveController, model::LinModel)
387417

0 commit comments

Comments
 (0)