@@ -73,8 +73,9 @@ using Plots
7373u = [0.5]
7474N = 35
7575res = sim!(model, N, u)
76- plot(res, plotu=false)
77- savefig("plot1_NonLinMPC.svg"); nothing # hide
76+ p = plot(res, plotu=false)
77+ savefig(p, "plot1_NonLinMPC.svg") # hide
78+ display(p) # hide
7879```
7980
8081![ plot1_NonLinMPC] ( plot1_NonLinMPC.svg )
@@ -103,9 +104,11 @@ estimator tuning is tested on a plant with a 25 % larger friction coefficient ``
103104p_plant = copy(p_model)
104105p_plant[3] = 1.25*p_model[3]
105106plant = setname!(NonLinModel(f, h, Ts, nu, nx, ny; p=p_plant); u=vu, x=vx, y=vy)
107+ using Random; Random.seed!(2944) # hide
106108res = sim!(estim, N, [0.5], plant=plant, y_noise=[0.5])
107- plot(res, plotu=false, plotxwithx̂=true)
108- savefig("plot2_NonLinMPC.svg"); nothing # hide
109+ p = plot(res, plotu=false, plotxwithx̂=true)
110+ savefig(p, "plot2_NonLinMPC.svg") # hide
111+ display(p) # hide
109112```
110113
111114![ plot2_NonLinMPC] ( plot2_NonLinMPC.svg )
@@ -132,8 +135,9 @@ The option `Cwt=Inf` disables the slack variable `ϵ` for constraint softening.
132135using JuMP; unset_time_limit_sec(nmpc.optim) # hide
133136ry = [180.0]
134137res_ry = sim!(nmpc, N, ry, plant=plant, x_0=[0, 0], x̂_0=[0, 0, 0])
135- plot(res_ry)
136- savefig("plot3_NonLinMPC.svg"); nothing # hide
138+ p = plot(res_ry)
139+ savefig(p, "plot3_NonLinMPC.svg") # hide
140+ display(p) # hide
137141```
138142
139143![ plot3_NonLinMPC] ( plot3_NonLinMPC.svg )
@@ -144,8 +148,9 @@ satisfactory:
144148
145149``` @example man_nonlin
146150res_yd = sim!(nmpc, N, ry, plant=plant, x_0=[π, 0], x̂_0=[π, 0, 0], y_step=[10])
147- plot(res_yd)
148- savefig("plot4_NonLinMPC.svg"); nothing # hide
151+ p = plot(res_yd)
152+ savefig(p, "plot4_NonLinMPC.svg") # hide
153+ display(p) # hide
149154```
150155
151156![ plot4_NonLinMPC] ( plot4_NonLinMPC.svg )
@@ -217,8 +222,9 @@ setpoint is similar:
217222unset_time_limit_sec(empc.optim) # hide
218223ry = [180.0, 0]
219224res2_ry = sim!(empc, N, ry, plant=plant2, x_0=[0, 0], x̂_0=[0, 0, 0])
220- plot(res2_ry, ploty=[1])
221- savefig("plot5_NonLinMPC.svg"); nothing # hide
225+ p = plot(res2_ry, ploty=[1])
226+ savefig(p, "plot5_NonLinMPC.svg") # hide
227+ display(p) # hide
222228```
223229
224230![ plot5_NonLinMPC] ( plot5_NonLinMPC.svg )
@@ -237,8 +243,9 @@ Also, for a 10° step disturbance:
237243
238244``` @example man_nonlin
239245res2_yd = sim!(empc, N, ry; plant=plant2, x_0=[π, 0], x̂_0=[π, 0, 0], y_step=[10, 0])
240- plot(res2_yd, ploty=[1])
241- savefig("plot6_NonLinMPC.svg"); nothing # hide
246+ p = plot(res2_yd, ploty=[1])
247+ savefig(p, "plot6_NonLinMPC.svg") # hide
248+ display(p) # hide
242249```
243250
244251![ plot6_NonLinMPC] ( plot6_NonLinMPC.svg )
@@ -324,8 +331,9 @@ function plotWithPower(res, Pmax)
324331 plot!(plt2, t, Pmax, label=raw"$P_\mathrm{max}$", linestyle=:dot, linewidth=1.5)
325332 return plot(plt1, plt2, layout=(2,1))
326333end
327- plotWithPower(res3_ry, Pmax)
328- savefig("plot7_NonLinMPC.svg"); nothing # hide
334+ p = plotWithPower(res3_ry, Pmax)
335+ savefig(p, "plot7_NonLinMPC.svg") # hide
336+ display(p) # hide
329337```
330338
331339![ plot7_NonLinMPC] ( plot7_NonLinMPC.svg )
@@ -359,8 +367,9 @@ The linear controller satisfactorily rejects the 10° step disturbance:
359367``` @example man_nonlin
360368ry = [180.0]
361369res_lin = sim!(mpc, N, ry; plant, x_0=[π, 0], y_step=[10])
362- plot(res_lin)
363- savefig("plot9_NonLinMPC.svg"); nothing # hide
370+ p = plot(res_lin)
371+ savefig(p, "plot9_NonLinMPC.svg") # hide
372+ display(p) # hide
364373```
365374
366375![ plot9_NonLinMPC] ( plot9_NonLinMPC.svg )
@@ -398,8 +407,9 @@ does slightly improve the rejection of the step disturbance:
398407
399408``` @example man_nonlin
400409res_lin2 = sim!(mpc2, N, ry; plant, x_0=[π, 0], y_step=[10])
401- plot(res_lin2)
402- savefig("plot10_NonLinMPC.svg"); nothing # hide
410+ p = plot(res_lin2)
411+ savefig(p, "plot10_NonLinMPC.svg") # hide
412+ display(p) # hide
403413```
404414
405415![ plot10_NonLinMPC] ( plot10_NonLinMPC.svg )
@@ -418,8 +428,9 @@ results:
418428
419429``` @example man_nonlin
420430res_ms = sim!(mpc_ms, N, ry; plant, x_0=[π, 0], y_step=[10])
421- plot!(res_ms)
422- savefig("plot10b_NonLinMPC.svg"); nothing # hide
431+ plot!(p, res_ms)
432+ savefig(p, "plot10b_NonLinMPC.svg") # hide
433+ display(p) # hide
423434```
424435
425436![ plot10b_NonLinMPC] ( plot10b_NonLinMPC.svg )
@@ -490,8 +501,9 @@ operating point. The [`SimResult`](@ref) object is for plotting purposes only. T
490501``` @example man_nonlin
491502x_0 = [0, 0]; x̂_0 = [0, 0, 0];
492503res_slin = sim_adapt!(mpc3, model, N, ry, plant, x_0, x̂_0)
493- plot(res_slin)
494- savefig("plot12_NonLinMPC.svg"); nothing # hide
504+ p = plot(res_slin)
505+ savefig(p, "plot12_NonLinMPC.svg") # hide
506+ display(p) # hide
495507```
496508
497509![ plot12_NonLinMPC] ( plot12_NonLinMPC.svg )
@@ -501,8 +513,9 @@ and the 10° step disturbance:
501513``` @example man_nonlin
502514x_0 = [π, 0]; x̂_0 = [π, 0, 0]; y_step = [10]
503515res_slin = sim_adapt!(mpc3, model, N, ry, plant, x_0, x̂_0, y_step)
504- plot(res_slin)
505- savefig("plot13_NonLinMPC.svg"); nothing # hide
516+ p = plot(res_slin)
517+ savefig(p, "plot13_NonLinMPC.svg") # hide
518+ display(p) # hide
506519```
507520
508521![ plot13_NonLinMPC] ( plot13_NonLinMPC.svg )
0 commit comments