Skip to content

Minor correction doc #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions docs/src/manual/nonlinmpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,25 +338,27 @@ the [`LinMPC`](@ref) instance based on repeated online linearization.
The [`setmodel!`](@ref) method allows online adaptation of a linear plant model. Combined
with the automatic linearization of [`linearize`](@ref), a successive linearization MPC can
be designed with minimal efforts. The [`SteadyKalmanFilter`](@ref) does not support
[`setmodel!`](@ref), so we need to use the time-varying [`KalmanFilter`](@ref) instead:
[`setmodel!`](@ref) so we need to use the time-varying [`KalmanFilter`](@ref), and we
initialize it with a linearization at ``θ = ω = τ = 0``:

```@example 1
kf = KalmanFilter(linmodel; σQ, σR, nint_u, σQint_u)
linmodel = linearize(model, x=[0, 0], u=[0])
kf = KalmanFilter(linmodel; σQ, σR, nint_u, σQint_u)
mpc3 = LinMPC(kf; Hp, Hc, Mwt, Nwt, Cwt=Inf, optim=daqp)
mpc3 = setconstraint!(mpc3; umin, umax)
```

We create a function that simulates the plant and the adaptive controller:

```@example 1
function test_slmpc(nonlinmodel, mpc, ry, plant; x_0=plant.xop, y_step=0)
N = 35
function sim_adapt!(mpc, nonlinmodel, N, ry, plant, x_0, x̂_0, y_step=[0])
U_data, Y_data, Ry_data = zeros(plant.nu, N), zeros(plant.ny, N), zeros(plant.ny, N)
setstate!(plant, x_0)
u, y = [0.0], plant()
x̂ = initstate!(mpc, u, y)
initstate!(mpc, [0], plant())
setstate!(mpc, x̂_0)
x̂ = x̂_0
for i = 1:N
y = plant() .+ y_step
y = plant() + y_step
u = moveinput!(mpc, ry)
linmodel = linearize(nonlinmodel; u, x=x̂[1:2])
setmodel!(mpc, linmodel)
Expand All @@ -376,7 +378,8 @@ The [`SimResult`](@ref) object is for plotting purposes only. The adaptive [`Lin
performances are similar to the nonlinear MPC, both for the 180° setpoint:

```@example 1
res_slin = test_slmpc(model, mpc3, [180], plant, x_0=[0, 0])
x_0 = [0, 0]; x̂_0 = [0, 0, 0]; ry = [180]
res_slin = sim_adapt!(mpc3, model, N, ry, plant, x_0, x̂_0)
plot(res_slin)
savefig("plot10_NonLinMPC.svg"); nothing # hide
```
Expand All @@ -386,7 +389,8 @@ savefig("plot10_NonLinMPC.svg"); nothing # hide
and the 10° step disturbance:

```@example 1
res_slin = test_slmpc(model, mpc3, [180], plant, x_0=[π, 0], y_step=[10])
x_0 = [π, 0]; x̂_0 = [π, 0, 0]; y_step = [10]
res_slin = sim_adapt!(mpc3, model, N, ry, plant, x_0, x̂_0, y_step)
plot(res_slin)
savefig("plot11_NonLinMPC.svg"); nothing # hide
```
Expand Down
Loading