@@ -351,14 +351,14 @@ mpc3 = setconstraint!(mpc3; umin, umax)
351
351
We create a function that simulates the plant and the adaptive controller:
352
352
353
353
``` @example 1
354
- function test_slmpc(nonlinmodel, mpc, ry, plant; x_0=plant.xop, y_step=0)
355
- N = 35
354
+ function sim_adapt!(mpc, nonlinmodel, N, ry, plant, x_0, x̂_0, y_step=[0])
356
355
U_data, Y_data, Ry_data = zeros(plant.nu, N), zeros(plant.ny, N), zeros(plant.ny, N)
357
356
setstate!(plant, x_0)
358
- u, y = [0.0], plant()
359
- x̂ = initstate!(mpc, u, y)
357
+ initstate!(mpc, [0], plant())
358
+ setstate!(mpc, x̂_0)
359
+ x̂ = x̂_0
360
360
for i = 1:N
361
- y = plant() . + y_step
361
+ y = plant() + y_step
362
362
u = moveinput!(mpc, ry)
363
363
linmodel = linearize(nonlinmodel; u, x=x̂[1:2])
364
364
setmodel!(mpc, linmodel)
@@ -378,7 +378,8 @@ The [`SimResult`](@ref) object is for plotting purposes only. The adaptive [`Lin
378
378
performances are similar to the nonlinear MPC, both for the 180° setpoint:
379
379
380
380
``` @example 1
381
- res_slin = test_slmpc(model, mpc3, [180], plant, x_0=[0, 0])
381
+ x_0 = [0, 0]; x̂_0 = [0, 0, 0]; ry = [180]
382
+ res_slin = sim_adapt!(mpc3, model, N, ry, plant, x_0, x̂_0)
382
383
plot(res_slin)
383
384
savefig("plot10_NonLinMPC.svg"); nothing # hide
384
385
```
@@ -388,7 +389,8 @@ savefig("plot10_NonLinMPC.svg"); nothing # hide
388
389
and the 10° step disturbance:
389
390
390
391
``` @example 1
391
- res_slin = test_slmpc(model, mpc3, [180], plant, x_0=[π, 0], y_step=[10])
392
+ x_0 = [π, 0]; x̂_0 = [π, 0, 0]; y_step = [10]
393
+ res_slin = sim_adapt!(mpc3, model, N, ry, plant, x_0, x̂_0, y_step)
392
394
plot(res_slin)
393
395
savefig("plot11_NonLinMPC.svg"); nothing # hide
394
396
```
0 commit comments