Skip to content

Commit 408701b

Browse files
committed
test: new integration with ManualEstimator and MPCs
1 parent 6131c63 commit 408701b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/3_test_predictive_control.jl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,34 @@ end
180180
@test ym r atol=1e-2
181181
end
182182

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+
= 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+
183211
@testitem "LinMPC other methods" setup=[SetupMPCtests] begin
184212
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
185213
linmodel1 = setop!(LinModel(sys,Ts,i_u=[1,2]), uop=[10,50], yop=[50,30])
@@ -852,6 +880,37 @@ end
852880
@test ym r atol=1e-2
853881
end
854882

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+
= 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+
855914
@testitem "NonLinMPC other methods" setup=[SetupMPCtests] begin
856915
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
857916
linmodel = setop!(LinModel(sys,Ts,i_u=[1,2]), uop=[10,50], yop=[50,30])

0 commit comments

Comments
 (0)