Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 6 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
- package-ecosystem: "julia"
directory: "/"
directories: # Location of Julia projects
- "/"
- "/docs"
- "/test"
- "/benchmark"
schedule:
interval: "weekly"
# groups: # uncomment to group all julia package updates into a single PR
# all-julia-packages:
# patterns:
# - "*"
interval: "weekly"
16 changes: 0 additions & 16 deletions .github/workflows/CompatHelper.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ModelPredictiveControl"
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
version = "2.15.0"
version = "2.15.1"
authors = ["Francis Gagnon"]

[deps]
Expand Down
24 changes: 11 additions & 13 deletions docs/src/manual/mtk.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
Pages = ["mtk.md"]
```

```@setup 1
using Logging; errlogger = ConsoleLogger(stderr, Error);
old_logger = global_logger(); global_logger(errlogger);
```

## Pendulum Model

This example integrates the simple pendulum model of the [penultimate section](@ref man_nonlin)
Expand Down Expand Up @@ -150,27 +145,30 @@ The 180° setpoint response is identical:
using Plots
N = 35
using JuMP; unset_time_limit_sec(nmpc.optim) # hide
using Logging # hide
res_ry = with_logger(ConsoleLogger(stderr, Error)) do # hide
res_ry = sim!(nmpc, N, [180.0], plant=plant, x_0=[0, 0], x̂_0=[0, 0, 0])
plot(res_ry)
savefig("plot1_MTK.svg"); nothing # hide
end #
p = plot(res_ry)
savefig(p, "plot1_MTK.svg") # hide
display(p) # hide
```

![plot1_MTK](plot1_MTK.svg)

and also the output disturbance rejection:

```@example 1
res_yd = with_logger(ConsoleLogger(stderr, Error)) do # hide
res_yd = sim!(nmpc, N, [180.0], plant=plant, x_0=[0, π], x̂_0=[0, π, 0], y_step=[10])
plot(res_yd)
savefig("plot2_MTK.svg"); nothing # hide
end # hide
p = plot(res_yd)
savefig(p, "plot2_MTK.svg") # hide
display(p) # hide
```

![plot2_MTK](plot2_MTK.svg)

## Acknowledgement

Authored by `1-Bart-1` and `baggepinnen`, thanks for the contribution.

```@setup 1
global_logger(old_logger);
```
61 changes: 37 additions & 24 deletions docs/src/manual/nonlinmpc1.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ using Plots
u = [0.5]
N = 35
res = sim!(model, N, u)
plot(res, plotu=false)
savefig("plot1_NonLinMPC.svg"); nothing # hide
p = plot(res, plotu=false)
savefig(p, "plot1_NonLinMPC.svg") # hide
display(p) # hide
```

![plot1_NonLinMPC](plot1_NonLinMPC.svg)
Expand Down Expand Up @@ -103,9 +104,11 @@ estimator tuning is tested on a plant with a 25 % larger friction coefficient ``
p_plant = copy(p_model)
p_plant[3] = 1.25*p_model[3]
plant = setname!(NonLinModel(f, h, Ts, nu, nx, ny; p=p_plant); u=vu, x=vx, y=vy)
using Random; Random.seed!(2944) # hide
res = sim!(estim, N, [0.5], plant=plant, y_noise=[0.5])
plot(res, plotu=false, plotxwithx̂=true)
savefig("plot2_NonLinMPC.svg"); nothing # hide
p = plot(res, plotu=false, plotxwithx̂=true)
savefig(p, "plot2_NonLinMPC.svg") # hide
display(p) # hide
```

![plot2_NonLinMPC](plot2_NonLinMPC.svg)
Expand All @@ -132,8 +135,9 @@ The option `Cwt=Inf` disables the slack variable `ϵ` for constraint softening.
using JuMP; unset_time_limit_sec(nmpc.optim) # hide
ry = [180.0]
res_ry = sim!(nmpc, N, ry, plant=plant, x_0=[0, 0], x̂_0=[0, 0, 0])
plot(res_ry)
savefig("plot3_NonLinMPC.svg"); nothing # hide
p = plot(res_ry)
savefig(p, "plot3_NonLinMPC.svg") # hide
display(p) # hide
```

![plot3_NonLinMPC](plot3_NonLinMPC.svg)
Expand All @@ -144,8 +148,9 @@ satisfactory:

```@example man_nonlin
res_yd = sim!(nmpc, N, ry, plant=plant, x_0=[π, 0], x̂_0=[π, 0, 0], y_step=[10])
plot(res_yd)
savefig("plot4_NonLinMPC.svg"); nothing # hide
p = plot(res_yd)
savefig(p, "plot4_NonLinMPC.svg") # hide
display(p) # hide
```

![plot4_NonLinMPC](plot4_NonLinMPC.svg)
Expand Down Expand Up @@ -217,8 +222,9 @@ setpoint is similar:
unset_time_limit_sec(empc.optim) # hide
ry = [180.0, 0]
res2_ry = sim!(empc, N, ry, plant=plant2, x_0=[0, 0], x̂_0=[0, 0, 0])
plot(res2_ry, ploty=[1])
savefig("plot5_NonLinMPC.svg"); nothing # hide
p = plot(res2_ry, ploty=[1])
savefig(p, "plot5_NonLinMPC.svg") # hide
display(p) # hide
```

![plot5_NonLinMPC](plot5_NonLinMPC.svg)
Expand All @@ -237,8 +243,9 @@ Also, for a 10° step disturbance:

```@example man_nonlin
res2_yd = sim!(empc, N, ry; plant=plant2, x_0=[π, 0], x̂_0=[π, 0, 0], y_step=[10, 0])
plot(res2_yd, ploty=[1])
savefig("plot6_NonLinMPC.svg"); nothing # hide
p = plot(res2_yd, ploty=[1])
savefig(p, "plot6_NonLinMPC.svg") # hide
display(p) # hide
```

![plot6_NonLinMPC](plot6_NonLinMPC.svg)
Expand Down Expand Up @@ -324,8 +331,9 @@ function plotWithPower(res, Pmax)
plot!(plt2, t, Pmax, label=raw"$P_\mathrm{max}$", linestyle=:dot, linewidth=1.5)
return plot(plt1, plt2, layout=(2,1))
end
plotWithPower(res3_ry, Pmax)
savefig("plot7_NonLinMPC.svg"); nothing # hide
p = plotWithPower(res3_ry, Pmax)
savefig(p, "plot7_NonLinMPC.svg") # hide
display(p) # hide
```

![plot7_NonLinMPC](plot7_NonLinMPC.svg)
Expand Down Expand Up @@ -359,8 +367,9 @@ The linear controller satisfactorily rejects the 10° step disturbance:
```@example man_nonlin
ry = [180.0]
res_lin = sim!(mpc, N, ry; plant, x_0=[π, 0], y_step=[10])
plot(res_lin)
savefig("plot9_NonLinMPC.svg"); nothing # hide
p = plot(res_lin)
savefig(p, "plot9_NonLinMPC.svg") # hide
display(p) # hide
```

![plot9_NonLinMPC](plot9_NonLinMPC.svg)
Expand Down Expand Up @@ -398,8 +407,9 @@ does slightly improve the rejection of the step disturbance:

```@example man_nonlin
res_lin2 = sim!(mpc2, N, ry; plant, x_0=[π, 0], y_step=[10])
plot(res_lin2)
savefig("plot10_NonLinMPC.svg"); nothing # hide
p = plot(res_lin2)
savefig(p, "plot10_NonLinMPC.svg") # hide
display(p) # hide
```

![plot10_NonLinMPC](plot10_NonLinMPC.svg)
Expand All @@ -418,8 +428,9 @@ results:

```@example man_nonlin
res_ms = sim!(mpc_ms, N, ry; plant, x_0=[π, 0], y_step=[10])
plot!(res_ms)
savefig("plot10b_NonLinMPC.svg"); nothing # hide
plot!(p, res_ms)
savefig(p, "plot10b_NonLinMPC.svg") # hide
display(p) # hide
```

![plot10b_NonLinMPC](plot10b_NonLinMPC.svg)
Expand Down Expand Up @@ -490,8 +501,9 @@ operating point. The [`SimResult`](@ref) object is for plotting purposes only. T
```@example man_nonlin
x_0 = [0, 0]; x̂_0 = [0, 0, 0];
res_slin = sim_adapt!(mpc3, model, N, ry, plant, x_0, x̂_0)
plot(res_slin)
savefig("plot12_NonLinMPC.svg"); nothing # hide
p = plot(res_slin)
savefig(p, "plot12_NonLinMPC.svg") # hide
display(p) # hide
```

![plot12_NonLinMPC](plot12_NonLinMPC.svg)
Expand All @@ -501,8 +513,9 @@ and the 10° step disturbance:
```@example man_nonlin
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("plot13_NonLinMPC.svg"); nothing # hide
p = plot(res_slin)
savefig(p, "plot13_NonLinMPC.svg") # hide
display(p) # hide
```

![plot13_NonLinMPC](plot13_NonLinMPC.svg)
Expand Down
25 changes: 14 additions & 11 deletions docs/src/manual/nonlinmpc2.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ We can now plot the result:

```@example 1
using Plots
plot(res, plotu=true, plotd=true)
savefig("plot1_DAEpH.svg"); nothing # hide
p = plot(res, plotu=true, plotd=true)
savefig(p, "plot1_DAEpH.svg") # hide
display(p) # hide
```

![plot1_DAEpH](plot1_DAEpH.svg)
Expand Down Expand Up @@ -314,6 +315,7 @@ performs under pH and flow rate measurement noise:

```@example 1
using Random
Random.seed!(1123) # hide
function simMHE(mhe, plant, N; x_0, x̂_0)
ny, ny, nd, nx, nx̂ = plant.ny, plant.ny, plant.nd, plant.nx, mhe.nx̂
Y_data, U_data, D_data = zeros(ny, N), zeros(nu, N), zeros(nd, N)
Expand Down Expand Up @@ -349,7 +351,7 @@ end
x̂_0 = [0.025, 0.025, c_Ain]
res = simMHE(mhe, plant, N; x_0, x̂_0)
p = plot(res, plotd=false, plotu=false, plotxwithx̂=true, plotx̂min=false)
savefig(p, "plot2_DAEpH.svg"); nothing # hide
savefig(p, "plot2_DAEpH.svg") # hide
display(p) # hide
```

Expand Down Expand Up @@ -424,11 +426,11 @@ function simNMPC(nmpc, plant, N, ry; x_0, x̂_0, noise=false)
end
N2, ry = 61, [7.0]
using Logging # hide
res2 = with_logger(ConsoleLogger(stderr, Error)) do # hide
res2 = simNMPC(nmpc, plant, N2, ry; x_0=[0.07, 0.04], x̂_0)
res = with_logger(ConsoleLogger(stderr, Error)) do # hide
res = simNMPC(nmpc, plant, N2, ry; x_0=[0.07, 0.04], x̂_0)
end # hide
p = plot(res2, plotd=false, plotxwithx̂=true, plotx̂min=false, plotŷ=true)
savefig(p, "plot3_DAEpH.svg"); nothing # hide
p = plot(res, plotd=false, plotxwithx̂=true, plotx̂min=false, plotŷ=true)
savefig(p, "plot3_DAEpH.svg") # hide
display(p) # hide
```

Expand All @@ -440,11 +442,12 @@ measurement noise, the pH constraints are occasionally violated briefly, but the
law responds quickly and returns the effluent pH to the specified range:

```@example 1
res3 = with_logger(ConsoleLogger(stderr, Error)) do # hide
res3 = simNMPC(nmpc, plant, N2, ry; x_0=[0.07, 0.04], x̂_0, noise=true)
res = with_logger(ConsoleLogger(stderr, Error)) do # hide
Random.seed!(5379) # hide
res = simNMPC(nmpc, plant, N2, ry; x_0=[0.07, 0.04], x̂_0, noise=true)
end # hide
p = plot(res3, plotd=false, plotxwithx̂=true, plotx̂min=false, plotŷ=true)
savefig(p, "plot4_DAEpH.svg"); nothing # hide
p = plot(res, plotd=false, plotxwithx̂=true, plotx̂min=false, plotŷ=true)
savefig(p, "plot4_DAEpH.svg") # hide
display(p) # hide
```

Expand Down
Loading