Skip to content

Commit 5889e5e

Browse files
committed
added : plotxwithx̂ option and output step dist in manual
1 parent 73770d0 commit 5889e5e

File tree

9 files changed

+104
-118
lines changed

9 files changed

+104
-118
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A [model predictive control](https://en.wikipedia.org/wiki/Model_predictive_cont
99
for Julia.
1010

1111
The package depends on [`ControlSystemsBase.jl`](https://github.com/JuliaControl/ControlSystems.jl)
12-
for the linear systems and [`JuMP.jl`](https://github.com/jump-dev/JuMP.jl) for the solvers.
12+
for the linear systems and [`JuMP.jl`](https://github.com/jump-dev/JuMP.jl) for the solving.
1313

1414
## Installation
1515

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ DocMeta.setdocmeta!(
1414
)
1515
makedocs(
1616
sitename = "ModelPredictiveControl.jl",
17-
modules = [ModelPredictiveControl],
1817
doctest = true,
1918
format = Documenter.HTML(
2019
prettyurls = get(ENV, "CI", nothing) == "true",
@@ -24,6 +23,7 @@ makedocs(
2423
"Home" => "index.md",
2524
"Manual" => [
2625
"Examples" => [
26+
"Installation" => "manual/installation.md",
2727
"Linear Design" => "manual/linmpc.md",
2828
"Nonlinear Design" => "manual/nonlinmpc.md",
2929
],

docs/src/index.md

Lines changed: 35 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,53 @@ A [model predictive control](https://en.wikipedia.org/wiki/Model_predictive_cont
44
for Julia.
55

66
The package depends on [`ControlSystemsBase.jl`](https://github.com/JuliaControl/ControlSystems.jl)
7-
for the linear systems and [`JuMP.jl`](https://github.com/jump-dev/JuMP.jl) for the solvers.
7+
for the linear systems and [`JuMP.jl`](https://github.com/jump-dev/JuMP.jl) for the solving.
88

9-
## Contents
9+
The objective is to provide a simple and clear framework to quickly design model predictive
10+
controllers (MPCs) in Julia, while keeping the flexibility for advanced optimization. Modern
11+
MPCs based on closed-loop state estimators are the main focus of the package, but classical
12+
approaches that rely on internal models are also possible. The `JuMP.jl` interface allows
13+
to easily test different solvers if the performance of the default settings is not
14+
satisfactory.
15+
16+
The documentation is divided in two parts:
17+
18+
- **[Manual](@ref man_lin)** This section includes step-by-step guides to design
19+
predictive controllers or multiple case studies.
20+
- **[Functions](@ref func_sim_model)** This part contains the documentation of
21+
methods and types that are exported by the package. The "Internals" section provides
22+
implementation details of functions that are not exported.
23+
24+
## Manual
1025

1126
```@contents
27+
Depth = 2
1228
Pages = [
13-
"index.md",
29+
"manual/installation.md",
1430
"manual/linmpc.md",
1531
"manual/nonlinmpc.md",
32+
]
33+
```
34+
35+
## Functions: Public
36+
37+
```@contents
38+
Depth = 2
39+
Pages = [
1640
"public/sim_model.md",
1741
"public/state_estim.md",
1842
"public/predictive_control.md",
1943
"public/generic_func.md",
44+
]
45+
```
46+
47+
## Functions: Internals
48+
49+
```@contents
50+
Depth = 1
51+
Pages = [
2052
"internals/sim_model.md",
2153
"internals/state_estim.md",
2254
"internals/predictive_control.md",
23-
"func_index.md"
2455
]
2556
```
26-
27-
## Features
28-
29-
### Legend
30-
31-
✅ implemented feature
32-
⬜ planned feature
33-
34-
### Model Predictive Control Features
35-
36-
- ✅ linear and nonlinear plant models exploiting multiple dispatch
37-
- ✅ supported objective function terms:
38-
- ✅ output setpoint tracking
39-
- ✅ move suppression
40-
- ✅ input setpoint tracking
41-
- ✅ economic costs (economic model predictive control)
42-
- ⬜ terminal cost to ensure nominal stability
43-
- ✅ soft and hard constraints on:
44-
- ✅ output predictions
45-
- ✅ manipulated inputs
46-
- ✅ manipulated inputs increments
47-
- ⬜ custom manipulated input constraints that are a function of the predictions
48-
- ✅ supported feedback strategy:
49-
- ✅ state estimator (see State Estimation features)
50-
- ✅ internal model structure with a custom stochastic model
51-
- ✅ offset-free tracking with a single or multiple integrators on measured outputs
52-
- ✅ support for unmeasured model outputs
53-
- ✅ feedforward action with measured disturbances that supports direct transmission
54-
- ✅ custom predictions for:
55-
- ✅ output setpoints
56-
- ✅ measured disturbances
57-
- ✅ easy integration with `Plots.jl`
58-
- ✅ optimization based on `JuMP.jl`:
59-
- ✅ quickly compare multiple optimizers
60-
- ✅ nonlinear solvers relying on automatic differentiation (exact derivative)
61-
- ✅ additional information about the optimum to ease troubleshooting
62-
63-
### State Estimation Features
64-
65-
- ⬜ supported state estimators/observers:
66-
- ✅ steady-state Kalman filter
67-
- ✅ Kalman filter
68-
- ✅ Luenberger observer
69-
- ✅ internal model structure
70-
- ⬜ extended Kalman filter
71-
- ✅ unscented Kalman filter
72-
- ⬜ moving horizon estimator
73-
- ✅ observers in predictor form to ease control applications
74-
- ⬜ moving horizon estimator that supports:
75-
- ⬜ inequality state constraints
76-
- ⬜ zero process noise equality constraint to reduce the problem size

docs/src/manual/installation.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Manual: Installation
2+
3+
To install the `ModelPredictiveControl` package, run this command in the Julia REPL:
4+
5+
```julia
6+
using Pkg; Pkg.add("ModelPredictiveControl")
7+
```
8+
9+
It will also automatically install all the dependencies, including [`JuMP.jl`](https://github.com/jump-dev/JuMP.jl)
10+
and [`ControlSystemsBase.jl`](https://github.com/JuliaControl/ControlSystems.jl). Note that
11+
that the construction of linear models typically requires `ss` or `tf` functions, it is thus
12+
recommended to load the package with:
13+
14+
```julia
15+
using ModelPredictiveControl, ControlSystemsBase
16+
```

docs/src/manual/linmpc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ nothing # hide
113113
The [`LinMPC`](@ref) objects are also callable as an alternative syntax for
114114
[`moveinput!`](@ref). Calling [`updatestate!`](@ref) on the `mpc` object updates its
115115
internal state for the *NEXT* control period (this is by design, see
116-
[State Estimators](@ref) for justifications). That is why the call is done at the end of the
117-
`for` loop. The same logic applies for `model`.
116+
[Functions: State Estimators](@ref) for justifications). That is why the call is done at the
117+
end of the `for` loop. The same logic applies for `model`.
118118

119119
Lastly, we plot the closed-loop test with the `Plots` package:
120120

docs/src/manual/nonlinmpc.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ is good practice to first simulate `model` using [`sim!`](@ref) as a quick sanit
5050

5151
```@example 1
5252
using Plots
53-
u = [0.5] # τ = 0.5 N m
53+
u = [0.5]
5454
plot(sim!(model, 60, u), plotu=false)
5555
```
5656

@@ -59,7 +59,7 @@ plot(sim!(model, 60, u), plotu=false)
5959
An [`UnscentedKalmanFilter`](@ref) estimates the plant state :
6060

6161
```@example 1
62-
estim = UnscentedKalmanFilter(model, σQ=[0.5, 2.5], σQ_int=[0.5])
62+
estim = UnscentedKalmanFilter(model, σQ=[0.5, 2.5], σQ_int=[5.0], σR=[0.5])
6363
```
6464

6565
The standard deviation of the angular velocity ``ω`` is higher here (`σQ` second value)
@@ -70,24 +70,33 @@ since ``\dot{ω}(t)`` equation includes an uncertain parameter: the friction coe
7070
par_plant = (par[1], par[2], par[3] + 0.25, par[4])
7171
f_plant(x, u, _) = x + Ts*pendulum(par_plant, x, u)
7272
plant = NonLinModel(f_plant, h, Ts, nu, nx, ny)
73-
res = sim!(estim, 30, [0.5], plant=plant, y_noise=[0.5]) # τ = 0.5 N m
74-
plot(res, plotu=false, plotx=true, plotx̂=true)
73+
res = sim!(estim, 60, [0.5], plant=plant, y_noise=[0.5])
74+
plot(res, plotu=false, plotxwithx̂=true)
7575
```
7676

77-
The Kalman filter performance seems sufficient for control. As the motor torque is limited
78-
to -1.5 to 1.5 N m, we incorporate the input constraints in a [`NonLinMPC`](@ref):
77+
The estimate ``x̂_3`` is the integrator state that compensates for static errors (`nint_ym`
78+
parameter of [`UnscentedKalmanFilter`](@ref)). The Kalman filter performance seems
79+
sufficient for control. As the motor torque is limited to -1.5 to 1.5 N m, we incorporate
80+
the input constraints in a [`NonLinMPC`](@ref):
7981

8082
```@example 1
81-
mpc = NonLinMPC(estim, Hp=20, Hc=2, Mwt=[0.1], Nwt=[1.0], Cwt=Inf)
83+
mpc = NonLinMPC(estim, Hp=20, Hc=4, Mwt=[0.1], Nwt=[1.0], Cwt=Inf)
8284
mpc = setconstraint!(mpc, umin=[-1.5], umax=[+1.5])
8385
```
8486

8587
We test `mpc` performance on `plant` by imposing an angular setpoint of 180° (inverted
8688
position):
8789

8890
```@example 1
89-
res = sim!(mpc, 30, [180.0], x̂0=zeros(mpc.estim.nx̂), plant=plant, x0=zeros(plant.nx))
90-
plot(res, plotŷ=true)
91+
res = sim!(mpc, 65, [180.0], plant=plant, x0=zeros(plant.nx), x̂0=zeros(mpc.estim.nx̂))
92+
plot(res)
9193
```
9294

93-
The controller seems robust enough to variations on ``K`` coefficient.
95+
The controller seems robust enough to variations on ``K`` coefficient. Moreover, starting
96+
from this inverted position, the closed-loop response to a step disturbances of 10° on ``θ``
97+
is also satisfactory:
98+
99+
```@example 1
100+
res = sim!(mpc, 65, [180.0], plant=plant, x0=[π, 0], x̂0=[π, 0, 0], y_step=[10])
101+
plot(res)
102+
```

docs/src/public/sim_model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Functions: Plant Models
1+
# [Functions: Plant Models](@id func_sim_model)
22

33
```@contents
44
Pages = ["sim_model.md"]

example/juMPC.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,9 @@ ps = plot(res, plotx=true)
169169
display(ps)
170170

171171
res2 = sim!(uscKalmanFilter1, mpc.Hp+10)
172-
ps2 = plot(res2)
172+
ps2 = plot(res2, plotxwithx̂=true)
173173
display(ps2)
174174

175-
res2 = sim!(uscKalmanFilter1, mpc.Hp+10, plant=deepcopy(uscKalmanFilter1.model))
176-
ps2 = plot(res2, plotx=true, plotx̂=true)
177-
display(ps2)
178-
179-
180175

181176
test_mpc(linModel4, nmpc)
182177
@time u_data, y_data, r_data, d_data = test_mpc(linModel4, nmpc)

0 commit comments

Comments
 (0)