Skip to content

Commit b5b61ac

Browse files
committed
added : unit test EMPC with LinModel
1 parent 4ee07ed commit b5b61ac

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

test/test_predictive_control.jl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,29 +146,32 @@ end
146146
_ , info = getinfo(nmpc_lin)
147147
@test info[:u] u
148148
@test info[:Ŷ][end] 5 atol=1e-2
149+
Hp = 1000
150+
R̂y = fill(5, Hp)
151+
JE = (_ , ŶE, _ ) -> sum((ŶE[2:end] - R̂y).^2)
152+
nmpc = NonLinMPC(linmodel, Mwt=[0], Nwt=[0], Cwt=Inf, Ewt=1, JE=JE, Hp=Hp, Hc=1)
153+
u = moveinput!(nmpc)
154+
@test u [1] atol=1e-2
149155
f(x,u,_) = linmodel.A*x + linmodel.Bu*u
150156
h(x,_) = linmodel.C*x
151157
nonlinmodel = NonLinModel(f, h, 3, 1, 1, 1)
152-
nmpc1 = NonLinMPC(nonlinmodel, Nwt=[0], Hp=1000, Hc=1)
158+
nmpc2 = NonLinMPC(nonlinmodel, Nwt=[0], Hp=1000, Hc=1)
153159
r = [5]
154-
u = moveinput!(nmpc1, r)
160+
u = moveinput!(nmpc2, r)
155161
@test u [1] atol=1e-2
156-
u = nmpc1(r)
162+
u = nmpc2(r)
157163
@test u [1] atol=1e-2
158-
_ , info = getinfo(nmpc1)
164+
_ , info = getinfo(nmpc2)
159165
@test info[:u] u
160166
@test info[:Ŷ][end] 5 atol=1e-2
161-
nmpc2 = NonLinMPC(nonlinmodel, Nwt=[0], Cwt=Inf, Hp=1000, Hc=1)
162-
u = moveinput!(nmpc2, [5])
167+
nmpc3 = NonLinMPC(nonlinmodel, Nwt=[0], Cwt=Inf, Hp=1000, Hc=1)
168+
u = moveinput!(nmpc3, [5])
163169
@test u [1] atol=1e-2
164-
nmpc3 = NonLinMPC(nonlinmodel, Mwt=[0], Nwt=[0], Lwt=[1], ru=[12])
165-
u = moveinput!(nmpc3, [0])
170+
nmpc4 = NonLinMPC(nonlinmodel, Mwt=[0], Nwt=[0], Lwt=[1], ru=[12])
171+
u = moveinput!(nmpc4, [0])
166172
@test u [12] atol=1e-2
167-
Hp = 1000
168-
R̂y = fill(5, Hp)
169-
JE = (_ , ŶE, _ ) -> sum((ŶE[2:end] - R̂y).^2)
170-
nmpc4 = NonLinMPC(nonlinmodel, Mwt=[0], Nwt=[0], Cwt=Inf, Ewt=1, JE=JE, Hp=Hp, Hc=1)
171-
u = moveinput!(nmpc4)
173+
nmpc5 = NonLinMPC(nonlinmodel, Mwt=[0], Nwt=[0], Cwt=Inf, Ewt=1, JE=JE, Hp=Hp, Hc=1)
174+
u = moveinput!(nmpc5)
172175
@test u [1] atol=1e-2
173176
end
174177

0 commit comments

Comments
 (0)