@@ -714,10 +714,10 @@ end
714714end
715715
716716@testset " NonLinMPC constraint violation" begin
717- gc ( _ , Ŷe, _ , p , ϵ) = p[ ]* (Ŷe .- 3.14 .- ϵ)
717+ gc (Ue , Ŷe, _ ,p , ϵ) = [p[ 1 ]* (Ue .- 4.2 .- ϵ); p[ 2 ] * ( Ŷe .- 3.14 .- ϵ)]
718718
719719 linmodel = LinModel (tf ([2 ], [10000 , 1 ]), 3000.0 )
720- nmpc_lin = NonLinMPC (linmodel, Hp= 50 , Hc= 5 , gc= gc, nc= 50 + 1 , p= [0 ])
720+ nmpc_lin = NonLinMPC (linmodel, Hp= 50 , Hc= 5 , gc= gc, nc= 2 * ( 50 + 1 ) , p= [0 ; 0 ])
721721
722722 setconstraint! (nmpc_lin, x̂min= [- 1e3 ,- Inf ], x̂max= [1e3 ,+ Inf ])
723723 setconstraint! (nmpc_lin, umin= [- 3 ], umax= [3 ])
@@ -766,11 +766,18 @@ end
766766 info = getinfo (nmpc_lin)
767767 @test info[:x̂end ][1 ] ≈ 0 atol= 1e-1
768768
769- nmpc_lin. p[] = 1
770769 setconstraint! (nmpc_lin, x̂min= [- 1e3 ,- Inf ], x̂max= [1e3 ,+ Inf ])
771770 setconstraint! (nmpc_lin, umin= [- 10 ], umax= [10 ])
772771 setconstraint! (nmpc_lin, Δumin= [- 15 ], Δumax= [15 ])
773772 setconstraint! (nmpc_lin, ymin= [- 100 ], ymax= [100 ])
773+
774+ nmpc_lin. p .= [1 ; 0 ]
775+ moveinput! (nmpc_lin, [20 ])
776+ info = getinfo (nmpc_lin)
777+ @test info[:U ][end ] ≈ 4.2 atol= 1e-1
778+ @test info[:U ][begin ] ≈ 4.2 atol= 1e-1
779+
780+ nmpc_lin. p .= [0 ; 1 ]
774781 moveinput! (nmpc_lin, [20 ])
775782 info = getinfo (nmpc_lin)
776783 @test info[:Ŷ ][end ] ≈ 3.14 atol= 1e-1
779786 f = (x,u,_,_) -> linmodel. A* x + linmodel. Bu* u
780787 h = (x,_,_) -> linmodel. C* x
781788 nonlinmodel = NonLinModel (f, h, linmodel. Ts, 1 , 1 , 1 , solver= nothing )
782- nmpc = NonLinMPC (nonlinmodel, Hp= 50 , Hc= 5 , gc= gc, nc= 50 + 1 , p= [0 ])
789+ nmpc = NonLinMPC (nonlinmodel, Hp= 50 , Hc= 5 , gc= gc, nc= 2 * ( 50 + 1 ) , p= [0 ; 0 ])
783790
784791 setconstraint! (nmpc, x̂min= [- 1e3 ,- Inf ], x̂max= [1e3 ,+ Inf ])
785792 setconstraint! (nmpc, umin= [- 3 ], umax= [3 ])
@@ -828,11 +835,18 @@ end
828835 info = getinfo (nmpc)
829836 @test info[:x̂end ][1 ] ≈ 0 atol= 1e-1
830837
831- nmpc. p[] = 1
832838 setconstraint! (nmpc, x̂min= [- 1e3 ,- Inf ], x̂max= [1e3 ,+ Inf ])
833839 setconstraint! (nmpc, umin= [- 10 ], umax= [10 ])
834840 setconstraint! (nmpc, Δumin= [- 15 ], Δumax= [15 ])
835841 setconstraint! (nmpc, ymin= [- 100 ], ymax= [100 ])
842+
843+ nmpc. p .= [1 ; 0 ]
844+ moveinput! (nmpc, [20 ])
845+ info = getinfo (nmpc)
846+ @test info[:U ][end ] ≈ 4.2 atol= 1e-1
847+ @test info[:U ][begin ] ≈ 4.2 atol= 1e-1
848+
849+ nmpc. p .= [0 ; 1 ]
836850 moveinput! (nmpc, [20 ])
837851 info = getinfo (nmpc)
838852 @test info[:Ŷ ][end ] ≈ 3.14 atol= 1e-1
0 commit comments