865865 Hp= 50
866866
867867 linmodel = LinModel (tf ([2 ], [10000 , 1 ]), 3000.0 )
868- nmpc_lin = NonLinMPC (linmodel; Hp, Hc= 5 , gc= gc , nc= 2 Hp, p= [0 ; 0 ])
869-
868+ nmpc_lin = NonLinMPC (linmodel; Hp, Hc= 5 , gc, nc= 2 Hp, p= [0 ; 0 ])
869+
870870 setconstraint! (nmpc_lin, x̂min= [- 1e6 ,- Inf ], x̂max= [1e6 ,+ Inf ])
871871 setconstraint! (nmpc_lin, umin= [- 10 ], umax= [10 ])
872872 setconstraint! (nmpc_lin, Δumin= [- 1e6 ], Δumax= [1e6 ])
935935 f = (x,u,_,p) -> p. A* x + p. Bu* u
936936 h = (x,_,p) -> p. C* x
937937 nonlinmodel = NonLinModel (f, h, linmodel. Ts, 1 , 1 , 1 , solver= nothing , p= linmodel)
938- nmpc = NonLinMPC (nonlinmodel; Hp, Hc= 5 , gc= gc , nc= 2 Hp, p= [0 ; 0 ])
938+ nmpc = NonLinMPC (nonlinmodel; Hp, Hc= 5 , gc, nc= 2 Hp, p= [0 ; 0 ])
939939
940940 setconstraint! (nmpc, x̂min= [- 1e6 ,- Inf ], x̂max= [+ 1e6 ,+ Inf ])
941941 setconstraint! (nmpc, umin= [- 1e6 ], umax= [+ 1e6 ])
@@ -1000,9 +1000,11 @@ end
10001000 moveinput! (nmpc, [100 ])
10011001 info = getinfo (nmpc)
10021002 @test all (isapprox .(info[:Ŷ ], 3.14 ; atol= 1e-1 ))
1003- @test all (isapprox .(info[:gc ][Hp+ 1 : end ], 0.0 ; atol= 1e-1 ))
1003+ @test all (isapprox .(info[:gc ][Hp+ 1 : end ], 0.0 ; atol= 1e-1 ))= #
10041004
1005- nmpc_ms = NonLinMPC (nonlinmodel; Hp, Hc= 5 , transcription= MultipleShooting ())
1005+ nmpc_ms = NonLinMPC (
1006+ nonlinmodel; Hp, Hc= 5 , transcription= MultipleShooting (), gc, nc= 2 Hp, p= [0 ; 0 ]
1007+ )
10061008
10071009 preparestate! (nmpc_ms, [0 ])
10081010
@@ -1013,6 +1015,19 @@ end
10131015 moveinput! (nmpc_ms, [10 ])
10141016 info = getinfo (nmpc_ms)
10151017 @test info[:x̂end ][1 ] ≈ 0 atol= 1e-1
1018+ setconstraint! (nmpc_ms, x̂min= [- 1e6 ,- Inf ], x̂max= [1e6 ,+ Inf ])
1019+
1020+ nmpc_ms. p .= [1 ; 0 ]
1021+ moveinput! (nmpc_ms, [100 ])
1022+ info = getinfo (nmpc_ms)
1023+ @test all (isapprox .(info[:U ], 4.2 ; atol= 1e-1 ))
1024+ @test all (isapprox .(info[:gc ][1 : Hp], 0.0 ; atol= 1e-1 ))
1025+
1026+ nmpc_ms. p .= [0 ; 1 ]
1027+ moveinput! (nmpc_ms, [100 ])
1028+ info = getinfo (nmpc_ms)
1029+ @test all (isapprox .(info[:Ŷ ], 3.14 ; atol= 1e-1 ))
1030+ @test all (isapprox .(info[:gc ][Hp+ 1 : end ], 0.0 ; atol= 1e-1 ))
10161031
10171032end
10181033
0 commit comments