Skip to content

Commit eb37227

Browse files
committed
added : Hp and Hc printed for PredictiveController instances
1 parent 6aa272f commit eb37227

File tree

13 files changed

+73
-153
lines changed

13 files changed

+73
-153
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/Manifest.toml
22
docs/build/
33
JuliaSysimage.so
4-
LocalPreferences.toml
4+
LocalPreferences.toml
5+
.vscode/

.vscode/JuliaSysimage.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

.vscode/precompile_control.jl

Lines changed: 0 additions & 14 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 0 additions & 82 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,29 @@ We first construct the plant model with a sample time $T_s = 1$ s:
3737

3838
```julia
3939
using ModelPredictiveControl, ControlSystemsBase
40-
G = [
41-
tf( 2 , [10, 1])*delay(20)
42-
tf( 10, [4, 1])
43-
]
40+
G = [ tf( 2 , [10, 1])*delay(20)
41+
tf( 10, [4, 1]) ]
4442
Ts = 1.0
4543
model = LinModel(G, Ts)
4644
```
4745

48-
Our goal is controlling the first output, but the second one should never exceed 35:
46+
Our goal is controlling the first output $y_1$, but the second one $y_2$ should never exceed
47+
35:
4948

5049
```julia
5150
mpc = LinMPC(model, Mwt=[1, 0], Nwt=[0.1])
5251
mpc = setconstraint!(mpc, ŷmax=[Inf, 35])
5352
```
5453

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):
54+
The keyword arguments `Mwt` and `Nwt` are the output setpoint tracking and move suppression
55+
weights, respectively. A setpoint step change of five tests `mpc` controller in closed-loop.
56+
The result is displayed with [`Plots.jl`](https://github.com/JuliaPlots/Plots.jl):
5857

5958
```julia
6059
using Plots
6160
ry = [5, 0]
62-
plot(sim!(mpc, 40, ry), plotry=true, plotŷmax=true)
61+
res = sim!(mpc, 40, ry)
62+
plot(res, plotry=true, plotŷmax=true)
6363
```
6464

6565
![StepChangeResponse](/docs/src/assets/readme_result.svg)

src/controller/linmpc.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,13 @@ julia> model = LinModel([tf(3, [30, 1]); tf(-2, [5, 1])], 4);
135135
136136
julia> mpc = LinMPC(model, Mwt=[0, 1], Nwt=[0.5], Hp=30, Hc=1)
137137
LinMPC controller with a sample time Ts = 4.0 s, SteadyKalmanFilter estimator and:
138-
1 manipulated inputs u
139-
4 states x̂
140-
2 measured outputs ym
141-
0 unmeasured outputs yu
142-
0 measured disturbances d
138+
30 prediction steps Hp
139+
1 control steps Hc
140+
1 manipulated inputs u
141+
4 states x̂
142+
2 measured outputs ym
143+
0 unmeasured outputs yu
144+
0 measured disturbances d
143145
```
144146
145147
# Extended Help
@@ -163,11 +165,13 @@ julia> estim = KalmanFilter(LinModel([tf(3, [30, 1]); tf(-2, [5, 1])], 4), i_ym=
163165
164166
julia> mpc = LinMPC(estim, Mwt=[0, 1], Nwt=[0.5], Hp=30, Hc=1)
165167
LinMPC controller with a sample time Ts = 4.0 s, KalmanFilter estimator and:
166-
1 manipulated inputs u
167-
3 states x̂
168-
1 measured outputs ym
169-
1 unmeasured outputs yu
170-
0 measured disturbances d
168+
30 prediction steps Hp
169+
1 control steps Hc
170+
1 manipulated inputs u
171+
3 states x̂
172+
1 measured outputs ym
173+
1 unmeasured outputs yu
174+
0 measured disturbances d
171175
```
172176
"""
173177
function LinMPC(

src/controller/nonlinmpc.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,17 @@ This method uses the default state estimator :
131131
132132
# Examples
133133
```jldoctest
134-
julia> model = NonLinModel((x,u,_)->0.5x+u, (x,_)->2x, 10, 1, 1, 1);
134+
julia> model = NonLinModel((x,u,_)->0.5x+u, (x,_)->2x, 10.0, 1, 1, 1);
135135
136136
julia> mpc = NonLinMPC(model, Hp=20, Hc=1, Cwt=1e6)
137137
NonLinMPC controller with a sample time Ts = 10.0 s, UnscentedKalmanFilter estimator and:
138-
1 manipulated inputs u
139-
2 states x̂
140-
1 measured outputs ym
141-
0 unmeasured outputs yu
142-
0 measured disturbances d
138+
20 prediction steps Hp
139+
1 control steps Hc
140+
1 manipulated inputs u
141+
2 states x̂
142+
1 measured outputs ym
143+
0 unmeasured outputs yu
144+
0 measured disturbances d
143145
```
144146
145147
# Extended Help
@@ -170,11 +172,13 @@ julia> estim = UnscentedKalmanFilter(model, σQ_int=[0.05]);
170172
171173
julia> mpc = NonLinMPC(estim, Hp=20, Hc=1, Cwt=1e6)
172174
NonLinMPC controller with a sample time Ts = 10.0 s, UnscentedKalmanFilter estimator and:
173-
1 manipulated inputs u
174-
2 states x̂
175-
1 measured outputs ym
176-
0 unmeasured outputs yu
177-
0 measured disturbances d
175+
20 prediction steps Hp
176+
1 control steps Hc
177+
1 manipulated inputs u
178+
2 states x̂
179+
1 measured outputs ym
180+
0 unmeasured outputs yu
181+
0 measured disturbances d
178182
```
179183
"""
180184
function NonLinMPC(

src/estimator/kalman.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ The [`SteadyKalmanFilter`](@ref) updates it with the precomputed Kalman gain ``\
151151
152152
# Examples
153153
```jldoctest
154-
julia> kf = SteadyKalmanFilter(LinModel(ss(1, 1, 1, 0, 1)));
154+
julia> kf = SteadyKalmanFilter(LinModel(ss(1, 1, 1, 0, 1.0)));
155155
156156
julia> x̂ = updatestate!(kf, [1], [0]) # x̂[2] is the integrator state (nint_ym argument)
157157
2-element Vector{Float64}:

src/estimator/luenberger.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct Luenberger <: StateEstimator
1818
Ĉm ::Matrix{Float64}
1919
D̂dm ::Matrix{Float64}
2020
K::Matrix{Float64}
21-
function Luenberger(model, i_ym, nint_ym, Asm, Csm, p)
21+
function Luenberger(model, i_ym, nint_ym, Asm, Csm, )
2222
nu, nx, ny = model.nu, model.nx, model.ny
2323
nym, nyu = length(i_ym), ny - length(i_ym)
2424
nxs = size(Asm,1)
@@ -27,9 +27,9 @@ struct Luenberger <: StateEstimator
2727
Â, B̂u, Ĉ, B̂d, D̂d = augment_model(model, As, Cs)
2828
Ĉm, D̂dm = Ĉ[i_ym, :], D̂d[i_ym, :] # measured outputs ym only
2929
K = try
30-
place(Â, Ĉ, p, :o)
30+
place(Â, Ĉ, , :o)
3131
catch
32-
error("Cannot compute the Luenberger gain L with specified poles p.")
32+
error("Cannot compute the Luenberger gain L with specified poles .")
3333
end
3434
i_ym = collect(i_ym)
3535
lastu0 = zeros(nu)

src/plot_sim.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ end
477477
yguide --> "\$y_$i\$"
478478
color --> 3
479479
subplot --> subplot_base + i
480-
seriestype --> :steppost
481480
linestyle --> :dash
482481
linewidth --> 0.75
483482
label --> "\$\\mathbf{r_y}\$"

0 commit comments

Comments
 (0)