5353const par = (9.8, 0.4, 1.2, 0.3)
5454f(x, u, _ ) = pendulum(par, x, u)
5555h(x, _ ) = [180/π*x[1]] # [°]
56- Ts, nu, nx, ny = 0.1, 1, 2, 1
57- model = NonLinModel(f, h, Ts, nu, nx, ny)
56+ nu, nx, ny, Ts = 1, 2, 1, 0.1
57+ vu, vx, vy = ["\$τ\$ (N m)"], ["\$θ\$ (rad)", "\$ω\$ (rad/s)"], ["\$θ\$ (°)"]
58+ model = setname!(NonLinModel(f, h, Ts, nu, nx, ny); u=vu, x=vx, y=vy)
5859```
5960
6061The output function `` \mathbf{h} `` converts the `` θ `` angle to degrees. Note that special
@@ -72,6 +73,8 @@ plot(res, plotu=false)
7273savefig(ans, "plot1_NonLinMPC.svg"); nothing # hide
7374```
7475
76+ The [ ` setname! ` ] ( @ref ) function allows customizing the Y-axis labels.
77+
7578![ plot1_NonLinMPC] ( plot1_NonLinMPC.svg )
7679
7780## Nonlinear Model Predictive Controller
@@ -93,7 +96,7 @@ estimator tuning is tested on a plant with a 25 % larger friction coefficient ``
9396``` @example 1
9497const par_plant = (par[1], par[2], 1.25*par[3], par[4])
9598f_plant(x, u, _ ) = pendulum(par_plant, x, u)
96- plant = NonLinModel(f_plant, h, Ts, nu, nx, ny)
99+ plant = setname!( NonLinModel(f_plant, h, Ts, nu, nx, ny); u=vu, x=vx, y=vy )
97100res = sim!(estim, N, [0.5], plant=plant, y_noise=[0.5])
98101plot(res, plotu=false, plotxwithx̂=true)
99102savefig(ans, "plot2_NonLinMPC.svg"); nothing # hide
@@ -173,8 +176,8 @@ Kalman Filter similar to the previous one (``\mathbf{y^m} = θ`` and ``\mathbf{y
173176``` @example 1
174177h2(x, _ ) = [180/π*x[1], x[2]]
175178nu, nx, ny = 1, 2, 2
176- model2 = NonLinModel(f , h2, Ts, nu, nx, ny)
177- plant2 = NonLinModel(f_plant, h2, Ts, nu, nx, ny)
179+ model2 = setname!( NonLinModel(f , h2, Ts, nu, nx, ny), u=vu, x=vx, y=[vy; vx[2]] )
180+ plant2 = setname!( NonLinModel(f_plant, h2, Ts, nu, nx, ny), u=vu, x=vx, y=[vy; vx[2]] )
178181estim2 = UnscentedKalmanFilter(model2; σQ, σR, nint_u, σQint_u, i_ym=[1])
179182```
180183
0 commit comments