|
72 | 72 | mpc3 = LinMPC(LinModel(tf(5, [2, 1]), 3), Mwt=[0], Nwt=[0], Lwt=[1], ru=[12]) |
73 | 73 | u = moveinput!(mpc3, [0]) |
74 | 74 | @test u ≈ [12] atol=1e-2 |
| 75 | + mpc_im = LinMPC(InternalModel(LinModel(tf(5, [2, 1]), 3))) |
| 76 | + ym, u = mpc_im.estim.model() - [5], [0.0] |
| 77 | + for i=1:25 |
| 78 | + ym = mpc_im.estim.model() - [5] |
| 79 | + u = moveinput!(mpc_im, r; ym) |
| 80 | + updatestate!(mpc_im, u, ym) |
| 81 | + updatestate!(mpc_im.estim.model, u) |
| 82 | + end |
| 83 | + @test u ≈ [2] atol=1e-2 |
| 84 | + @test ym ≈ [5] atol=1e-2 |
| 85 | + mpc_nint_u = LinMPC(SteadyKalmanFilter(LinModel(tf(5, [2, 1]), 3), nint_u=[1])) |
| 86 | + ym, u = mpc_nint_u.estim.model() - [5], [0.0] |
| 87 | + for i=1:25 |
| 88 | + ym = mpc_nint_u.estim.model() - [5] |
| 89 | + u = moveinput!(mpc_nint_u, r; ym) |
| 90 | + updatestate!(mpc_nint_u, u, ym) |
| 91 | + updatestate!(mpc_nint_u.estim.model, u) |
| 92 | + end |
| 93 | + @test u ≈ [2] atol=1e-2 |
| 94 | + @test ym ≈ [5] atol=1e-2 |
| 95 | + mpc_nint_ym = LinMPC(SteadyKalmanFilter(LinModel(tf(5, [2, 1]), 3), nint_ym=[1])) |
| 96 | + ym, u = mpc_nint_ym.estim.model() - [5], [0.0] |
| 97 | + for i=1:25 |
| 98 | + ym = mpc_nint_ym.estim.model() - [5] |
| 99 | + u = moveinput!(mpc_nint_ym, r; ym) |
| 100 | + updatestate!(mpc_nint_ym, u, ym) |
| 101 | + updatestate!(mpc_nint_ym.estim.model, u) |
| 102 | + end |
| 103 | + @test u ≈ [2] atol=1e-2 |
| 104 | + @test ym ≈ [5] atol=1e-2 |
75 | 105 | end |
76 | 106 |
|
77 | 107 | @testset "LinMPC other methods" begin |
|
136 | 166 | mpc3 = ExplicitMPC(LinModel(tf(5, [2, 1]), 3), Mwt=[0], Nwt=[0], Lwt=[1], ru=[12]) |
137 | 167 | u = moveinput!(mpc3, [0]) |
138 | 168 | @test u ≈ [12] atol=1e-2 |
| 169 | + mpc_im = ExplicitMPC(InternalModel(LinModel(tf(5, [2, 1]), 3))) |
| 170 | + ym, u = mpc_im.estim.model() - [5], [0.0] |
| 171 | + for i=1:25 |
| 172 | + ym = mpc_im.estim.model() - [5] |
| 173 | + u = moveinput!(mpc_im, r; ym) |
| 174 | + updatestate!(mpc_im, u, ym) |
| 175 | + updatestate!(mpc_im.estim.model, u) |
| 176 | + end |
| 177 | + @test u ≈ [2] atol=1e-2 |
| 178 | + @test ym ≈ [5] atol=1e-2 |
| 179 | + mpc_nint_u = ExplicitMPC(SteadyKalmanFilter(LinModel(tf(5, [2, 1]), 3), nint_u=[1])) |
| 180 | + ym, u = mpc_nint_u.estim.model() - [5], [0.0] |
| 181 | + for i=1:25 |
| 182 | + ym = mpc_nint_u.estim.model() - [5] |
| 183 | + u = moveinput!(mpc_nint_u, r; ym) |
| 184 | + updatestate!(mpc_nint_u, u, ym) |
| 185 | + updatestate!(mpc_nint_u.estim.model, u) |
| 186 | + end |
| 187 | + @test u ≈ [2] atol=1e-2 |
| 188 | + @test ym ≈ [5] atol=1e-2 |
| 189 | + mpc_nint_ym = ExplicitMPC(SteadyKalmanFilter(LinModel(tf(5, [2, 1]), 3), nint_ym=[1])) |
| 190 | + ym, u = mpc_nint_ym.estim.model() - [5], [0.0] |
| 191 | + for i=1:25 |
| 192 | + ym = mpc_nint_ym.estim.model() - [5] |
| 193 | + u = moveinput!(mpc_nint_ym, r; ym) |
| 194 | + updatestate!(mpc_nint_ym, u, ym) |
| 195 | + updatestate!(mpc_nint_ym.estim.model, u) |
| 196 | + end |
| 197 | + @test u ≈ [2] atol=1e-2 |
| 198 | + @test ym ≈ [5] atol=1e-2 |
139 | 199 | end |
140 | 200 |
|
141 | 201 | @testset "ExplicitMPC other methods" begin |
@@ -231,16 +291,15 @@ end |
231 | 291 | nonlinmodel = NonLinModel(f, h, 3.0, 1, 2, 1, 1) |
232 | 292 | nmpc2 = NonLinMPC(nonlinmodel, Nwt=[0], Hp=1000, Hc=1) |
233 | 293 | d = [0.1] |
234 | | - r = 7*d |
235 | | - u = moveinput!(nmpc2, r, d) |
| 294 | + u = moveinput!(nmpc2, 7d, d) |
236 | 295 | @test u ≈ [0] atol=5e-2 |
237 | | - u = nmpc2(r, d) |
| 296 | + u = nmpc2(7d, d) |
238 | 297 | @test u ≈ [0] atol=5e-2 |
239 | 298 | _ , info = getinfo(nmpc2) |
240 | 299 | @test info[:u] ≈ u |
241 | | - @test info[:Ŷ][end] ≈ r[1] atol=5e-2 |
| 300 | + @test info[:Ŷ][end] ≈ 7d[1] atol=5e-2 |
242 | 301 | nmpc3 = NonLinMPC(nonlinmodel, Nwt=[0], Cwt=Inf, Hp=1000, Hc=1) |
243 | | - u = moveinput!(nmpc3, r, d) |
| 302 | + u = moveinput!(nmpc3, 7d, d) |
244 | 303 | @test u ≈ [0] atol=5e-2 |
245 | 304 | nmpc4 = NonLinMPC(nonlinmodel, Mwt=[0], Nwt=[0], Lwt=[1], ru=[12]) |
246 | 305 | u = moveinput!(nmpc4, [0], d) |
|
249 | 308 | C_Ymax_end = nmpc5.optim.nlp_model.operators.registered_multivariate_operators[end].f |
250 | 309 | @test C_Ymax_end(Float64.((1.0, 1.0))) ≤ 0.0 # test con_nonlinprog_i(i,::NTuple{N, Float64}) |
251 | 310 | @test C_Ymax_end(Float32.((1.0, 1.0))) ≤ 0.0 # test con_nonlinprog_i(i,::NTuple{N, Real}) |
| 311 | + nmpc_im = NonLinMPC(InternalModel(LinModel(tf(5, [2, 1]), 3))) |
| 312 | + ym, u = nmpc_im.estim.model() - [5], [0.0] |
| 313 | + for i=1:25 |
| 314 | + ym = nmpc_im.estim.model() - [5] |
| 315 | + u = moveinput!(nmpc_im, r; ym) |
| 316 | + updatestate!(nmpc_im, u, ym) |
| 317 | + updatestate!(nmpc_im.estim.model, u) |
| 318 | + end |
| 319 | + @test u ≈ [2] atol=1e-2 |
| 320 | + @test ym ≈ [5] atol=1e-2 |
| 321 | + nmpc_nint_u = NonLinMPC(SteadyKalmanFilter(LinModel(tf(5, [2, 1]), 3), nint_u=[1])) |
| 322 | + ym, u = nmpc_nint_u.estim.model() - [5], [0.0] |
| 323 | + for i=1:25 |
| 324 | + ym = nmpc_nint_u.estim.model() - [5] |
| 325 | + u = moveinput!(nmpc_nint_u, r; ym) |
| 326 | + updatestate!(nmpc_nint_u, u, ym) |
| 327 | + updatestate!(nmpc_nint_u.estim.model, u) |
| 328 | + end |
| 329 | + @test u ≈ [2] atol=1e-2 |
| 330 | + @test ym ≈ [5] atol=1e-2 |
| 331 | + nmpc_nint_ym = NonLinMPC(SteadyKalmanFilter(LinModel(tf(5, [2, 1]), 3), nint_ym=[1])) |
| 332 | + ym, u = nmpc_nint_ym.estim.model() - [5], [0.0] |
| 333 | + for i=1:25 |
| 334 | + ym = nmpc_nint_ym.estim.model() - [5] |
| 335 | + u = moveinput!(nmpc_nint_ym, r; ym) |
| 336 | + updatestate!(nmpc_nint_ym, u, ym) |
| 337 | + updatestate!(nmpc_nint_ym.estim.model, u) |
| 338 | + end |
| 339 | + @test u ≈ [2] atol=1e-2 |
| 340 | + @test ym ≈ [5] atol=1e-2 |
| 341 | + |
252 | 342 | end |
253 | 343 |
|
254 | 344 | @testset "NonLinMPC other methods" begin |
|
0 commit comments