@@ -955,36 +955,53 @@ end
955955 f = (x,u,d,model) -> model. A* x + model. Bu* u + model. Bd* d
956956 h = (x,d,model) -> model. C* x + model. Dd* d
957957 nonlinmodel = NonLinModel (f, h, 3000.0 , 1 , 2 , 1 , 1 , solver= nothing , p= linmodel2)
958+
959+ f! = (ẋ,x,u,_,_) -> ẋ .= - 0.001 x .+ u
960+ h! = (y,x,_,_) -> y .= x
961+ nonlinmodel_c = NonLinModel (f!, h!, 500 , 1 , 1 , 1 )
958962
959- nmpc2 = NonLinMPC (nonlinmodel, Nwt= [0 ], Hp= 100 , Hc= 1 )
960- preparestate! (nmpc2 , [0 ], [0 ])
963+ nmpc1 = NonLinMPC (nonlinmodel, Nwt= [0 ], Hp= 100 , Hc= 1 )
964+ preparestate! (nmpc1 , [0 ], [0 ])
961965 # if d=[0.1], the output will eventually reach 7*0.1=0.7, no action needed (u=0):
962966 d = [0.1 ]
963- u = moveinput! (nmpc2 , 7 d, d)
967+ u = moveinput! (nmpc1 , 7 d, d)
964968 @test u ≈ [0 ] atol= 5e-2
965- u = nmpc2 (7 d, d)
969+ u = nmpc1 (7 d, d)
966970 @test u ≈ [0 ] atol= 5e-2
967- info = getinfo (nmpc2 )
971+ info = getinfo (nmpc1 )
968972 @test info[:u ] ≈ u
969973 @test info[:Ŷ ][end ] ≈ 7 d[1 ] atol= 5e-2
970974
971- nmpc3 = NonLinMPC (nonlinmodel, Nwt= [0 ], Cwt= Inf , Hp= 100 , Hc= 1 )
972- preparestate! (nmpc3 , [0 ], [0 ])
973- u = moveinput! (nmpc3 , 7 d, d)
975+ nmpc2 = NonLinMPC (nonlinmodel, Nwt= [0 ], Cwt= Inf , Hp= 100 , Hc= 1 )
976+ preparestate! (nmpc2 , [0 ], [0 ])
977+ u = moveinput! (nmpc2 , 7 d, d)
974978 @test u ≈ [0 ] atol= 5e-2
975979
976- nmpc4 = NonLinMPC (nonlinmodel, Hp= 15 , Mwt= [0 ], Nwt= [0 ], Lwt= [1 ])
977- preparestate! (nmpc4 , [0 ], [0 ])
978- u = moveinput! (nmpc4 , [0 ], d, R̂u= fill (12 , nmpc4 . Hp))
980+ nmpc3 = NonLinMPC (nonlinmodel, Hp= 15 , Mwt= [0 ], Nwt= [0 ], Lwt= [1 ])
981+ preparestate! (nmpc3 , [0 ], [0 ])
982+ u = moveinput! (nmpc3 , [0 ], d, R̂u= fill (12 , nmpc3 . Hp))
979983 @test u ≈ [12 ] atol= 5e-2
984+
985+ transcription = MultipleShooting ()
986+ nmpc4 = NonLinMPC (nonlinmodel; Nwt= [0 ], Hp= 100 , Hc= 1 , transcription)
987+ preparestate! (nmpc4, [0 ], [0 ])
988+ u = moveinput! (nmpc4, [10 ], [0 ])
989+ @test u ≈ [2 ] atol= 5e-2
990+ info = getinfo (nmpc4)
991+ @test info[:u ] ≈ u
992+ @test info[:Ŷ ][end ] ≈ 10 atol= 5e-2
980993
981- nmpc5 = NonLinMPC (nonlinmodel, Hp= 1 , Hc= 1 , Cwt= Inf , transcription= MultipleShooting ())
982- nmpc5 = setconstraint! (nmpc5, ymin= [1 ])
983- f! = (ẋ,x,u,_,_) -> ẋ .= - 0.001 x .+ u
984- h! = (y,x,_,_) -> y .= x
985- nonlinmodel_c = NonLinModel (f!, h!, 500 , 1 , 1 , 1 )
994+ transcription = MultipleShooting (f_threads= true , h_threads= true )
995+ nmpc4t = NonLinMPC (nonlinmodel; Nwt= [0 ], Hp= 100 , Hc= 1 , transcription, hessian= true )
996+ nmpc4t = setconstraint! (nmpc4t, ymax= [100 ], ymin= [- 100 ]) # coverage of getinfo! Hessians of Lagrangian
997+ preparestate! (nmpc4t, [0 ], [0 ])
998+ u = moveinput! (nmpc4t, [10 ], [0 ])
999+ @test u ≈ [2 ] atol= 5e-2
1000+ info = getinfo (nmpc4t)
1001+ @test info[:u ] ≈ u
1002+ @test info[:Ŷ ][end ] ≈ 10 atol= 5e-2
1003+
9861004 transcription = TrapezoidalCollocation (0 , f_threads= true , h_threads= true )
987-
9881005 nmpc5 = NonLinMPC (nonlinmodel_c; Nwt= [0 ], Hp= 100 , Hc= 1 , transcription)
9891006 preparestate! (nmpc5, [0.0 ])
9901007 u = moveinput! (nmpc5, [1 / 0.001 ])
@@ -1014,25 +1031,6 @@ end
10141031 ModelPredictiveControl. h! (y, nonlinmodel2, Float32[0 ,0 ], Float32[0 ], nonlinmodel2. p)
10151032 preparestate! (nmpc7, [0 ], [0 ])
10161033 @test moveinput! (nmpc7, [0 ], [0 ]) ≈ [0.0 ] atol= 5e-2
1017- transcription = MultipleShooting ()
1018-
1019- nmpc8 = NonLinMPC (nonlinmodel; Nwt= [0 ], Hp= 100 , Hc= 1 , transcription)
1020- preparestate! (nmpc8, [0 ], [0 ])
1021- u = moveinput! (nmpc8, [10 ], [0 ])
1022- @test u ≈ [2 ] atol= 5e-2
1023- info = getinfo (nmpc8)
1024- @test info[:u ] ≈ u
1025- @test info[:Ŷ ][end ] ≈ 10 atol= 5e-2
1026-
1027- transcription = MultipleShooting (f_threads= true , h_threads= true )
1028- nmpc8t = NonLinMPC (nonlinmodel; Nwt= [0 ], Hp= 100 , Hc= 1 , transcription, hessian= true )
1029- nmpc8t = setconstraint! (nmpc8t, ymax= [100 ], ymin= [- 100 ]) # coverage of getinfo! Hessians of Lagrangian
1030- preparestate! (nmpc8t, [0 ], [0 ])
1031- u = moveinput! (nmpc8t, [10 ], [0 ])
1032- @test u ≈ [2 ] atol= 5e-2
1033- info = getinfo (nmpc8t)
1034- @test info[:u ] ≈ u
1035- @test info[:Ŷ ][end ] ≈ 10 atol= 5e-2
10361034
10371035 nmpc10 = setconstraint! (NonLinMPC (
10381036 nonlinmodel, Nwt= [0 ], Hp= 100 , Hc= 1 ,
0 commit comments