Skip to content

Commit 22ddc05

Browse files
committed
warm-stat ΔŨ with unconstrained_solution
1 parent 14639b4 commit 22ddc05

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

example/juMPC.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ mpcluen = LinMPC(luenberger)
6060
mpcexplicit = ExplicitMPC(LinModel(append(tf(3,[2, 1]), tf(2, [6, 1])), 0.1), Hp=10000, Hc=1)
6161
moveinput!(mpcexplicit, [10, 10])
6262

63-
#=
63+
6464
kalmanFilter1 = KalmanFilter(linModel1)
6565
kalmanFilter2 = KalmanFilter(linModel1,nint_ym=0)
6666

@@ -212,4 +212,3 @@ display(pu)
212212
display(py)
213213
214214
=#
215-
=#

src/predictive_control.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,18 @@ Set the estimate at `mpc.estim.x̂`.
328328
"""
329329
setstate!(mpc::PredictiveController, x̂) = (setstate!(mpc.estim, x̂); return mpc)
330330

331-
"""
331+
@doc raw"""
332332
initstate!(mpc::PredictiveController, u, ym, d=Float64[])
333333
334334
Init `mpc.ΔŨ` for warm-starting and the states of `mpc.estim` [`StateEstimator`](@ref).
335+
336+
Before calling [`initstate!(::StateEstimator,::Any,::Any,::Any)`](@ref), it warm-starts ``\mathbf{ΔŨ}``:
337+
- If `model` is a [`LinModel`], the vector is filled with the analytical minimum ``J`` of
338+
the unconstrained problem.
339+
- Else, the vector is filled with zeros.
335340
"""
336341
function initstate!(mpc::PredictiveController, u, ym, d=Float64[])
337-
mpc.ΔŨ .= 0
342+
mpc.ΔŨ[:] = unconstrained_solution(mpc, mpc.estim.model)
338343
return initstate!(mpc.estim, u, ym, d)
339344
end
340345

@@ -730,6 +735,13 @@ end
730735
"Return the quadratic programming objective function, see [`init_quadprog`](@ref)."
731736
obj_quadprog(ΔŨ, P̃, q̃) = 0.5*ΔŨ'**ΔŨ +'*ΔŨ
732737

738+
739+
"Calc the analytical unconstrained minimum of ``J`` for [`LinModel`](@ref)."
740+
unconstrained_solution(mpc::PredictiveController, model::LinModel) = -mpc.\mpc.
741+
742+
"When model is not a `LinModel`(@ref), returns a null vector ``\\mathbf{0}``."
743+
unconstrained_solution(mpc::PredictiveController, ::SimModel) = zeros(size(mpc.ΔŨ))
744+
733745
"""
734746
init_defaultcon(model, C, S_Hp, S_Hc, N_Hc, E) -> con, S̃_Hp, Ñ_Hc, Ẽ
735747
@@ -1024,6 +1036,9 @@ function isfatal(status::TerminationStatusCode)
10241036
return any(status .== fatalstatuses)
10251037
end
10261038

1039+
1040+
1041+
10271042
"Functor allowing callable `PredictiveController` object as an alias for `moveinput!`."
10281043
function (mpc::PredictiveController)(
10291044
ry::Vector = mpc.estim.model.yop,

0 commit comments

Comments
 (0)