Skip to content

Commit d9f174e

Browse files
committed
added: :gc field in getinfo dict for NonLinMPC
1 parent 311cfa3 commit d9f174e

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/controller/execute.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ The function should be called after calling [`moveinput!`](@ref). It returns the
9696
- `:d` : current measured disturbance, ``\mathbf{d}(k)``
9797
9898
For [`LinMPC`](@ref) and [`NonLinMPC`](@ref), the field `:sol` also contains the optimizer
99-
solution summary that can be printed. Lastly, the optimal economic cost `:JE` is also
100-
available for [`NonLinMPC`](@ref).
99+
solution summary that can be printed. Lastly, the economical cost `:JE` and the custom
100+
nonlinear constraints `:gc` values at the optimum are also available for [`NonLinMPC`](@ref).
101101
102102
# Examples
103103
```jldoctest
@@ -131,14 +131,14 @@ function getinfo(mpc::PredictiveController{NT}) where NT<:Real
131131
Ŷs .= mpc.F # predictstoch! init mpc.F with Ŷs value if estim is an InternalModel
132132
mpc.F .= oldF # restore old F value
133133
info[:ΔU] = mpc.ΔŨ[1:mpc.Hc*model.nu]
134-
info[] = mpc.== 1 ? mpc.ΔŨ[end] : NaN
134+
info[] = mpc.== 1 ? mpc.ΔŨ[end] : zero(NT)
135135
info[:J] = J
136136
info[:U] = U
137137
info[:u] = info[:U][1:model.nu]
138138
info[:d] = mpc.d0 + model.dop
139139
info[:D̂] = mpc.D̂0 + mpc.Dop
140140
info[:ŷ] = mpc.
141-
info[:Ŷ] = Ŷ0 + mpc.Yop
141+
info[:Ŷ] =
142142
info[:x̂end] = x̂0end + mpc.estim.x̂op
143143
info[:Ŷs] = Ŷs
144144
info[:R̂y] = mpc.R̂y

src/controller/nonlinmpc.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ function test_custom_functions(NT, model::SimModel, JE, gc!, nc, Uop, Yop, Dop,
423423
exception=(err, catch_backtrace())
424424
)
425425
end
426-
ϵ, gc = 0, Vector{NT}(undef, nc)
426+
ϵ, gc = zero(NT), Vector{NT}(undef, nc)
427427
try
428428
gc!(gc, Ue, Ŷe, D̂e, p, ϵ)
429429
catch err
@@ -444,12 +444,16 @@ end
444444
445445
For [`NonLinMPC`](@ref), add `:sol` and the optimal economic cost `:JE`.
446446
"""
447-
function addinfo!(info, mpc::NonLinMPC)
448-
U, Ŷ, D̂, ŷ, d = info[:U], info[:Ŷ], info[:D̂], info[:ŷ], info[:d]
447+
function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
448+
U, Ŷ, D̂, ŷ, d, ϵ = info[:U], info[:Ŷ], info[:D̂], info[:ŷ], info[:d], info[]
449449
Ue = [U; U[(end - mpc.estim.model.nu + 1):end]]
450450
Ŷe = [ŷ; Ŷ]
451-
D̂e = [d; D̂]
452-
info[:JE] = mpc.JE(Ue, Ŷe, D̂e, mpc.p)
451+
D̂e = [d; D̂]
452+
JE = mpc.JE(Ue, Ŷe, D̂e, mpc.p)
453+
LHS = Vector{NT}(undef, mpc.con.nc)
454+
mpc.con.gc!(LHS, Ue, Ŷe, D̂e, mpc.p, ϵ)
455+
info[:JE] = JE
456+
info[:gc] = LHS
453457
info[:sol] = JuMP.solution_summary(mpc.optim, verbose=true)
454458
return info
455459
end

src/estimator/mhe/execute.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function getinfo(estim::MovingHorizonEstimator{NT}) where NT<:Real
134134
end
135135
info[:Ŵ] = estim.Ŵ[1:Nk*nŵ]
136136
info[:x̂arr] = x̂0arr + estim.x̂op
137-
info[] = 0 ? estim.Z̃[begin] : NaN
137+
info[] = 0 ? estim.Z̃[begin] : zero(NT)
138138
info[:J] = obj_nonlinprog!(x̄, estim, estim.model, V̂, estim.Z̃)
139139
info[:X̂] = X̂0 .+ @views [estim.x̂op; estim.X̂op[1:nx̂*Nk]]
140140
info[:x̂] = estim.x̂0 .+ estim.x̂op

0 commit comments

Comments
 (0)