Skip to content

Commit 5548ac9

Browse files
committed
doc: minor modifications in slmpc simulation function
1 parent efd3d58 commit 5548ac9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

docs/src/manual/nonlinmpc.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,14 @@ mpc3 = setconstraint!(mpc3; umin, umax)
351351
We create a function that simulates the plant and the adaptive controller:
352352

353353
```@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])
356355
U_data, Y_data, Ry_data = zeros(plant.nu, N), zeros(plant.ny, N), zeros(plant.ny, N)
357356
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
360360
for i = 1:N
361-
y = plant() .+ y_step
361+
y = plant() + y_step
362362
u = moveinput!(mpc, ry)
363363
linmodel = linearize(nonlinmodel; u, x=x̂[1:2])
364364
setmodel!(mpc, linmodel)
@@ -378,7 +378,8 @@ The [`SimResult`](@ref) object is for plotting purposes only. The adaptive [`Lin
378378
performances are similar to the nonlinear MPC, both for the 180° setpoint:
379379

380380
```@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)
382383
plot(res_slin)
383384
savefig("plot10_NonLinMPC.svg"); nothing # hide
384385
```
@@ -388,7 +389,8 @@ savefig("plot10_NonLinMPC.svg"); nothing # hide
388389
and the 10° step disturbance:
389390

390391
```@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)
392394
plot(res_slin)
393395
savefig("plot11_NonLinMPC.svg"); nothing # hide
394396
```

0 commit comments

Comments
 (0)