Skip to content

Commit e71817e

Browse files
committed
doc: add information about move blocking in public section
1 parent bccc161 commit e71817e

File tree

5 files changed

+32
-35
lines changed

5 files changed

+32
-35
lines changed

docs/src/internals/predictive_control.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The prediction methodology of this module is mainly based on Maciejowski textboo
1212
## Controller Construction
1313

1414
```@docs
15+
ModelPredictiveControl.move_blocking
1516
ModelPredictiveControl.init_ZtoΔU
1617
ModelPredictiveControl.init_ZtoU
1718
ModelPredictiveControl.init_predmat

src/controller/construct.jl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,26 +457,40 @@ end
457457
estimate_delays(::SimModel) = 0
458458

459459

460-
"""
460+
@doc raw"""
461461
move_blocking(Hp::Int, Hc::AbstractVector{Int}) -> nb
462462
463-
Get move blocking vector `nb` and actual control horizon from `Hp` and `Hc` arguments.
464-
465-
The argument `Hc` is in fact the move blocking vector `nb` provided by the user. The `nb`
466-
vector is modified in these two cases:
463+
Get the move blocking vector `nb` from the `Hc` argument, and modify it to match `Hp`.
467464
465+
The argument `Hc` is interpreted as the move blocking vector `nb`. It specifies the length
466+
of each step (or "block") in the ``\mathbf{ΔU}`` vector, to customize the pattern (strictly
467+
positive integers):
468+
```math
469+
\mathbf{n_b} = \begin{bmatrix} n_1 & n_2 & \cdots & n_{H_c} \end{bmatrix}'
470+
```
471+
The vector with all the manipulated input increments is then defined as:
472+
```math
473+
\mathbf{ΔU} = \begin{bmatrix}
474+
\mathbf{Δu}(k + 0) \\[0.1em]
475+
\mathbf{Δu}(k + ∑_{i=1}^1 n_i) \\[0.1em]
476+
\mathbf{Δu}(k + ∑_{i=1}^2 n_i) \\[0.1em]
477+
\vdots \\[0.1em]
478+
\mathbf{Δu}(k + ∑_{i=1}^{H_c-1} n_i)
479+
\end{bmatrix}
480+
```
481+
The provided `nb` vector is modified in these two cases:
468482
- If `sum(nb) < Hp`, a new element is pushed to `nb` with the value `Hp - sum(nb)`.
469483
- If `sum(nb) > Hp`, the intervals are truncated until the sum is `Hp`. For example, if
470484
`Hp = 10` and `nb = [1, 2, 3, 6, 7]`, then `nb` is truncated to `[1, 2, 3, 4]`.
471485
"""
472486
function move_blocking(Hp_arg::Int, Hc_arg::AbstractVector{Int})
473487
Hp = Hp_arg
474488
nb = Hc_arg
489+
all(>(0), nb) || throw(ArgumentError("Move blocking vector must be strictly positive integers."))
475490
if sum(nb) < Hp
476491
newblock = [Hp - sum(nb)]
477492
nb = [nb; newblock]
478493
elseif sum(nb) > Hp
479-
#For example, if Hp = 10 and nb = [1, 2, 3, 6, 7], than nb is truncated to [1, 2, 3, 4]
480494
nb = nb[begin:findfirst((Hp), cumsum(nb))]
481495
if sum(nb) > Hp
482496
# if the last block is too large, it is truncated to fit Hp:
@@ -489,7 +503,7 @@ end
489503
"""
490504
move_blocking(Hp::Int, Hc::Int) -> nb
491505
492-
Construct a move blocking vector `nb` that match the provided `Hp` and `Hc` horizons.
506+
Construct a move blocking vector `nb` that match the provided `Hp` and `Hc` integers.
493507
494508
The vector is filled with `1`s, except for the last element which is `Hp - Hc + 1`.
495509
"""

src/controller/linmpc.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ arguments. This controller allocates memory at each time step for the optimizati
146146
147147
# Arguments
148148
- `model::LinModel` : model used for controller predictions and state estimations.
149-
- `Hp=10+nk` : prediction horizon ``H_p``, `nk` is the number of delays in `model`.
150-
- `Hc=2` : control horizon ``H_c``.
149+
- `Hp::Int=10+nk` : prediction horizon ``H_p``, `nk` is the number of delays in `model`.
150+
- `Hc::Union{Int, Vector{Int}}=2` : control horizon ``H_c``, custom move blocking is
151+
specified with a vector of integers (see [`move_blocking`](@ref) for details).
151152
- `Mwt=fill(1.0,model.ny)` : main diagonal of ``\mathbf{M}`` weight matrix (vector).
152153
- `Nwt=fill(0.1,model.nu)` : main diagonal of ``\mathbf{N}`` weight matrix (vector).
153154
- `Lwt=fill(0.0,model.nu)` : main diagonal of ``\mathbf{L}`` weight matrix (vector).

src/controller/nonlinmpc.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ This controller allocates memory at each time step for the optimization.
189189
190190
# Arguments
191191
- `model::SimModel` : model used for controller predictions and state estimations.
192-
- `Hp=nothing`: prediction horizon ``H_p``, must be specified for [`NonLinModel`](@ref).
193-
- `Hc=2` : control horizon ``H_c``.
192+
- `Hp::Int=10+nk` : prediction horizon ``H_p``, `nk` is the number of delays if `model` is a
193+
[`LinModel`](@ref) (must be specified otherwise).
194+
- `Hc::Union{Int, Vector{Int}}=2` : control horizon ``H_c``, custom move blocking is
195+
specified with a vector of integers (see [`move_blocking`](@ref) for details).
194196
- `Mwt=fill(1.0,model.ny)` : main diagonal of ``\mathbf{M}`` weight matrix (vector).
195197
- `Nwt=fill(0.1,model.nu)` : main diagonal of ``\mathbf{N}`` weight matrix (vector).
196198
- `Lwt=fill(0.0,model.nu)` : main diagonal of ``\mathbf{L}`` weight matrix (vector).

src/controller/transcription.jl

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,8 @@ end
6666
6767
Init decision variables to input increments over ``H_c`` conversion matrix `PΔu`.
6868
69-
Introducing the move blocking vector that specifies the length of each step in the
70-
``\mathbf{ΔU}`` vector, to customize the pattern (strictly positive integers):
71-
72-
```math
73-
\mathbf{n_b} = \begin{bmatrix} n_1 & n_2 & \cdots & n_{H_c} \end{bmatrix}'
74-
```
75-
76-
The vector with all the manipulated input increments over the control horizon is defined
77-
as:
78-
79-
```math
80-
\mathbf{ΔU} = \begin{bmatrix}
81-
\mathbf{Δu}(k + 0) \\[0.1em]
82-
\mathbf{Δu}(k + ∑_{i=1}^1 n_i) \\[0.1em]
83-
\mathbf{Δu}(k + ∑_{i=1}^2 n_i) \\[0.1em]
84-
\vdots \\[0.1em]
85-
\mathbf{Δu}(k + ∑_{i=1}^{H_c-1} n_i)
86-
\end{bmatrix}
87-
```
88-
89-
This vector is extracted from from the decision variables ``\mathbf{Z}`` using the following
90-
formula:
91-
69+
The conversion from the decision variables ``\mathbf{Z}`` to ``\mathbf{ΔU}``, the input
70+
increments over ``H_c``, is computed by:
9271
```math
9372
\mathbf{ΔU} = \mathbf{P_{Δu}} \mathbf{Z}
9473
```
@@ -134,7 +113,7 @@ The ``\mathbf{P_u}`` and ``\mathbf{T_u}`` matrices are defined in the Extended H
134113
135114
# Extended Help
136115
!!! details "Extended Help"
137-
With ``n_j``, the ``j``th element of the ``\mathbf{n_b}`` vector definedc in [`init_ZtoΔU`](@ref)
116+
With ``n_j``, the ``j``th element of the ``\mathbf{n_b}`` vector defined in [`move_blocking`](@ref)
138117
documentation, we introduce the ``\mathbf{Q}(j)`` matrix of size `(nu*nj, nu)`:
139118
```math
140119
\mathbf{Q}(j) = \begin{bmatrix}

0 commit comments

Comments
 (0)