@@ -52,9 +52,9 @@ julia> u = moveinput!(mpc, ry); round.(u, digits=3)
5252function moveinput! (
5353 mpc:: PredictiveController ,
5454 ry:: Vector = mpc. estim. model. yop,
55- d :: Vector = mpc. estim . buffer. empty;
56- Dhat :: Vector = repeat ( d, mpc. Hp),
57- Rhaty:: Vector = repeat ( ry, mpc. Hp),
55+ d :: Vector = mpc. buffer. empty;
56+ Dhat :: Vector = repeat! (mpc . buffer . D̂, d, mpc. Hp),
57+ Rhaty:: Vector = repeat! (mpc . buffer . R̂y, ry, mpc. Hp),
5858 Rhatu:: Vector = mpc. Uop,
5959 D̂ = Dhat,
6060 R̂y = Rhaty,
@@ -67,13 +67,9 @@ function moveinput!(
6767 initpred! (mpc, mpc. estim. model, d, D̂, R̂y, R̂u)
6868 linconstraint! (mpc, mpc. estim. model)
6969 ΔŨ = optim_objective! (mpc)
70- Δu = ΔŨ[1 : mpc. estim. model. nu] # receding horizon principle: only Δu(k) is used (1st one)
71- u = mpc. estim. lastu0 + mpc. estim. model. uop + Δu
72- return u
70+ return getinput (mpc, ΔŨ)
7371end
7472
75-
76-
7773@doc raw """
7874 getinfo(mpc::PredictiveController) -> info
7975
@@ -506,6 +502,24 @@ function preparestate!(mpc::PredictiveController, ym, d=mpc.estim.buffer.empty)
506502 return preparestate! (mpc. estim, ym, d)
507503end
508504
505+ @doc raw """
506+ getinput(mpc::PredictiveController, ΔŨ) -> u
507+
508+ Get current manipulated input `u` from a [`PredictiveController`](@ref) solution `ΔŨ`.
509+
510+ The first manipulated input ``\m athbf{u}(k)`` is extracted from the input increments vector
511+ ``\m athbf{ΔŨ}`` and applied on the plant (from the receding horizon principle).
512+ """
513+ function getinput (mpc, ΔŨ)
514+ Δu = mpc. buffer. u
515+ for i in 1 : mpc. estim. model. nu
516+ Δu[i] = ΔŨ[i]
517+ end
518+ u = Δu
519+ u .+ = mpc. estim. lastu0 .+ mpc. estim. model. uop
520+ return u
521+ end
522+
509523"""
510524 updatestate!(mpc::PredictiveController, u, ym, d=[]) -> x̂next
511525
0 commit comments