Skip to content

Commit 20f8634

Browse files
authored
Merge pull request #339 from JuliaControl/getinfo_states
added: current estimate `x̂` and last input `lastu` in `getinfo` dictionnary for MPCs
2 parents 4aee803 + dd66aed commit 20f8634

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ModelPredictiveControl"
22
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
3-
version = "2.1.2"
3+
version = "2.2.0"
44
authors = ["Francis Gagnon"]
55

66
[deps]

src/controller/execute.jl

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,18 @@ The function should be called after calling [`moveinput!`](@ref). It returns the
9393
- `:ΔU` or *`:DeltaU`* : optimal manipulated input increments over ``H_c``, ``\mathbf{ΔU}``
9494
- `:ϵ` or *`:epsilon`* : optimal slack variable, ``ϵ``
9595
- `:D̂` or *`:Dhat`* : predicted measured disturbances over ``H_p``, ``\mathbf{D̂}``
96+
- `:x̂` or *`:xhat`* : current estimated state, ``\mathbf{x̂}_i(k)``
9697
- `:ŷ` or *`:yhat`* : current estimated output, ``\mathbf{ŷ}(k)``
9798
- `:Ŷ` or *`:Yhat`* : optimal predicted outputs over ``H_p``, ``\mathbf{Ŷ}``
9899
- `:Ŷs` or *`:Yhats`* : predicted stochastic output over ``H_p`` of [`InternalModel`](@ref), ``\mathbf{Ŷ_s}``
99100
- `:R̂y` or *`:Rhaty`* : predicted output setpoint over ``H_p``, ``\mathbf{R̂_y}``
100101
- `:R̂u` or *`:Rhatu`* : predicted manipulated input setpoint over ``H_p``, ``\mathbf{R̂_u}``
101102
- `:x̂end` or *`:xhatend`* : optimal terminal states, ``\mathbf{x̂}_i(k+H_p)``
102-
- `:J` : objective value optimum, ``J``
103-
- `:U` : optimal manipulated inputs over ``H_p``, ``\mathbf{U}``
104-
- `:u` : current optimal manipulated input, ``\mathbf{u}(k)``
105-
- `:d` : current measured disturbance, ``\mathbf{d}(k)``
103+
- `:J` : objective value optimum, ``J``
104+
- `:U` : optimal manipulated inputs over ``H_p``, ``\mathbf{U}``
105+
- `:u` : current optimal manipulated input, ``\mathbf{u}(k)``
106+
- `:d` : current measured disturbance, ``\mathbf{d}(k)``
107+
- `:lastu` : last manipulated input, ``\mathbf{u}(k-1)``
106108
107109
For [`LinMPC`](@ref) and [`NonLinMPC`](@ref), the following fields are also available:
108110
@@ -160,23 +162,26 @@ function getinfo(mpc::PredictiveController{NT}) where NT<:Real
160162
J = obj_nonlinprog!(Ŷ0, U0, mpc, Ue, Ŷe, ΔŨ)
161163
Ŷs = similar(mpc.Yop)
162164
predictstoch!(Ŷs, mpc, mpc.estim)
163-
info[:ΔU] = Z̃[1:mpc.Hc*model.nu]
164-
info[] = getϵ(mpc, Z̃)
165-
info[:J] = J
166-
info[:U] = U
167-
info[:u] = info[:U][1:model.nu]
168-
info[:d] = mpc.d0 + model.dop
169-
info[:D̂] =
170-
info[:ŷ] = mpc.
171-
info[:Ŷ] =
172-
info[:x̂end] = x̂0end + mpc.estim.x̂op
173-
info[:Ŷs] = Ŷs
174-
info[:R̂y] = mpc.R̂y
175-
info[:R̂u] = mpc.R̂u
165+
info[:ΔU] = Z̃[1:mpc.Hc*model.nu]
166+
info[] = getϵ(mpc, Z̃)
167+
info[:J] = J
168+
info[:U] = U
169+
info[:u] = info[:U][1:model.nu]
170+
info[:lastu] = mpc.lastu0 .+ model.uop
171+
info[:d] = mpc.d0 + model.dop
172+
info[:D̂] =
173+
info[:x̂] = mpc.estim.x̂0 .+ mpc.estim.x̂op
174+
info[:ŷ] = mpc.
175+
info[:Ŷ] =
176+
info[:x̂end] = x̂0end + mpc.estim.x̂op
177+
info[:Ŷs] = Ŷs
178+
info[:R̂y] = mpc.R̂y
179+
info[:R̂u] = mpc.R̂u
176180
# --- non-Unicode fields ---
177181
info[:DeltaU] = info[:ΔU]
178182
info[:epsilon] = info[]
179183
info[:Dhat] = info[:D̂]
184+
info[:xhat] = info[:x̂]
180185
info[:yhat] = info[:ŷ]
181186
info[:Yhat] = info[:Ŷ]
182187
info[:xhatend] = info[:x̂end]

src/general.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const HIDDEN_GETINFO_KEYS_MHE = (
2222
)
2323

2424
const HIDDEN_GETINFO_KEYS_MPC = (
25-
:DeltaU, :epsilon, :Dhat, :yhat, :Yhat, :xhatend, :Yhats, :Rhaty, :Rhatu,
25+
:DeltaU, :epsilon, :Dhat, :xhat, :yhat, :Yhat, :xhatend, :Yhats, :Rhaty, :Rhatu,
2626
:nablaJ, :nabla2J, :nablag, :nabla2lg, :nablageq, :nabla2lgeq
2727
)
2828

0 commit comments

Comments
 (0)