@@ -730,10 +730,11 @@ end
730
730
end
731
731
732
732
@testset " NonLinMPC constraint violation" begin
733
- gc (Ue, Ŷe, _ ,p , ϵ) = [p[1 ]* (Ue .- 4.2 .- ϵ); p[2 ]* (Ŷe .- 3.14 .- ϵ)]
733
+ gc (Ue, Ŷe, _ ,p , ϵ) = [p[1 ]* (Ue[1 : end - 1 ] .- 4.2 .- ϵ); p[2 ]* (Ŷe[2 : end ] .- 3.14 .- ϵ)]
734
+ Hp= 50
734
735
735
736
linmodel = LinModel (tf ([2 ], [10000 , 1 ]), 3000.0 )
736
- nmpc_lin = NonLinMPC (linmodel, Hp= 50 , Hc= 5 , gc= gc, nc= 2 * ( 50 + 1 ) , p= [0 ; 0 ])
737
+ nmpc_lin = NonLinMPC (linmodel, Hp= Hp , Hc= 5 , gc= gc, nc= 2 Hp , p= [0 ; 0 ])
737
738
738
739
setconstraint! (nmpc_lin, x̂min= [- 1e6 ,- Inf ], x̂max= [1e6 ,+ Inf ])
739
740
setconstraint! (nmpc_lin, umin= [- 10 ], umax= [10 ])
768
769
@test all (isapprox .(info[:Ŷ ], 0.9 ; atol= 1e-1 ))
769
770
setconstraint! (nmpc_lin, ymin= [- 100 ], ymax= [100 ])
770
771
771
- setconstraint! (nmpc_lin, Ymin= [- 0.5 ; fill (- 100 , 49 )], Ymax= [0.9 ; fill (+ 100 , 49 )])
772
+ setconstraint! (nmpc_lin, Ymin= [- 0.5 ; fill (- 100 , Hp - 1 )], Ymax= [0.9 ; fill (+ 100 , Hp - 1 )])
772
773
moveinput! (nmpc_lin, [- 10 ])
773
774
info = getinfo (nmpc_lin)
774
775
@test info[:Ŷ ][end ] ≈ - 10 atol= 1e-1
@@ -792,17 +793,18 @@ end
792
793
moveinput! (nmpc_lin, [100 ])
793
794
info = getinfo (nmpc_lin)
794
795
@test all (isapprox .(info[:U ], 4.2 ; atol= 1e-1 ))
796
+ @test all (isapprox .(info[:gc ][1 : Hp], 0.0 ; atol= 1e-1 ))
795
797
796
798
nmpc_lin. p .= [0 ; 1 ]
797
799
moveinput! (nmpc_lin, [100 ])
798
800
info = getinfo (nmpc_lin)
799
801
@test all (isapprox .(info[:Ŷ ], 3.14 ; atol= 1e-1 ))
800
-
802
+ @test all ( isapprox .(info[ :gc ][Hp + 1 : end ], 0.0 ; atol = 1e-1 ))
801
803
802
804
f = (x,u,_,p) -> p. A* x + p. Bu* u
803
805
h = (x,_,p) -> p. C* x
804
806
nonlinmodel = NonLinModel (f, h, linmodel. Ts, 1 , 1 , 1 , solver= nothing , p= linmodel)
805
- nmpc = NonLinMPC (nonlinmodel, Hp= 50 , Hc= 5 , gc= gc, nc= 2 * ( 50 + 1 ) , p= [0 ; 0 ])
807
+ nmpc = NonLinMPC (nonlinmodel, Hp= 50 , Hc= 5 , gc= gc, nc= 2 Hp , p= [0 ; 0 ])
806
808
807
809
setconstraint! (nmpc, x̂min= [- 1e6 ,- Inf ], x̂max= [1e6 ,+ Inf ])
808
810
setconstraint! (nmpc, umin= [- 10 ], umax= [10 ])
837
839
@test all (isapprox .(info[:Ŷ ], 0.9 ; atol= 1e-1 ))
838
840
setconstraint! (nmpc, ymin= [- 100 ], ymax= [100 ])
839
841
840
- setconstraint! (nmpc, Ymin= [- 0.5 ; fill (- 100 , 49 )], Ymax= [0.9 ; fill (+ 100 , 49 )])
842
+ setconstraint! (nmpc, Ymin= [- 0.5 ; fill (- 100 , Hp - 1 )], Ymax= [0.9 ; fill (+ 100 , Hp - 1 )])
841
843
moveinput! (nmpc, [- 10 ])
842
844
info = getinfo (nmpc)
843
845
@test info[:Ŷ ][end ] ≈ - 10 atol= 1e-1
@@ -861,11 +863,13 @@ end
861
863
moveinput! (nmpc, [100 ])
862
864
info = getinfo (nmpc)
863
865
@test all (isapprox .(info[:U ], 4.2 ; atol= 1e-1 ))
866
+ @test all (isapprox .(info[:gc ][1 : Hp], 0.0 ; atol= 1e-1 ))
864
867
865
868
nmpc. p .= [0 ; 1 ]
866
869
moveinput! (nmpc, [100 ])
867
870
info = getinfo (nmpc)
868
871
@test all (isapprox .(info[:Ŷ ], 3.14 ; atol= 1e-1 ))
872
+ @test all (isapprox .(info[:gc ][Hp+ 1 : end ], 0.0 ; atol= 1e-1 ))
869
873
870
874
end
871
875
0 commit comments