Skip to content

Commit 7528a95

Browse files
committed
test: NonLinMPC move input and getinfo with MultipleShooting
1 parent 49bbbd3 commit 7528a95

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

test/3_test_predictive_control.jl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ end
602602
@testitem "NonLinMPC moves and getinfo" setup=[SetupMPCtests] begin
603603
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra, ForwardDiff
604604
linmodel = setop!(LinModel(tf(5, [2000, 1]), 3000.0), yop=[10])
605-
Hp = 1000
605+
Hp = 100
606606
nmpc_lin = NonLinMPC(linmodel, Nwt=[0], Hp=Hp, Hc=1)
607607
ry, ru = [15], [4]
608608
preparestate!(nmpc_lin, [10])
@@ -635,7 +635,7 @@ end
635635
f = (x,u,d,_) -> linmodel2.A*x + linmodel2.Bu*u + linmodel2.Bd*d
636636
h = (x,d,_) -> linmodel2.C*x + linmodel2.Dd*d
637637
nonlinmodel = NonLinModel(f, h, 3000.0, 1, 2, 1, 1, solver=nothing)
638-
nmpc2 = NonLinMPC(nonlinmodel, Nwt=[0], Hp=1000, Hc=1)
638+
nmpc2 = NonLinMPC(nonlinmodel, Nwt=[0], Hp=100, Hc=1)
639639
# if d=[0.1], the output will eventually reach 7*0.1=0.7, no action needed (u=0):
640640
d = [0.1]
641641
preparestate!(nmpc2, [0], d)
@@ -646,7 +646,7 @@ end
646646
info = getinfo(nmpc2)
647647
@test info[:u] u
648648
@test info[:Ŷ][end] 7d[1] atol=5e-2
649-
nmpc3 = NonLinMPC(nonlinmodel, Nwt=[0], Cwt=Inf, Hp=1000, Hc=1)
649+
nmpc3 = NonLinMPC(nonlinmodel, Nwt=[0], Cwt=Inf, Hp=100, Hc=1)
650650
preparestate!(nmpc3, [0], [0])
651651
u = moveinput!(nmpc3, 7d, d)
652652
@test u [0] atol=5e-2
@@ -670,6 +670,20 @@ end
670670
nonlinmodel2.h!(y, Float32[0,0], Float32[0], Float32[])
671671
preparestate!(nmpc7, [0], [0])
672672
@test moveinput!(nmpc7, [0], [0]) [0.0]
673+
nmpc8 = NonLinMPC(nonlinmodel, Nwt=[0], Hp=100, Hc=1, transcription=MultipleShooting())
674+
preparestate!(nmpc8, [0], [0])
675+
u = moveinput!(nmpc8, [10], [0])
676+
@test u [2] atol=5e-2
677+
info = getinfo(nmpc8)
678+
@test info[:u] u
679+
@test info[:Ŷ][end] 10 atol=5e-2
680+
nmpc9 = NonLinMPC(linmodel, Nwt=[0], Hp=100, Hc=1, transcription=MultipleShooting())
681+
preparestate!(nmpc9, [0])
682+
u = moveinput!(nmpc9, [15])
683+
@test u [3] atol=5e-2
684+
info = getinfo(nmpc9)
685+
@test info[:u] u
686+
@test info[:Ŷ][end] 15 atol=5e-2
673687
@test_nowarn ModelPredictiveControl.info2debugstr(info)
674688
end
675689

0 commit comments

Comments
 (0)