Skip to content

Commit c5eff2a

Browse files
committed
added: smarter initstate! for non-SingleShooting
1 parent bf93872 commit c5eff2a

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

docs/src/internals/predictive_control.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ ModelPredictiveControl.get_nonlinobj_op(::NonLinMPC, ::ModelPredictiveControl.Ge
3030
ModelPredictiveControl.get_nonlincon_oracle(::NonLinMPC, ::ModelPredictiveControl.GenericModel)
3131
```
3232

33+
## Init Decision Vector
34+
35+
```@docs
36+
ModelPredictiveControl.init_decision!
37+
```
38+
3339
## Update Quadratic Optimization
3440

3541
```@docs

src/controller/execute.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
@doc raw"""
22
initstate!(mpc::PredictiveController, u, ym, d=[]) -> x̂
33
4-
Init the states of `mpc.estim` [`StateEstimator`](@ref) and warm start `mpc.Z̃` at zero.
4+
Init the states of `mpc.estim` [`StateEstimator`](@ref) and the warm start value `mpc.Z̃`.
55
66
It also stores `u - mpc.estim.model.uop` at `mpc.lastu0` for converting the input increments
7-
``\mathbf{ΔU}`` to inputs ``\mathbf{U}``.
7+
``\mathbf{ΔU}`` to inputs ``\mathbf{U}``. See [`init_decision!`](@ref) for details on how
8+
`mpc.Z̃` is initialized. The function returns the initial state estimate `x̂`.
89
"""
910
function initstate!(mpc::PredictiveController, u, ym, d=mpc.estim.buffer.empty)
10-
mpc.Z̃ .= 0
11+
= initstate!(mpc.estim, u, ym, d)
1112
mpc.lastu0 .= u .- mpc.estim.model.uop
12-
return initstate!(mpc.estim, u, ym, d)
13+
init_decision!(mpc, mpc.transcription, x̂)
14+
return
1315
end
1416

1517
@doc raw"""

src/controller/transcription.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,32 @@ function init_matconstraint_mpc(
766766
return i_b, i_g, A, Aeq, neq
767767
end
768768

769+
@doc raw"""
770+
init_decision!(mpc::PredictiveController, ::SingleShooting)
771+
772+
Init the decision vector ``\mathbf{Z̃ = ΔŨ}`` with zeros for [`SingleShooting`](@ref).
773+
"""
774+
init_decision!(mpc::PredictiveController, ::SingleShooting, _) = (mpc.Z̃ .= 0; nothing)
775+
776+
@dow raw"""
777+
init_decision!(mpc::PredictiveController, ::TranscriptionMethod)
778+
779+
Also init the state part of the decision vector for other [`TranscriptionMethod`](@ref)s.
780+
781+
The ``\mathbf{X̂_0}`` component is assumed constant over ``H_p`` at the current value stored
782+
in `mpc.estim.x̂0`.
783+
"""
784+
function init_decision!(mpc::PredictiveController, ::TranscriptionMethod)
785+
nΔU, nx̂ = mpc.Hc*mpc.model.nu, mpc.estim.nx̂
786+
mpc.Z̃ .= 0
787+
for j=1:mpc.Hp
788+
iRow = nΔU .+ (1:nx̂) .+ nx̂*(j-1)
789+
mpc.Z̃[iRow] .= mpc.estim.x̂0
790+
end
791+
return nothing
792+
end
793+
794+
769795
@doc raw"""
770796
linconstraint!(mpc::PredictiveController, model::LinModel)
771797

0 commit comments

Comments
 (0)