Skip to content

Commit ccc64e9

Browse files
committed
predict function received a vector instead of tuple
1 parent 27f980f commit ccc64e9

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/controller/nonlinmpc.jl

Lines changed: 4 additions & 4 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_Ŷ = predict(mpc, model, ΔŨ)
80+
last_Ŷ = predict(mpc, model, collect(ΔŨ))
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Ŷ = predict(mpc, model, dΔŨ)
89+
last_dŶ = predict(mpc, model, collect(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_Ŷ = predict(mpc, model, ΔŨ)
100+
last_Ŷ = predict(mpc, model, collect(ΔŨ))
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Ŷ = predict(mpc, model, dΔŨ)
108+
last_dŶ = predict(mpc, model, collect(dΔŨ))
109109
last_dC = con_nonlinprog(mpc, model, last_dŶ, dΔŨ)
110110
last_dΔŨ = dΔŨ
111111
end

src/predictive_control.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,7 @@ end
387387
388388
Evaluate the outputs predictions ``\\mathbf{Ŷ}`` when `model` is a [`LinModel`](@ref).
389389
"""
390-
function predict(mpc::PredictiveController, ::LinModel, ΔŨ::NTuple{N, T}) where {N, T}
391-
ΔŨ = collect(ΔŨ) # convert NTuple to Vector
390+
function predict(mpc::PredictiveController, ::LinModel, ΔŨ::Vector{T}) where {T<:Real}
392391
return mpc.*ΔŨ + mpc.F
393392
end
394393

@@ -397,8 +396,7 @@ end
397396
398397
Evaluate ``\\mathbf{Ŷ}`` when `model` is not a [`LinModel`](@ref).
399398
"""
400-
function predict(mpc::PredictiveController, model::SimModel, ΔŨ::NTuple{N, T}) where {N, T}
401-
ΔŨ = collect(ΔŨ) # convert NTuple to Vector
399+
function predict(mpc::PredictiveController, model::SimModel, ΔŨ::Vector{T}) where {T<:Real}
402400
U0 = mpc.S̃_Hp*ΔŨ + mpc.T_Hp*(mpc.estim.lastu0)
403401
Ŷd = Vector{T}(undef, model.ny*mpc.Hp)
404402
x̂d::Vector{T} = copy(mpc.x̂d)

0 commit comments

Comments
 (0)