Skip to content

Commit fb15e48

Browse files
committed
add example to README.md
1 parent e4176a5 commit fb15e48

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,55 @@ To install the `ModelPredictiveControl` package, run this command in the Julia R
1818
using Pkg; Pkg.add("ModelPredictiveControl")
1919
```
2020

21+
## Getting Started
22+
23+
To construct model predictive controllers, we must first specify a plant model that is
24+
typically extracted from input-output data using [system identification](https://github.com/baggepinnen/ControlSystemIdentification.jl).
25+
The model here is linear with one input, two outputs and a large time delay in the first
26+
channel:
27+
28+
```math
29+
\mathbf{G}(s) = \frac{\mathbf{y}(s)}{\mathbf{u}(s)} =
30+
\begin{bmatrix}
31+
\frac{2e^{-20s}}{10s + 1} \\[3pt]
32+
\frac{10}{4s +1}
33+
\end{bmatrix}
34+
```
35+
36+
We first construct the plant model with a sample time ``T_s = 1`` s:
37+
38+
```julia
39+
using ModelPredictiveControl, ControlSystemsBase
40+
sys = [
41+
tf( 2 , [10, 1])*delay(20)
42+
tf( 10, [4, 1])
43+
]
44+
Ts = 1.0
45+
model = LinModel(sys, Ts)
46+
```
47+
48+
Our goal is controlling the first output, but the second one should never exceed 35:
49+
50+
```julia
51+
mpc = LinMPC(model, Mwt=[1, 0], Nwt=[0.1], Hp=30, Hc=2)
52+
mpc = setconstraint!(mpc, ŷmax=[Inf, 35])
53+
```
54+
55+
The keyword arguments `Mwt` and `Nwt` are the setpoint tracking and move suppression
56+
weights, respectively. We can now test `mpc` controller with a setpoint step change and
57+
display the result using [`Plots.jl`](https://github.com/JuliaPlots/Plots.jl):
58+
59+
```julia
60+
using Plots
61+
ry = [5, 0]
62+
plot(sim!(mpc, 40, ry), plotry=true, plotŷmax=true)
63+
```
64+
65+
![StepChangeResponse](/example/readme_result.svg)
66+
67+
See the [manual](https://franckgaga.github.io/ModelPredictiveControl.jl/stable/manual/) for
68+
more detailed examples.
69+
2170
## Features
2271

2372
### Legend

0 commit comments

Comments
 (0)