From 6ea28b0038fad8e6cd08be0c9902a1bcd5b8c2f6 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Sun, 15 Nov 2026 17:39:20 -0500 Subject: [PATCH 1/9] wip: support `d` in conversion from MTK --- docs/src/manual/mtk.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index a2d334e98..9d89e3071 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -35,9 +35,10 @@ model, with combined differential states and algebraic variables in a single vec using ModelPredictiveControl, ModelingToolkit using ModelingToolkit: D_nounits as D, t_nounits as t -function generate_f_h_mtk(model, inputs, outputs) +function generate_f_h_mtk(model, inputs, outputs, disturbances=nothing) + known_disturbance_inputs = disturbances (_, f_ip), x_sym, p_sym, io_sys = ModelingToolkit.generate_control_function( - model, inputs, split=false, simplify=true + model, inputs; known_disturbance_inputs, split=false, simplify=true ) i_alg = ModelingToolkit.is_alg_equation.(equations(io_sys)) function f_mtk!(ẋ, x, u, _ , p) @@ -248,7 +249,8 @@ The MTK model of the neutralization reactor from the [last section](@ref man_dae constructed as follows: ```@example 1 -@parameters c_Ain=0.1 c_Bin=0.1 Kw=1e-14 Ka=1.75e-5 V=1000 q_Ain=10 +@parameters c_Ain=0.1 c_Bin=0.1 Kw=1e-14 Ka=1.75e-5 V=1000 +@variables q_Ain(t)=10 @variables c_A(t)=0.025 c_B(t)=0.025 q_Bin(t)=10 pH(t)=7.0 @variables q_out(t) c_Aout(t) c_Bout(t) eqs = [ @@ -266,8 +268,10 @@ The substitution ``a_H = 10^{-\mathrm{pH}}`` is explicitly applied in the algebr to improve the numerical conditioning of the system. The converted model is: ```@example 1 -inputs, outputs = [q_Bin], [pH] -f_mtk!, h_mtk!, p_sym, p, x_sym, x, i_alg = generate_f_h_mtk(mtk_model, inputs, outputs) +inputs, outputs, disturbances = [q_Bin], [pH], [q_Ain] +f_mtk!, h_mtk!, p_sym, p, x_sym, x, i_alg = generate_f_h_mtk( + mtk_model, inputs, outputs, disturbances +) [x_sym x] ``` From 59d9138d1110cdf60ecb594090550e511d069e65 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 16 Nov 2026 09:03:34 -0500 Subject: [PATCH 2/9] doc: support `d` in MTK model conversion --- docs/src/manual/mtk.md | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index 9d89e3071..e93266b44 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -15,8 +15,7 @@ objects. This object is then used to design controllers similar to the previous !!! danger "Disclaimer" This simple example is not an official interface to `ModelingToolkit.jl`. It is provided as a basic starting template to combine both packages. There is no guarantee that it - will work for all corner cases. For instance, measured disturbances are not supported in - the current implementation (to be added). + will work for all corner cases. ```@codeblocks line_counter = :continue @@ -41,9 +40,11 @@ function generate_f_h_mtk(model, inputs, outputs, disturbances=nothing) model, inputs; known_disturbance_inputs, split=false, simplify=true ) i_alg = ModelingToolkit.is_alg_equation.(equations(io_sys)) - function f_mtk!(ẋ, x, u, _ , p) + nd = isnothing(disturbances) ? 0 : length(disturbances) + f_ip_with_d = (nd < 1) ? (ẋ, x, u, p, t, _ ) -> f_ip(ẋ, x, u, p, t) : f_ip + function f_mtk!(ẋ, x, u, d, p) try - f_ip(ẋ, x, u, p, nothing) + f_ip_with_d(ẋ, x, u, p, nothing, d) catch err if err isa MethodError error("NonLinModel does not support a time argument t in the f "* @@ -55,15 +56,16 @@ function generate_f_h_mtk(model, inputs, outputs, disturbances=nothing) return nothing end (_, h_ip) = ModelingToolkit.build_explicit_observed_function( - io_sys, outputs; inputs, return_inplace = true + io_sys, outputs; inputs, known_disturbance_inputs, return_inplace = true ) + h_ip_with_d = (nd < 1) ? (y, x, u, p, t, _ ) -> h_ip(y, x, u, p, t) : h_ip u_nothing = fill(nothing, length(inputs)) - function h_mtk!(y, x, _ , p) + function h_mtk!(y, x, d, p) try # MTK.jl supports a `u` argument in `h_ip` function but not this package. We # set `u` as a vector of nothing and `h_ip` function will presumably throw # an MethodError if this argument is used inside the function - h_ip(y, x, u_nothing, p, nothing) + h_ip_with_d(y, x, u_nothing, p, nothing, d) catch err if err isa MethodError error("NonLinModel only support strictly proper systems (no "* @@ -100,10 +102,11 @@ this package's interface: ```@example 1 function generate_model( - f_mtk!::F, h_mtk!::H, Ts, i_alg, inputs, outputs, p; - xs_mtk=zeros(length(i_alg)), unit="s", transcription=OrthogonalCollocation() + f_mtk!::F, h_mtk!::H, Ts, i_alg, inputs, outputs, disturbances=nothing; + p=nothing, xs_mtk=zeros(length(i_alg)), unit="s", transcription=OrthogonalCollocation() ) where {F<:Function, H<:Function} nu, ny = length(inputs), length(outputs) + nd = isnothing(disturbances) ? 0 : length(disturbances) nx_mtk::Int = length(i_alg) na::Int = sum(i_alg) nx::Int = nx_mtk - na @@ -130,11 +133,11 @@ function generate_model( end xs_0, as_0 = xs_mtk[i_x], xs_mtk[i_a] model = NonLinModelDAE( - fq!, h!, Ts, nu, nx, na, ny; p, unit, xs_0, as_0, transcription + fq!, h!, Ts, nu, nx, na, ny, nd; p, unit, xs_0, as_0, transcription ) else f!, h! = f_mtk!, h_mtk! - model = NonLinModel(f!, h!, Ts, nu, nx, ny; p, unit) + model = NonLinModel(f!, h!, Ts, nu, nx, ny, nd; p, unit) end return model # deliberately type unstable function end @@ -179,7 +182,7 @@ We can now construct a [`SimModel`](@ref) with this specific state realization: ```@example 1 Ts = 0.1 -model = generate_model(f_mtk!, h_mtk!, Ts, i_alg, inputs, outputs, p) +model = generate_model(f_mtk!, h_mtk!, Ts, i_alg, inputs, outputs; p) vu, vx, vy = ["\$τ\$ (Nm)"], ["\$ω\$ (rad/s)", "\$θ\$ (rad)"], ["\$θ\$ (°)"] model = setname!(model; u=vu, x=vx, y=vy) ``` @@ -192,7 +195,7 @@ coefficient ``K``: i_K = findfirst(==("K"), string.(p_sym)) p2 = copy(p) p2[i_K] = 1.25*p[i_K] -plant = generate_model(f_mtk!, h_mtk!, Ts, i_alg, inputs, outputs, p2) +plant = generate_model(f_mtk!, h_mtk!, Ts, i_alg, inputs, outputs; p=p2) plant = setname!(plant; u=vu, x=vx, y=vy) ``` @@ -291,11 +294,12 @@ Ts, unit = 0.5, "h" xs_mtk = x transcription = TrapezoidalCollocation() model = generate_model( - f_mtk!, h_mtk!, Ts, i_alg, inputs, outputs, p; xs_mtk, unit, transcription + f_mtk!, h_mtk!, Ts, i_alg, inputs, outputs, disturbances; + p, xs_mtk, unit, transcription ) -vu = [raw"$q_{Bin}$ (L/min)"] +vu, vd = [raw"$q_{Bin}$ (L/min)"], [raw"$q_{Ain}$ (L/min)"] vx, vy = [raw"$c_B$ (mol/L)", raw"$c_A$ (mol/L)"], [raw"$\mathrm{pH}$"] -model = setname!(model, u=vu, y=vy, x=vx) +model = setname!(model, u=vu, d=vd, y=vy, x=vx) ``` The returned value is a [`NonLinModelDAE`](@ref) object, as expected. The transient @@ -304,11 +308,11 @@ response is identical to the first 10 hours of the open-loop simulations of the ```@example 1 using Plots -u, x_0 = [10.0], [0.0495, 0.0505] +u, d, x_0 = [10.0], [10.0], [0.0495, 0.0505] N = 21 using Logging # hide res = with_logger(ConsoleLogger(stderr, Error)) do # hide -res = sim!(model, N, u; x_0) +res = sim!(model, N, u, d; x_0) end # hide p = plot(res) savefig(p, "plot3_MTK.svg") # hide From 56e12af049f09634313b6a553d33daf42548f46c Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 16 Nov 2026 09:34:42 -0500 Subject: [PATCH 3/9] doc: wip adaptive MHE with MTK --- docs/src/manual/mtk.md | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index e93266b44..2336cf4d0 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -77,6 +77,7 @@ function generate_f_h_mtk(model, inputs, outputs, disturbances=nothing) return nothing end ic = initial_conditions(io_sys) + io_sys |> equations |> display p_map, x_map = try ( Dict(sym => ic[sym] for sym in p_sym), @@ -321,6 +322,49 @@ display(p) # hide ![plot3_MTK](plot3_MTK.svg) +```@example 1 +using Plots +u, d, x_0 = [10.0], [10.0], [0.0495, 0.0505] +N = 21 +using Logging # hide +res = with_logger(ConsoleLogger(stderr, Error)) do # hide +res = sim!(model, N, u, d; x_0) +end # hide +p = plot(res) +savefig(p, "plot3_MTK.svg") # hide +display(p) # hide +``` + +```@example 1 +@variables c_Ain_s(t)=0.1 +eqs_2 = [ + D(c_A) ~ 60/V*(q_Ain * c_Ain_s - q_out * c_Aout) + D(c_B) ~ 60/V*(q_Bin * c_Bin - q_out * c_Bout) + D(c_Ain_s) ~ 0 + 0 ~ 10^(-pH) + c_B - (Kw / 10^(-pH)) - (Ka * c_A / (Ka + 10^(-pH))) + q_out ~ q_Ain + q_Bin + c_Aout ~ c_A + c_Bout ~ c_B +] +@named mtk_model_2 = System(eqs_2, t) +f_mtk!, h_mtk!, p_sym, p, x_sym, x, i_alg = generate_f_h_mtk( + mtk_model_2, inputs, outputs, disturbances +) +[x_sym x] +``` + +```@example 1 +``` + +```@example 1 +model = generate_model( + f_mtk!, h_mtk!, Ts, i_alg, inputs, outputs, disturbances; + p, xs_mtk, unit, transcription +) +vx̂ = [vx; raw"$c_{Ain}$ (mol/L)"] +model = setname!(model, u=vu, d=vd, y=vy, x=vx̂) +``` + ## Acknowledgement Authored by `1-Bart-1` and `baggepinnen`, thanks for the contribution. From f80df48e1d0dc55e90cf681754ac3f68b205207b Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 16 Nov 2026 11:06:24 -0500 Subject: [PATCH 4/9] doc: simple MHE and NMPC of the pH tank with MTK --- docs/src/manual/mtk.md | 58 ++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index 2336cf4d0..2f1c398e5 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -77,7 +77,6 @@ function generate_f_h_mtk(model, inputs, outputs, disturbances=nothing) return nothing end ic = initial_conditions(io_sys) - io_sys |> equations |> display p_map, x_map = try ( Dict(sym => ic[sym] for sym in p_sym), @@ -323,48 +322,47 @@ display(p) # hide ![plot3_MTK](plot3_MTK.svg) ```@example 1 -using Plots -u, d, x_0 = [10.0], [10.0], [0.0495, 0.0505] -N = 21 +nint_u=[1] # integrating state at the q_Bin input +He = 8; hessian = true +σQ = [0.5e-3, 0.5e-3]; σR=[0.05]; σP_0 = [0.05, 0.05]; σQint_u=[0.15]; σPint_u_0=[0.075] +mhe = MovingHorizonEstimator(model; nint_u, He, hessian, σQ, σR, σP_0, σQint_u, σPint_u_0) +using JuMP; unset_time_limit_sec(mhe.optim) # no wall time limit during optimization +mhe = setconstraint!(mhe, x̂min=[0, 0, -Inf]) +``` + +```@example 1 +x_0, x̂_0 = [0.0495, 0.0505], [0.025, 0.025, 0] using Logging # hide res = with_logger(ConsoleLogger(stderr, Error)) do # hide -res = sim!(model, N, u, d; x_0) +res = sim!(mhe, N, u, d; x_0, x̂_0) end # hide -p = plot(res) -savefig(p, "plot3_MTK.svg") # hide +p = plot(res, plotd=false, plotu=false, plotxwithx̂=true, plotx̂min=false) +savefig(p, "plot4_DAEpH.svg") # hide display(p) # hide ``` -```@example 1 -@variables c_Ain_s(t)=0.1 -eqs_2 = [ - D(c_A) ~ 60/V*(q_Ain * c_Ain_s - q_out * c_Aout) - D(c_B) ~ 60/V*(q_Bin * c_Bin - q_out * c_Bout) - D(c_Ain_s) ~ 0 - 0 ~ 10^(-pH) + c_B - (Kw / 10^(-pH)) - (Ka * c_A / (Ka + 10^(-pH))) - q_out ~ q_Ain + q_Bin - c_Aout ~ c_A - c_Bout ~ c_B -] -@named mtk_model_2 = System(eqs_2, t) -f_mtk!, h_mtk!, p_sym, p, x_sym, x, i_alg = generate_f_h_mtk( - mtk_model_2, inputs, outputs, disturbances -) -[x_sym x] -``` +![plot4_MTK](plot4_MTK.svg) ```@example 1 +nmpc = NonLinMPC(mhe, Hp=8, Hc=2, Nwt=[5.0], hessian=true) +using JuMP; unset_time_limit_sec(nmpc.optim) # no wall time limit during optimization +nmpc = setconstraint!(nmpc, ymin=[6], ymax=[8], umin=[0], umax=[20]) ``` ```@example 1 -model = generate_model( - f_mtk!, h_mtk!, Ts, i_alg, inputs, outputs, disturbances; - p, xs_mtk, unit, transcription -) -vx̂ = [vx; raw"$c_{Ain}$ (mol/L)"] -model = setname!(model, u=vu, d=vd, y=vy, x=vx̂) +ry = [7.0] +x_0, x̂_0 = [0.04, 0.07], [0.025, 0.025, 0] +using Logging # hide +res = with_logger(ConsoleLogger(stderr, Error)) do # hide +res = sim!(nmpc, N, ry, d; x_0, x̂_0) +end # hide +p = plot(res, plotd=false, plotu=false, plotxwithx̂=true, plotx̂min=false, plotŷ=true) +savefig(p, "plot5_DAEpH.svg") # hide +display(p) # hide ``` +![plot5_MTK](plot5_MTK.svg) + ## Acknowledgement Authored by `1-Bart-1` and `baggepinnen`, thanks for the contribution. From 53191f0cb135709c3a31ee11af7b69d30d76e560 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 16 Nov 2026 11:20:36 -0500 Subject: [PATCH 5/9] doc: MTK section finished --- docs/src/manual/mtk.md | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index 2f1c398e5..4f9987b5b 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -245,8 +245,10 @@ display(p) # hide ## Neutralization Reactor Model -!!! todo "Under Construction" - This section is not finished, only the model conversion is written for now. +This example repeats the neutralization reactor setup from the previous section but with +MTK. The observer and controller are non-adaptive to simplify the design. Instead of +estimating the acid feed concentration, an integrating state is added at the manipulated +input ``q_{Bin}``. The MTK model of the neutralization reactor from the [last section](@ref man_dae) is constructed as follows: @@ -278,7 +280,7 @@ f_mtk!, h_mtk!, p_sym, p, x_sym, x, i_alg = generate_f_h_mtk( [x_sym x] ``` -The content of `x_sym` shows that it chose for the combined state and algebraic vector +The content of `x_sym` shows that it chose for the combined state and algebraic vector this: ``[\begin{smallmatrix}c_B(t) && c_A(t) && \mathrm{pH}(t)\end{smallmatrix}]'``. The states are thus in the reverse order of the [last section](@ref man_dae). The order of the parameters is: @@ -302,9 +304,8 @@ vx, vy = [raw"$c_B$ (mol/L)", raw"$c_A$ (mol/L)"], [raw"$\mathrm{pH}$"] model = setname!(model, u=vu, d=vd, y=vy, x=vx) ``` -The returned value is a [`NonLinModelDAE`](@ref) object, as expected. The transient -response is identical to the first 10 hours of the open-loop simulations of the -[last section](@ref man_dae): +The returned value is a [`NonLinModelDAE`](@ref) object, as expected. The transient response +is identical to the first 10 hours of the open-loop simulations in the [last section](@ref man_dae): ```@example 1 using Plots @@ -321,6 +322,8 @@ display(p) # hide ![plot3_MTK](plot3_MTK.svg) +We next configure the MHE, including an integrating state at the manipulated input: + ```@example 1 nint_u=[1] # integrating state at the q_Bin input He = 8; hessian = true @@ -330,18 +333,7 @@ using JuMP; unset_time_limit_sec(mhe.optim) # no wall time limit during opti mhe = setconstraint!(mhe, x̂min=[0, 0, -Inf]) ``` -```@example 1 -x_0, x̂_0 = [0.0495, 0.0505], [0.025, 0.025, 0] -using Logging # hide -res = with_logger(ConsoleLogger(stderr, Error)) do # hide -res = sim!(mhe, N, u, d; x_0, x̂_0) -end # hide -p = plot(res, plotd=false, plotu=false, plotxwithx̂=true, plotx̂min=false) -savefig(p, "plot4_DAEpH.svg") # hide -display(p) # hide -``` - -![plot4_MTK](plot4_MTK.svg) +Using the MHE, we configure an NMPC to keep the pH within the desired range: ```@example 1 nmpc = NonLinMPC(mhe, Hp=8, Hc=2, Nwt=[5.0], hessian=true) @@ -349,6 +341,8 @@ using JuMP; unset_time_limit_sec(nmpc.optim) # no wall time limit during optimi nmpc = setconstraint!(nmpc, ymin=[6], ymax=[8], umin=[0], umax=[20]) ``` +Finally, we simulate the closed-loop response with a pH setpoint of 7: + ```@example 1 ry = [7.0] x_0, x̂_0 = [0.04, 0.07], [0.025, 0.025, 0] @@ -363,6 +357,9 @@ display(p) # hide ![plot5_MTK](plot5_MTK.svg) +As expected, the close-loop response is similar to the one of the [last section](@ref man_dae), +but not identical since the stochastic model of the unmeasured disturbances is different. + ## Acknowledgement Authored by `1-Bart-1` and `baggepinnen`, thanks for the contribution. From 577a36ec960abf73d45a181420d6ff89aa10bf78 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 16 Nov 2026 12:23:08 -0500 Subject: [PATCH 6/9] bump --- Project.toml | 2 +- docs/src/manual/mtk.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 1572cfc85..bfa439348 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ModelPredictiveControl" uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c" -version = "2.16.3" +version = "2.16.4" authors = ["Francis Gagnon"] [deps] diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index 4f9987b5b..cbd9ce39f 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -351,11 +351,11 @@ res = with_logger(ConsoleLogger(stderr, Error)) do # hide res = sim!(nmpc, N, ry, d; x_0, x̂_0) end # hide p = plot(res, plotd=false, plotu=false, plotxwithx̂=true, plotx̂min=false, plotŷ=true) -savefig(p, "plot5_DAEpH.svg") # hide +savefig(p, "plot4_DAEpH.svg") # hide display(p) # hide ``` -![plot5_MTK](plot5_MTK.svg) +![plot4_MTK](plot4_MTK.svg) As expected, the close-loop response is similar to the one of the [last section](@ref man_dae), but not identical since the stochastic model of the unmeasured disturbances is different. From f4d601c27eb38577dc92eb0ef00591fe8daa27e5 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 16 Nov 2026 12:51:10 -0500 Subject: [PATCH 7/9] doc: debug --- docs/src/manual/mtk.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index cbd9ce39f..c825d24e4 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -351,7 +351,7 @@ res = with_logger(ConsoleLogger(stderr, Error)) do # hide res = sim!(nmpc, N, ry, d; x_0, x̂_0) end # hide p = plot(res, plotd=false, plotu=false, plotxwithx̂=true, plotx̂min=false, plotŷ=true) -savefig(p, "plot4_DAEpH.svg") # hide +savefig(p, "plot4_MTK.svg") # hide display(p) # hide ``` From c8e1840f2af67ce615cdbc8b1d02fffbd8bf05a1 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 16 Nov 2026 13:13:20 -0500 Subject: [PATCH 8/9] doc: also plot `u` in closed-loop --- docs/src/manual/mtk.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index c825d24e4..9746a1749 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -350,7 +350,7 @@ using Logging # hide res = with_logger(ConsoleLogger(stderr, Error)) do # hide res = sim!(nmpc, N, ry, d; x_0, x̂_0) end # hide -p = plot(res, plotd=false, plotu=false, plotxwithx̂=true, plotx̂min=false, plotŷ=true) +p = plot(res, plotd=false, plotxwithx̂=true, plotx̂min=false, plotŷ=true) savefig(p, "plot4_MTK.svg") # hide display(p) # hide ``` From 7b06b62f0c41e6024fe1780a005a941b15138f95 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 16 Nov 2026 13:15:55 -0500 Subject: [PATCH 9/9] doc: minor modification --- docs/src/manual/mtk.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/src/manual/mtk.md b/docs/src/manual/mtk.md index 9746a1749..a3e899f45 100644 --- a/docs/src/manual/mtk.md +++ b/docs/src/manual/mtk.md @@ -199,7 +199,7 @@ plant = generate_model(f_mtk!, h_mtk!, Ts, i_alg, inputs, outputs; p=p2) plant = setname!(plant; u=vu, x=vx, y=vy) ``` -## Pendulum Controller Design +## Pendulum Controller We can then reproduce the Kalman filter and the controller design of the [penultimate section](@ref man_nonlin) by reversing the order of `σQ` vector, because of the different state realization: @@ -322,6 +322,8 @@ display(p) # hide ![plot3_MTK](plot3_MTK.svg) +## Neutralization Reactor Controller + We next configure the MHE, including an integrating state at the manipulated input: ```@example 1