Skip to content

Commit 367af1b

Browse files
committed
doc: better logger handling in the manual
1 parent 42b00ba commit 367af1b

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

docs/src/manual/linmpc.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function plot_data(t_data, u_data, y_data, ry_data)
149149
return plot(p1, p2, p3, layout=(3,1))
150150
end
151151
plot_data(t_data, u_data, y_data, ry_data)
152-
savefig(ans, "plot1_LinMPC.svg"); nothing # hide
152+
savefig("plot1_LinMPC.svg"); nothing # hide
153153
```
154154

155155
![plot1_LinMPC](plot1_LinMPC.svg)
@@ -172,7 +172,7 @@ u, y = model.uop, model()
172172
initstate!(mpc2, u, y)
173173
u_data, y_data, ry_data = test_mpc(mpc2, model)
174174
plot_data(t_data, u_data, y_data, ry_data)
175-
savefig(ans, "plot2_LinMPC.svg"); nothing # hide
175+
savefig("plot2_LinMPC.svg"); nothing # hide
176176
```
177177

178178
![plot2_LinMPC](plot2_LinMPC.svg)
@@ -208,7 +208,7 @@ u, y, d = model.uop, model(), mpc_mhe.estim.model.dop
208208
initstate!(mpc_mhe, u, y, d)
209209
u_data, y_data, ry_data = test_mpc(mpc_mhe, model)
210210
plot_data(t_data, u_data, y_data, ry_data)
211-
savefig(ans, "plot3_LinMPC.svg"); nothing # hide
211+
savefig("plot3_LinMPC.svg"); nothing # hide
212212
```
213213

214214
![plot3_LinMPC](plot3_LinMPC.svg)
@@ -280,7 +280,7 @@ u, y, d = model.uop, model(), mpc_d.estim.model.dop
280280
initstate!(mpc_d, u, y, d)
281281
u_data, y_data, ry_data = test_mpc_d(mpc_d, model)
282282
plot_data(t_data, u_data, y_data, ry_data)
283-
savefig(ans, "plot4_LinMPC.svg"); nothing # hide
283+
savefig("plot4_LinMPC.svg"); nothing # hide
284284
```
285285

286286
![plot4_LinMPC](plot4_LinMPC.svg)

docs/src/manual/nonlinmpc.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
Pages = ["nonlinmpc.md"]
55
```
66

7+
```@setup 1
8+
using Logging; errlogger = ConsoleLogger(stderr, Error);
9+
old_logger = global_logger(); global_logger(errlogger);
10+
```
11+
712
## Nonlinear Model
813

914
In this example, the goal is to control the angular position ``θ`` of a pendulum
@@ -70,7 +75,7 @@ u = [0.5]
7075
N = 35
7176
res = sim!(model, N, u)
7277
plot(res, plotu=false)
73-
savefig(ans, "plot1_NonLinMPC.svg"); nothing # hide
78+
savefig("plot1_NonLinMPC.svg"); nothing # hide
7479
```
7580

7681
![plot1_NonLinMPC](plot1_NonLinMPC.svg)
@@ -99,7 +104,7 @@ f_plant(x, u, _ ) = pendulum(par_plant, x, u)
99104
plant = setname!(NonLinModel(f_plant, h, Ts, nu, nx, ny); u=vu, x=vx, y=vy)
100105
res = sim!(estim, N, [0.5], plant=plant, y_noise=[0.5])
101106
plot(res, plotu=false, plotxwithx̂=true)
102-
savefig(ans, "plot2_NonLinMPC.svg"); nothing # hide
107+
savefig("plot2_NonLinMPC.svg"); nothing # hide
103108
```
104109

105110
![plot2_NonLinMPC](plot2_NonLinMPC.svg)
@@ -121,11 +126,10 @@ The option `Cwt=Inf` disables the slack variable `ϵ` for constraint softening.
121126
performance on `plant` by imposing an angular setpoint of 180° (inverted position):
122127

123128
```@example 1
124-
using Logging; disable_logging(Warn) # hide
125-
using JuMP; unset_time_limit_sec(nmpc.optim) # hide
129+
using JuMP; unset_time_limit_sec(nmpc.optim) # hide
126130
res_ry = sim!(nmpc, N, [180.0], plant=plant, x_0=[0, 0], x̂_0=[0, 0, 0])
127131
plot(res_ry)
128-
savefig(ans, "plot3_NonLinMPC.svg"); nothing # hide
132+
savefig("plot3_NonLinMPC.svg"); nothing # hide
129133
```
130134

131135
![plot3_NonLinMPC](plot3_NonLinMPC.svg)
@@ -137,7 +141,7 @@ satisfactory:
137141
```@example 1
138142
res_yd = sim!(nmpc, N, [180.0], plant=plant, x_0=[π, 0], x̂_0=[π, 0, 0], y_step=[10])
139143
plot(res_yd)
140-
savefig(ans, "plot4_NonLinMPC.svg"); nothing # hide
144+
savefig("plot4_NonLinMPC.svg"); nothing # hide
141145
```
142146

143147
![plot4_NonLinMPC](plot4_NonLinMPC.svg)
@@ -201,10 +205,10 @@ speed ``ω`` is not requested to track a setpoint. The closed-loop response to a
201205
setpoint is similar:
202206

203207
```@example 1
204-
unset_time_limit_sec(empc.optim) # hide
208+
unset_time_limit_sec(empc.optim) # hide
205209
res2_ry = sim!(empc, N, [180, 0], plant=plant2, x_0=[0, 0], x̂_0=[0, 0, 0])
206210
plot(res2_ry)
207-
savefig(ans, "plot5_NonLinMPC.svg"); nothing # hide
211+
savefig("plot5_NonLinMPC.svg"); nothing # hide
208212
```
209213

210214
![plot5_NonLinMPC](plot5_NonLinMPC.svg)
@@ -224,7 +228,7 @@ Also, for a 10° step disturbance:
224228
```@example 1
225229
res2_yd = sim!(empc, N, [180; 0]; plant=plant2, x_0=[π, 0], x̂_0=[π, 0, 0], y_step=[10, 0])
226230
plot(res2_yd)
227-
savefig(ans, "plot6_NonLinMPC.svg"); nothing # hide
231+
savefig("plot6_NonLinMPC.svg"); nothing # hide
228232
```
229233

230234
![plot6_NonLinMPC](plot6_NonLinMPC.svg)
@@ -264,7 +268,7 @@ The linear controller has difficulties to reject the 10° step disturbance:
264268
```@example 1
265269
res_lin = sim!(mpc, N, [180.0]; plant, x_0=[π, 0], y_step=[10])
266270
plot(res_lin)
267-
savefig(ans, "plot7_NonLinMPC.svg"); nothing # hide
271+
savefig("plot7_NonLinMPC.svg"); nothing # hide
268272
```
269273

270274
![plot7_NonLinMPC](plot7_NonLinMPC.svg)
@@ -302,7 +306,7 @@ does improve the rejection of the step disturbance:
302306
```@example 1
303307
res_lin2 = sim!(mpc2, N, [180.0]; plant, x_0=[π, 0], y_step=[10])
304308
plot(res_lin2)
305-
savefig(ans, "plot8_NonLinMPC.svg"); nothing # hide
309+
savefig("plot8_NonLinMPC.svg"); nothing # hide
306310
```
307311

308312
![plot8_NonLinMPC](plot8_NonLinMPC.svg)
@@ -316,7 +320,7 @@ poor in the first quadrant:
316320
```@example 1
317321
res_lin3 = sim!(mpc2, N, [180.0]; plant, x_0=[0, 0])
318322
plot(res_lin3)
319-
savefig(ans, "plot9_NonLinMPC.svg"); nothing # hide
323+
savefig("plot9_NonLinMPC.svg"); nothing # hide
320324
```
321325

322326
![plot9_NonLinMPC](plot9_NonLinMPC.svg)
@@ -370,7 +374,7 @@ performances are similar to the nonlinear MPC, both for the 180° setpoint:
370374
```@example 1
371375
res_slin = test_slmpc(model, mpc3, [180], plant, x_0=[0, 0])
372376
plot(res_slin)
373-
savefig(ans, "plot10_NonLinMPC.svg"); nothing # hide
377+
savefig("plot10_NonLinMPC.svg"); nothing # hide
374378
```
375379

376380
![plot10_NonLinMPC](plot10_NonLinMPC.svg)
@@ -380,11 +384,15 @@ and the 10° step disturbance:
380384
```@example 1
381385
res_slin = test_slmpc(model, mpc3, [180], plant, x_0=[π, 0], y_step=[10])
382386
plot(res_slin)
383-
savefig(ans, "plot11_NonLinMPC.svg"); nothing # hide
387+
savefig("plot11_NonLinMPC.svg"); nothing # hide
384388
```
385389

386390
![plot11_NonLinMPC](plot11_NonLinMPC.svg)
387391

388392
The computations of the successive linearization MPC are about 125 times faster than the
389393
nonlinear MPC (0.00012 s per time steps versus 0.015 s per time steps, on average), an
390394
impressive gain for similar closed-loop performances!
395+
396+
```@setup 1
397+
global_logger(old_logger);
398+
```

0 commit comments

Comments
 (0)