@@ -730,10 +730,11 @@ end
730730end
731731
732732@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
734735
735736 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 ])
737738
738739 setconstraint!(nmpc_lin, x̂min= [- 1e6 ,- Inf ], x̂max= [1e6 ,+ Inf ])
739740 setconstraint!(nmpc_lin, umin= [- 10 ], umax= [10 ])
768769 @test all(isapprox.(info[:Ŷ], 0.9 ; atol= 1e-1 ))
769770 setconstraint!(nmpc_lin, ymin= [- 100 ], ymax= [100 ])
770771
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 )])
772773 moveinput!(nmpc_lin, [- 10 ])
773774 info = getinfo(nmpc_lin)
774775 @test info[:Ŷ][end ] ≈ - 10 atol= 1e-1
@@ -792,17 +793,18 @@ end
792793 moveinput!(nmpc_lin, [100 ])
793794 info = getinfo(nmpc_lin)
794795 @test all(isapprox.(info[:U], 4.2 ; atol= 1e-1 ))
796+ @test all(isapprox.(info[:gc][1 : Hp], 0.0 ; atol= 1e-1 ))
795797
796798 nmpc_lin. p .= [0 ; 1 ]
797799 moveinput!(nmpc_lin, [100 ])
798800 info = getinfo(nmpc_lin)
799801 @test all(isapprox.(info[:Ŷ], 3.14 ; atol= 1e-1 ))
800-
802+ @test all(isapprox.(info[:gc][Hp + 1 : end ], 0.0 ; atol = 1e-1 ))
801803
802804 f = (x,u,_,p) -> p. A* x + p. Bu* u
803805 h = (x,_,p) -> p. C* x
804806 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 ])
806808
807809 setconstraint!(nmpc, x̂min= [- 1e6 ,- Inf ], x̂max= [1e6 ,+ Inf ])
808810 setconstraint!(nmpc, umin= [- 10 ], umax= [10 ])
837839 @test all(isapprox.(info[:Ŷ], 0.9 ; atol= 1e-1 ))
838840 setconstraint!(nmpc, ymin= [- 100 ], ymax= [100 ])
839841
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 )])
841843 moveinput!(nmpc, [- 10 ])
842844 info = getinfo(nmpc)
843845 @test info[:Ŷ][end ] ≈ - 10 atol= 1e-1
@@ -861,11 +863,13 @@ end
861863 moveinput!(nmpc, [100 ])
862864 info = getinfo(nmpc)
863865 @test all(isapprox.(info[:U], 4.2 ; atol= 1e-1 ))
866+ @test all(isapprox.(info[:gc][1 : Hp], 0.0 ; atol= 1e-1 ))
864867
865868 nmpc. p .= [0 ; 1 ]
866869 moveinput!(nmpc, [100 ])
867870 info = getinfo(nmpc)
868871 @test all(isapprox.(info[:Ŷ], 3.14 ; atol= 1e-1 ))
872+ @test all(isapprox.(info[:gc][Hp+ 1 : end ], 0.0 ; atol= 1e-1 ))
869873
870874end
871875
0 commit comments