44Pages = ["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
914In this example, the goal is to control the angular position `` θ `` of a pendulum
@@ -70,7 +75,7 @@ u = [0.5]
7075N = 35
7176res = sim!(model, N, u)
7277plot(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)
99104plant = setname!(NonLinModel(f_plant, h, Ts, nu, nx, ny); u=vu, x=vx, y=vy)
100105res = sim!(estim, N, [0.5], plant=plant, y_noise=[0.5])
101106plot(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.
121126performance 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
126130res_ry = sim!(nmpc, N, [180.0], plant=plant, x_0=[0, 0], x̂_0=[0, 0, 0])
127131plot(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
138142res_yd = sim!(nmpc, N, [180.0], plant=plant, x_0=[π, 0], x̂_0=[π, 0, 0], y_step=[10])
139143plot(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
201205setpoint is similar:
202206
203207``` @example 1
204- unset_time_limit_sec(empc.optim) # hide
208+ unset_time_limit_sec(empc.optim) # hide
205209res2_ry = sim!(empc, N, [180, 0], plant=plant2, x_0=[0, 0], x̂_0=[0, 0, 0])
206210plot(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
225229res2_yd = sim!(empc, N, [180; 0]; plant=plant2, x_0=[π, 0], x̂_0=[π, 0, 0], y_step=[10, 0])
226230plot(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
265269res_lin = sim!(mpc, N, [180.0]; plant, x_0=[π, 0], y_step=[10])
266270plot(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
303307res_lin2 = sim!(mpc2, N, [180.0]; plant, x_0=[π, 0], y_step=[10])
304308plot(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
317321res_lin3 = sim!(mpc2, N, [180.0]; plant, x_0=[0, 0])
318322plot(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
371375res_slin = test_slmpc(model, mpc3, [180], plant, x_0=[0, 0])
372376plot(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
381385res_slin = test_slmpc(model, mpc3, [180], plant, x_0=[π, 0], y_step=[10])
382386plot(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
388392The computations of the successive linearization MPC are about 125 times faster than the
389393nonlinear MPC (0.00012 s per time steps versus 0.015 s per time steps, on average), an
390394impressive gain for similar closed-loop performances!
395+
396+ ``` @setup 1
397+ global_logger(old_logger);
398+ ```
0 commit comments