Skip to content

Commit dab958b

Browse files
committed
doc : added example with nint_u for LinMPC
1 parent 718d670 commit dab958b

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

docs/src/manual/linmpc.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ the following linear model accurately describes the plant dynamics:
4141
We first need to construct a [`LinModel`](@ref) objet with [`setop!`](@ref) to handle the
4242
operating points:
4343

44-
```julia
44+
```@example 1
4545
using ModelPredictiveControl, ControlSystemsBase
4646
sys = [ tf(1.90, [18, 1]) tf(1.90, [18, 1]);
4747
tf(-0.74,[8, 1]) tf(0.74, [8, 1]) ]
@@ -65,7 +65,7 @@ y_L ≥ 45
6565
We design our [`LinMPC`](@ref) controllers by including the linear level constraint with
6666
[`setconstraint!`](@ref) (`±Inf` values should be used when there is no bound):
6767

68-
```julia
68+
```@example 1
6969
mpc = setconstraint!(LinMPC(model, Hp=15, Hc=2), ŷmin=[45, -Inf])
7070
```
7171

@@ -83,7 +83,7 @@ measurements to ensure a bumpless transfer. Since `model` simulates our plant he
8383
output will initialize the states. [`LinModel`](@ref) objects are callable for this purpose
8484
(an alias for [`evaloutput`](@ref)):
8585

86-
```julia
86+
```@example 1
8787
u = model.uop
8888
y = model() # or equivalently : y = evaloutput(model)
8989
initstate!(mpc, u, y)
@@ -93,7 +93,7 @@ nothing # hide
9393
We can then close the loop and test `mpc` performance on the simulator by imposing step
9494
changes on output setpoints ``\mathbf{r_y}`` and on a load disturbance ``\mathbf{u_d}``:
9595

96-
```julia
96+
```@example 1
9797
function test_mpc(mpc, model)
9898
N = 200
9999
ry, ud = [50, 30], [0, 0]
@@ -103,15 +103,14 @@ function test_mpc(mpc, model)
103103
for k = 0:N-1
104104
y = model() # simulated measurements
105105
k == 50 && (ry = [50, 35])
106-
k == 100 && (ry = [55, 30])
107-
k == 150 && (ud = [-25, 0])
106+
k == 100 && (ry = [54, 30])
107+
k == 150 && (ud = [0, -20])
108108
u = mpc(ry) # or equivalently : u = moveinput!(mpc, ry)
109109
u_data[:,k+1] = u
110110
y_data[:,k+1] = y
111111
ry_data[:,k+1] = ry
112112
updatestate!(mpc, u, y) # update mpc state estimate
113113
updatestate!(model, u + ud) # update simulator with disturbance
114-
println(getinfo(mpc)[2][:Ŷs])
115114
end
116115
return u_data, y_data, ry_data
117116
end
@@ -128,7 +127,7 @@ end of the `for` loop. The same logic applies for `model`.
128127

129128
Lastly, we plot the closed-loop test with the `Plots` package:
130129

131-
```julia
130+
```@example 1
132131
using Plots
133132
function plot_data(t_data, u_data, y_data, ry_data)
134133
p1 = plot(t_data, y_data[1,:], label="meas."); ylabel!("level")
@@ -151,21 +150,23 @@ using Pkg; Pkg.add("DAQP")
151150
```
152151

153152
Also, compared to the default setting, adding the integrating states at the model inputs may
154-
improve the closed-loop performance. Load disturbances are indeed very frequent in real-life
155-
control problems. Constructing a [`LinMPC`](@ref) with `DAQP` and input integrators:
153+
improve the closed-loop performance. Load disturbances are indeed very frequent in many
154+
real-life control problems. Constructing a [`LinMPC`](@ref) with `DAQP` and input integrators:
156155

157-
```julia
156+
```@example 1
158157
using JuMP, DAQP
159158
daqp = Model(DAQP.Optimizer)
160159
estim = SteadyKalmanFilter(model, nint_u=[1, 1])
161160
mpc2 = setconstraint!(LinMPC(estim, Hp=15, Hc=2, optim=daqp), ŷmin=[45, -Inf])
162161
```
163162

164-
leads to identical results here:
163+
leads to similar computational times, but it does accelerate the rejection of the load
164+
disturbance and eliminates the level constraint violation:
165165

166-
```julia
166+
```@example 1
167167
setstate!(model, zeros(model.nx))
168168
initstate!(mpc2, model.uop, model())
169169
u_data2, y_data2, ry_data2 = test_mpc(mpc2, model)
170170
plot_data(t_data, u_data2, y_data2, ry_data2)
171171
```
172+

src/sim_model.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ julia> y = evaloutput(model)
135135
"""
136136
evaloutput(model::SimModel, d=Float64[]) = h(model, model.x, d - model.dop) + model.yop
137137

138-
139138
"Functor allowing callable `SimModel` object as an alias for `evaloutput`."
140139
(model::SimModel)(d=Float64[]) = evaloutput(model::SimModel, d)
141140

0 commit comments

Comments
 (0)