|
180 | 180 | @test ym ≈ r atol=1e-2 |
181 | 181 | end |
182 | 182 |
|
| 183 | +@testitem "LinMPC and ManualEstimator v.s. default" setup=[SetupMPCtests] begin |
| 184 | + using .SetupMPCtests, ControlSystemsBase, LinearAlgebra |
| 185 | + linmodel = setop!(LinModel(tf(5, [2, 1]), 3.0), yop=[10]) |
| 186 | + r = [15] |
| 187 | + outdist = [5] |
| 188 | + U_man, U_def = let linmodel=linmodel, r=r, outdist=outdist |
| 189 | + mpc_man = LinMPC(ManualEstimator(linmodel)) |
| 190 | + skf = SteadyKalmanFilter(linmodel) |
| 191 | + mpc_def = LinMPC(linmodel) |
| 192 | + linmodel.x0 .= 0 |
| 193 | + U_man, U_def = zeros(1, 25), zeros(1, 25) |
| 194 | + for i=1:25 |
| 195 | + ym = linmodel() - outdist |
| 196 | + x̂ = preparestate!(skf, ym) |
| 197 | + setstate!(mpc_man, x̂) |
| 198 | + preparestate!(mpc_def, ym) |
| 199 | + u_man = moveinput!(mpc_man, r) |
| 200 | + u_def = moveinput!(mpc_def, r) |
| 201 | + U_man[:, i], U_def[:, i] = u_man, u_def |
| 202 | + updatestate!(skf, u_man, ym) |
| 203 | + updatestate!(mpc_def, u_def, ym) |
| 204 | + updatestate!(linmodel, u_man) |
| 205 | + end |
| 206 | + U_man, U_def |
| 207 | + end |
| 208 | + @test U_man ≈ U_def atol=1e-9 |
| 209 | +end |
| 210 | + |
183 | 211 | @testitem "LinMPC other methods" setup=[SetupMPCtests] begin |
184 | 212 | using .SetupMPCtests, ControlSystemsBase, LinearAlgebra |
185 | 213 | linmodel1 = setop!(LinModel(sys,Ts,i_u=[1,2]), uop=[10,50], yop=[50,30]) |
|
852 | 880 | @test ym ≈ r atol=1e-2 |
853 | 881 | end |
854 | 882 |
|
| 883 | +@testitem "NonLinMPC and ManualEstimator v.s. default" setup=[SetupMPCtests] begin |
| 884 | + using .SetupMPCtests, ControlSystemsBase, LinearAlgebra |
| 885 | + linmodel = LinModel(tf(5, [2, 1]), 3.0) |
| 886 | + f(x,u,_,p) = p.A*x + p.Bu*u |
| 887 | + h(x,_,p) = p.C*x |
| 888 | + model = setop!(NonLinModel(f, h, 3.0, 1, 1, 1; solver=nothing, p=linmodel), yop=[10]) |
| 889 | + r = [15] |
| 890 | + outdist = [5] |
| 891 | + U_man, U_def = let model=model, r=r, outdist=outdist |
| 892 | + nmpc_man = NonLinMPC(ManualEstimator(model), Hp=10) |
| 893 | + ukf = UnscentedKalmanFilter(model) |
| 894 | + nmpc_def = NonLinMPC(model, Hp=10) |
| 895 | + model.x0 .= 0 |
| 896 | + U_man, U_def = zeros(1, 25), zeros(1, 25) |
| 897 | + for i=1:25 |
| 898 | + ym = model() - outdist |
| 899 | + x̂ = preparestate!(ukf, ym) |
| 900 | + setstate!(nmpc_man, x̂) |
| 901 | + preparestate!(nmpc_def, ym) |
| 902 | + u_man = moveinput!(nmpc_man, r) |
| 903 | + u_def = moveinput!(nmpc_def, r) |
| 904 | + U_man[:, i], U_def[:, i] = u_man, u_def |
| 905 | + updatestate!(ukf, u_man, ym) |
| 906 | + updatestate!(nmpc_def, u_def, ym) |
| 907 | + updatestate!(model, u_man) |
| 908 | + end |
| 909 | + U_man, U_def |
| 910 | + end |
| 911 | + @test U_man ≈ U_def atol=1e-9 |
| 912 | +end |
| 913 | + |
855 | 914 | @testitem "NonLinMPC other methods" setup=[SetupMPCtests] begin |
856 | 915 | using .SetupMPCtests, ControlSystemsBase, LinearAlgebra |
857 | 916 | linmodel = setop!(LinModel(sys,Ts,i_u=[1,2]), uop=[10,50], yop=[50,30]) |
|
0 commit comments