4
4
Pages = ["nonlinmpc.md"]
5
5
```
6
6
7
+ ``` @setup 1
8
+ using Logging; errlogger = ConsoleLogger(stderr, Error);
9
+ old_logger = global_logger(); global_logger(errlogger);
10
+ ```
11
+
7
12
## Nonlinear Model
8
13
9
14
In this example, the goal is to control the angular position `` θ `` of a pendulum
@@ -70,7 +75,7 @@ u = [0.5]
70
75
N = 35
71
76
res = sim!(model, N, u)
72
77
plot(res, plotu=false)
73
- savefig(ans, "plot1_NonLinMPC.svg"); nothing # hide
78
+ savefig("plot1_NonLinMPC.svg"); nothing # hide
74
79
```
75
80
76
81
![ plot1_NonLinMPC] ( plot1_NonLinMPC.svg )
@@ -99,7 +104,7 @@ f_plant(x, u, _ ) = pendulum(par_plant, x, u)
99
104
plant = setname!(NonLinModel(f_plant, h, Ts, nu, nx, ny); u=vu, x=vx, y=vy)
100
105
res = sim!(estim, N, [0.5], plant=plant, y_noise=[0.5])
101
106
plot(res, plotu=false, plotxwithx̂=true)
102
- savefig(ans, "plot2_NonLinMPC.svg"); nothing # hide
107
+ savefig("plot2_NonLinMPC.svg"); nothing # hide
103
108
```
104
109
105
110
![ plot2_NonLinMPC] ( plot2_NonLinMPC.svg )
@@ -121,11 +126,10 @@ The option `Cwt=Inf` disables the slack variable `ϵ` for constraint softening.
121
126
performance on ` plant ` by imposing an angular setpoint of 180° (inverted position):
122
127
123
128
``` @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
126
130
res_ry = sim!(nmpc, N, [180.0], plant=plant, x_0=[0, 0], x̂_0=[0, 0, 0])
127
131
plot(res_ry)
128
- savefig(ans, "plot3_NonLinMPC.svg"); nothing # hide
132
+ savefig("plot3_NonLinMPC.svg"); nothing # hide
129
133
```
130
134
131
135
![ plot3_NonLinMPC] ( plot3_NonLinMPC.svg )
@@ -137,7 +141,7 @@ satisfactory:
137
141
``` @example 1
138
142
res_yd = sim!(nmpc, N, [180.0], plant=plant, x_0=[π, 0], x̂_0=[π, 0, 0], y_step=[10])
139
143
plot(res_yd)
140
- savefig(ans, "plot4_NonLinMPC.svg"); nothing # hide
144
+ savefig("plot4_NonLinMPC.svg"); nothing # hide
141
145
```
142
146
143
147
![ plot4_NonLinMPC] ( plot4_NonLinMPC.svg )
@@ -201,10 +205,10 @@ speed ``ω`` is not requested to track a setpoint. The closed-loop response to a
201
205
setpoint is similar:
202
206
203
207
``` @example 1
204
- unset_time_limit_sec(empc.optim) # hide
208
+ unset_time_limit_sec(empc.optim) # hide
205
209
res2_ry = sim!(empc, N, [180, 0], plant=plant2, x_0=[0, 0], x̂_0=[0, 0, 0])
206
210
plot(res2_ry)
207
- savefig(ans, "plot5_NonLinMPC.svg"); nothing # hide
211
+ savefig("plot5_NonLinMPC.svg"); nothing # hide
208
212
```
209
213
210
214
![ plot5_NonLinMPC] ( plot5_NonLinMPC.svg )
@@ -224,7 +228,7 @@ Also, for a 10° step disturbance:
224
228
``` @example 1
225
229
res2_yd = sim!(empc, N, [180; 0]; plant=plant2, x_0=[π, 0], x̂_0=[π, 0, 0], y_step=[10, 0])
226
230
plot(res2_yd)
227
- savefig(ans, "plot6_NonLinMPC.svg"); nothing # hide
231
+ savefig("plot6_NonLinMPC.svg"); nothing # hide
228
232
```
229
233
230
234
![ plot6_NonLinMPC] ( plot6_NonLinMPC.svg )
@@ -264,7 +268,7 @@ The linear controller has difficulties to reject the 10° step disturbance:
264
268
``` @example 1
265
269
res_lin = sim!(mpc, N, [180.0]; plant, x_0=[π, 0], y_step=[10])
266
270
plot(res_lin)
267
- savefig(ans, "plot7_NonLinMPC.svg"); nothing # hide
271
+ savefig("plot7_NonLinMPC.svg"); nothing # hide
268
272
```
269
273
270
274
![ plot7_NonLinMPC] ( plot7_NonLinMPC.svg )
@@ -302,7 +306,7 @@ does improve the rejection of the step disturbance:
302
306
``` @example 1
303
307
res_lin2 = sim!(mpc2, N, [180.0]; plant, x_0=[π, 0], y_step=[10])
304
308
plot(res_lin2)
305
- savefig(ans, "plot8_NonLinMPC.svg"); nothing # hide
309
+ savefig("plot8_NonLinMPC.svg"); nothing # hide
306
310
```
307
311
308
312
![ plot8_NonLinMPC] ( plot8_NonLinMPC.svg )
@@ -316,7 +320,7 @@ poor in the first quadrant:
316
320
``` @example 1
317
321
res_lin3 = sim!(mpc2, N, [180.0]; plant, x_0=[0, 0])
318
322
plot(res_lin3)
319
- savefig(ans, "plot9_NonLinMPC.svg"); nothing # hide
323
+ savefig("plot9_NonLinMPC.svg"); nothing # hide
320
324
```
321
325
322
326
![ plot9_NonLinMPC] ( plot9_NonLinMPC.svg )
@@ -370,7 +374,7 @@ performances are similar to the nonlinear MPC, both for the 180° setpoint:
370
374
``` @example 1
371
375
res_slin = test_slmpc(model, mpc3, [180], plant, x_0=[0, 0])
372
376
plot(res_slin)
373
- savefig(ans, "plot10_NonLinMPC.svg"); nothing # hide
377
+ savefig("plot10_NonLinMPC.svg"); nothing # hide
374
378
```
375
379
376
380
![ plot10_NonLinMPC] ( plot10_NonLinMPC.svg )
@@ -380,11 +384,15 @@ and the 10° step disturbance:
380
384
``` @example 1
381
385
res_slin = test_slmpc(model, mpc3, [180], plant, x_0=[π, 0], y_step=[10])
382
386
plot(res_slin)
383
- savefig(ans, "plot11_NonLinMPC.svg"); nothing # hide
387
+ savefig("plot11_NonLinMPC.svg"); nothing # hide
384
388
```
385
389
386
390
![ plot11_NonLinMPC] ( plot11_NonLinMPC.svg )
387
391
388
392
The computations of the successive linearization MPC are about 125 times faster than the
389
393
nonlinear MPC (0.00012 s per time steps versus 0.015 s per time steps, on average), an
390
394
impressive gain for similar closed-loop performances!
395
+
396
+ ``` @setup 1
397
+ global_logger(old_logger);
398
+ ```
0 commit comments