|
65 | 65 | @test u ≈ [1] atol=1e-2 |
66 | 66 | _ , info = getinfo(mpc1) |
67 | 67 | @test info[:u] ≈ u |
68 | | - @test info[:Ŷ][end] ≈ 5 atol=1e-2 |
| 68 | + @test info[:Ŷ][end] ≈ r[1] atol=1e-2 |
69 | 69 | mpc2 = LinMPC(LinModel(tf(5, [2, 1]), 3), Nwt=[0], Cwt=Inf, Hp=1000, Hc=1) |
70 | 70 | u = moveinput!(mpc2, [5]) |
71 | 71 | @test u ≈ [1] atol=1e-2 |
@@ -141,45 +141,44 @@ end |
141 | 141 | end |
142 | 142 |
|
143 | 143 | @testset "NonLinMPC moves and getinfo" begin |
144 | | - linmodel = LinModel(tf(5, [2, 1]), 3) |
| 144 | + linmodel = LinModel(tf(5, [2, 1]), 3.0) |
145 | 145 | nmpc_lin = NonLinMPC(linmodel, Nwt=[0], Hp=1000, Hc=1) |
146 | 146 | r = [5] |
147 | 147 | u = moveinput!(nmpc_lin, r) |
148 | | - @test u ≈ [1] atol=1e-3 |
| 148 | + @test u ≈ [1] atol=5e-2 |
149 | 149 | u = nmpc_lin(r) |
150 | | - @test u ≈ [1] atol=1e-3 |
| 150 | + @test u ≈ [1] atol=5e-2 |
151 | 151 | _ , info = getinfo(nmpc_lin) |
152 | 152 | @test info[:u] ≈ u |
153 | | - @test info[:Ŷ][end] ≈ 5 atol=1e-2 |
| 153 | + @test info[:Ŷ][end] ≈ r[1] atol=5e-2 |
154 | 154 | Hp = 1000 |
155 | 155 | R̂y = fill(5, Hp) |
156 | 156 | JE = (_ , ŶE, _ ) -> sum((ŶE[2:end] - R̂y).^2) |
157 | 157 | nmpc = NonLinMPC(linmodel, Mwt=[0], Nwt=[0], Cwt=Inf, Ewt=1, JE=JE, Hp=Hp, Hc=1) |
158 | 158 | u = moveinput!(nmpc) |
159 | | - @test u ≈ [1] atol=1e-2 |
160 | | - f(x,u,_) = linmodel.A*x + linmodel.Bu*u |
161 | | - h(x,_) = linmodel.C*x |
162 | | - nonlinmodel = NonLinModel(f, h, 3, 1, 1, 1) |
| 159 | + @test u ≈ [1] atol=5e-2 |
| 160 | + linmodel = LinModel([tf(5, [2, 1]) tf(7, [8,1])], 3.0, i_d=[2]) |
| 161 | + f(x,u,d) = linmodel.A*x + linmodel.Bu*u + linmodel.Bd*d |
| 162 | + h(x,d) = linmodel.C*x + linmodel.Dd*d |
| 163 | + nonlinmodel = NonLinModel(f, h, 3.0, 1, 2, 1, 1) |
163 | 164 | nmpc2 = NonLinMPC(nonlinmodel, Nwt=[0], Hp=1000, Hc=1) |
164 | | - r = [5] |
165 | | - u = moveinput!(nmpc2, r) |
166 | | - @test u ≈ [1] atol=1e-2 |
167 | | - u = nmpc2(r) |
168 | | - @test u ≈ [1] atol=1e-2 |
| 165 | + d = [0.1] |
| 166 | + r = 7*d |
| 167 | + u = moveinput!(nmpc2, r, d) |
| 168 | + @test u ≈ [0] atol=5e-2 |
| 169 | + u = nmpc2(r, d) |
| 170 | + @test u ≈ [0] atol=5e-2 |
169 | 171 | _ , info = getinfo(nmpc2) |
170 | 172 | @test info[:u] ≈ u |
171 | | - @test info[:Ŷ][end] ≈ 5 atol=1e-2 |
| 173 | + @test info[:Ŷ][end] ≈ r[1] atol=5e-2 |
172 | 174 | nmpc3 = NonLinMPC(nonlinmodel, Nwt=[0], Cwt=Inf, Hp=1000, Hc=1) |
173 | | - u = moveinput!(nmpc3, [5]) |
174 | | - @test u ≈ [1] atol=1e-2 |
| 175 | + u = moveinput!(nmpc3, r, d) |
| 176 | + @test u ≈ [0] atol=5e-2 |
175 | 177 | nmpc4 = NonLinMPC(nonlinmodel, Mwt=[0], Nwt=[0], Lwt=[1], ru=[12]) |
176 | | - u = moveinput!(nmpc4, [0]) |
177 | | - @test u ≈ [12] atol=1e-2 |
178 | | - nmpc5 = NonLinMPC(nonlinmodel, Mwt=[0], Nwt=[0], Cwt=Inf, Ewt=1, JE=JE, Hp=Hp, Hc=1) |
179 | | - u = moveinput!(nmpc5) |
180 | | - @test u ≈ [1] atol=1e-2 |
181 | | - nmpc6 = setconstraint!(NonLinMPC(nonlinmodel, Cwt=Inf), ŷmin=[-1]) |
182 | | - C_Ŷmax_end = nmpc6.optim.nlp_model.operators.registered_multivariate_operators[end].f |
| 178 | + u = moveinput!(nmpc4, [0], d) |
| 179 | + @test u ≈ [12] atol=5e-2 |
| 180 | + nmpc5 = setconstraint!(NonLinMPC(nonlinmodel, Cwt=Inf), ŷmin=[-1]) |
| 181 | + C_Ŷmax_end = nmpc5.optim.nlp_model.operators.registered_multivariate_operators[end].f |
183 | 182 | @test C_Ŷmax_end(Float64.((1.0, 1.0))) ≤ 0.0 # test con_nonlinprog_i(i,::NTuple{N, Float64}) |
184 | 183 | @test C_Ŷmax_end(Float32.((1.0, 1.0))) ≤ 0.0 # test con_nonlinprog_i(i,::NTuple{N, Real}) |
185 | 184 | end |
|
0 commit comments