Skip to content

Commit 18f1cc1

Browse files
committed
doc: moving some content in extended help
1 parent e5cc5aa commit 18f1cc1

File tree

7 files changed

+44
-39
lines changed

7 files changed

+44
-39
lines changed

docs/src/public/generic_func.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Pages = ["generic_func.md"]
77
This page contains the documentation of functions that are generic to [`SimModel`](@ref),
88
[`StateEstimator`](@ref) and [`PredictiveController`](@ref) types.
99

10+
## Set Constraint
11+
12+
```@docs
13+
setconstraint!
14+
```
15+
1016
## Evaluate Output y
1117

1218
```@docs
@@ -31,12 +37,6 @@ initstate!
3137
setstate!
3238
```
3339

34-
## Set Constraint
35-
36-
```@docs
37-
setconstraint!
38-
```
39-
4040
## Quick Simulation
4141

4242
### Simulate

src/controller/construct.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ constraints are all soft by default. See Extended Help for time-varying constrai
4242
```jldoctest
4343
julia> mpc = LinMPC(setop!(LinModel(tf(3, [30, 1]), 4), uop=[50], yop=[25]));
4444
45-
julia> mpc = setconstraint!(mpc, umin=[0], umax=[100], c_umin=[0.0], c_umax=[0.0]);
46-
47-
julia> mpc = setconstraint!(mpc, Δumin=[-10], Δumax=[+10], c_Δumin=[1.0], c_Δumax=[1.0])
45+
julia> mpc = setconstraint!(mpc, umin=[0], umax=[100], Δumin=[-10], Δumax=[+10])
4846
LinMPC controller with a sample time Ts = 4.0 s, OSQP optimizer, SteadyKalmanFilter estimator and:
4947
10 prediction steps Hp
5048
2 control steps Hc

src/controller/execute.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ end
6868
@doc raw"""
6969
getinfo(mpc::PredictiveController) -> info
7070
71-
Get additional info about `mpc` controller optimum for troubleshooting.
71+
Get additional info about `mpc` [`PredictiveController`](@ref) optimum for troubleshooting.
7272
7373
The function should be called after calling [`moveinput!`](@ref). It returns the dictionary
7474
`info` with the following fields:

src/controller/nonlinmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ NonLinMPC controller with a sample time Ts = 10.0 s, Ipopt optimizer, UnscentedK
161161
algebra instead of a `for` loop. This feature can accelerate the optimization, especially
162162
for the constraint handling, and is not available in any other package, to my knowledge.
163163
164-
The optimizations rely on [`JuMP.jl`](https://github.com/jump-dev/JuMP.jl) automatic
164+
The optimization relies on [`JuMP.jl`](https://github.com/jump-dev/JuMP.jl) automatic
165165
differentiation (AD) to compute the objective and constraint derivatives. Optimizers
166166
generally benefit from exact derivatives like AD. However, the [`NonLinModel`](@ref) `f`
167167
and `h` functions must be compatible with this feature. See [Automatic differentiation](https://jump.dev/JuMP.jl/stable/manual/nlp/#Automatic-differentiation)

src/estimator/execute.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function init_estimate!(estim::StateEstimator, ::LinModel, u, ym, d)
125125
return nothing
126126
end
127127
"""
128-
init_estimate!(::StateEstimator, ::SimModel, _ , _ , _ )
128+
init_estimate!(estim::StateEstimator, model::SimModel, _ , _ , _ )
129129
130130
Left `estim.x̂` estimate unchanged if `model` is not a [`LinModel`](@ref).
131131
"""

src/estimator/kalman.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ is based on the process model :
410410
\end{aligned}
411411
```
412412
See [`SteadyKalmanFilter`](@ref) for details on ``\mathbf{v}(k), \mathbf{w}(k)`` noises and
413-
``\mathbf{R̂}, \mathbf{Q̂}`` covariances. The functions ``\mathbf{f̂, ĥ}`` are `model` state-
414-
space functions augmented with the stochastic model, which is specified by the numbers of
415-
integrator `nint_u` and `nint_ym` (see Extended Help). The ``\mathbf{ĥ^m}`` function
413+
``\mathbf{R̂}, \mathbf{Q̂}`` covariances. The functions ``\mathbf{f̂, ĥ}`` are `model`
414+
state-space functions augmented with the stochastic model, which is specified by the numbers
415+
of integrator `nint_u` and `nint_ym` (see Extended Help). The ``\mathbf{ĥ^m}`` function
416416
represents the measured outputs of ``\mathbf{ĥ}`` function (and unmeasured ones, for
417417
``\mathbf{ĥ^u}``).
418418

src/estimator/mhe/construct.jl

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ const DEFAULT_NONLINMHE_OPTIMIZER = optimizer_with_attributes(Ipopt.Optimizer,"s
66
77
Construct a moving horizon estimator (MHE) based on `model` ([`LinModel`](@ref) or [`NonLinModel`](@ref)).
88
9-
This estimator can handle constraints on the estimates, see [`setconstraint!`](@ref).
10-
Additionally, `model` is not linearized like the [`ExtendedKalmanFilter`](@ref), and the
11-
probability distribution is not approximated like the [`UnscentedKalmanFilter`](@ref). The
12-
computational costs are drastically higher, however, since it minimizes the following
13-
objective function at each discrete time ``k``:
9+
It can handle constraints on the estimates, see [`setconstraint!`](@ref). Additionally,
10+
`model` is not linearized like the [`ExtendedKalmanFilter`](@ref), and the probability
11+
distribution is not approximated like the [`UnscentedKalmanFilter`](@ref). The computational
12+
costs are drastically higher, however, since it minimizes the following objective function
13+
at each discrete time ``k``:
1414
```math
15-
\min_{\mathbf{x̂}_k(k-N_k+1), \mathbf{Ŵ}} \mathbf{x̄}' \mathbf{P̄}^{-1} \mathbf{x̄}
16-
+ \mathbf{Ŵ}' \mathbf{Q̂}_{N_k}^{-1} \mathbf{Ŵ}
17-
+ \mathbf{V̂}' \mathbf{R̂}_{N_k}^{-1} \mathbf{V̂}
15+
\min_{\mathbf{x̂}_k(k-N_k+1), \mathbf{Ŵ}, ϵ} \mathbf{x̄}' \mathbf{P̄}^{-1} \mathbf{x̄}
16+
+ \mathbf{Ŵ}' \mathbf{Q̂}_{N_k}^{-1} \mathbf{Ŵ}
17+
+ \mathbf{V̂}' \mathbf{R̂}_{N_k}^{-1} \mathbf{V̂}
18+
+ C ϵ^2
1819
```
1920
in which the arrival costs are evaluated from the states estimated at time ``k-N_k``:
2021
```math
@@ -38,22 +39,20 @@ N_k = \begin{cases}
3839
```
3940
The vectors ``\mathbf{Ŵ}`` and ``\mathbf{V̂}`` encompass the estimated process noise
4041
``\mathbf{ŵ}(k-j)`` and sensor noise ``\mathbf{v̂}(k-j)`` from ``j=N_k-1`` to ``0``. The
41-
Extended Help explicitly defines the two vectors. See [`SteadyKalmanFilter`](@ref) for
42-
details on ``\mathbf{R̂}, \mathbf{Q̂}`` covariances and model augmentation. The process
43-
model is identical to the one in [`UnscentedKalmanFilter`](@ref) documentation. The matrix
42+
Extended Help defines the two vectors. See [`UnscentedKalmanFilter`](@ref) for details on
43+
the augmented process model and ``\mathbf{R̂}, \mathbf{Q̂}`` covariances. The matrix
4444
``\mathbf{P̂}_{k-N_k}(k-N_k+1)`` is estimated with an [`ExtendedKalmanFilter`](@ref).
4545
4646
!!! warning
47-
See the Extended Help of [`NonLinMPC`](@ref) function if you get an error like:
47+
See the Extended Help if you get an error like:
4848
`MethodError: no method matching (::var"##")(::Vector{ForwardDiff.Dual})`.
4949
5050
# Arguments
5151
- `model::SimModel` : (deterministic) model for the estimations.
52-
- `He=nothing`: estimation horizon ``H_e``, must be specified.
53-
- `optim=default_optim_mhe(model)` : quadratic or nonlinear optimizer used in the moving
54-
horizon estimator, provided as a [`JuMP.Model`](https://jump.dev/JuMP.jl/stable/api/JuMP/#JuMP.Model)
55-
(default to [`Ipopt`](https://github.com/jump-dev/Ipopt.jl), or [`OSQP`](https://osqp.org/docs/parsers/jump.html)
56-
if `model` is a [`LinModel`](@ref)).
52+
- `He=nothing` : estimation horizon ``H_e``, must be specified.
53+
- `optim=default_optim_mhe(model)` : a [`JuMP.Model`](https://jump.dev/JuMP.jl/stable/api/JuMP/#JuMP.Model)
54+
with a quadratic/nonlinear optimizer for solving (default to [`Ipopt`](https://github.com/jump-dev/Ipopt.jl),
55+
or [`OSQP`](https://osqp.org/docs/parsers/jump.html) if `model` is a [`LinModel`](@ref)).
5756
- `<keyword arguments>` of [`SteadyKalmanFilter`](@ref) constructor.
5857
- `<keyword arguments>` of [`KalmanFilter`](@ref) constructor.
5958
@@ -97,6 +96,13 @@ MovingHorizonEstimator estimator with a sample time Ts = 10.0 s, Ipopt optimizer
9796
\mathbf{x̂}_k(k-j+1) &= \mathbf{f̂}\Big(\mathbf{x̂}_k(k-j), \mathbf{u}(k-j), \mathbf{d}(k-j)\Big) + \mathbf{ŵ}(k-j)
9897
\end{aligned}
9998
```
99+
100+
For [`LinModel`](@ref), the optimization is treated as a quadratic program with a
101+
time-varying Hessian, which is generally cheaper than nonlinear programming. For
102+
[`NonLinModel`](@ref), the optimization relies on automatic differentiation (AD).
103+
Optimizers generally benefit from exact derivatives like AD. However, the `f` and `h`
104+
functions must be compatible with this feature. See [Automatic differentiation](https://jump.dev/JuMP.jl/stable/manual/nlp/#Automatic-differentiation)
105+
for common mistakes when writing these functions.
100106
"""
101107
function MovingHorizonEstimator(
102108
model::SM;
@@ -520,8 +526,8 @@ end
520526
521527
Set the constraint parameters of the [`MovingHorizonEstimator`](@ref) `estim`.
522528
523-
The estimator supports both soft and hard constraints on the estimated state ``\mathbf{x̂}``,
524-
process noise ``\mathbf{ŵ}`` and sensor noise ``\mathbf{v̂}``:
529+
It supports both soft and hard constraints on the estimated state ``\mathbf{x̂}``, process
530+
noise ``\mathbf{ŵ}`` and sensor noise ``\mathbf{v̂}``:
525531
```math
526532
\begin{alignat*}{3}
527533
\mathbf{x̂_{min} - c_{x̂_{min}}} ϵ ≤&&\ \mathbf{x̂}_k(k-j+1) &≤ \mathbf{x̂_{max} + c_{x̂_{max}}} ϵ &&\qquad j = N_k, N_k - 1, ... , 0 \\
@@ -533,11 +539,9 @@ and also ``ϵ ≥ 0``. All the constraint parameters are vector. Use `±Inf` val
533539
is no bound. The constraint softness parameters ``\mathbf{c}``, also called equal concern
534540
for relaxation, are non-negative values that specify the softness of the associated bound.
535541
Use `0.0` values for hard constraints. The process and sensor noise constraints are all soft
536-
by default. Note that the state and process noise constraints are applied on the augmented
537-
vectors (see the extended help of [`SteadyKalmanFilter`](@ref) for details on augmentation).
538-
Also note that constraining the estimated sensor noises is equivalent to bounding the
539-
innovation term, since ``\mathbf{v̂}(k) = \mathbf{y^m}(k) - \mathbf{ŷ^m}(k)``. See Extended
540-
Help for time-varying constraints.
542+
by default. Notice that constraining the estimated sensor noises is equivalent to bounding
543+
the innovation term, since ``\mathbf{v̂}(k) = \mathbf{y^m}(k) - \mathbf{ŷ^m}(k)``. See
544+
Extended Help for details on model augmentation and time-varying constraints.
541545
542546
# Arguments
543547
!!! info
@@ -577,6 +581,9 @@ MovingHorizonEstimator estimator with a sample time Ts = 1.0 s, OSQP optimizer,
577581
578582
# Extended Help
579583
!!! details "Extended Help"
584+
Note that the state ``\mathbf{x̂}`` and process noise ``\mathbf{ŵ}`` constraints are
585+
applied on the augmented model, detailed in [`SteadyKalmanFilter`](@ref) Extended Help.
586+
580587
For variable constraints, the bounds can be modified after calling [`updatestate!`](@ref),
581588
that is, at runtime, except for `±Inf` bounds. Time-varying constraints over the
582589
estimation horizon ``H_e`` are also possible, mathematically defined as:

0 commit comments

Comments
 (0)