11@testitem " LinMPC construction" setup= [SetupMPCtests] begin
2+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP, DAQP
23 model = LinModel (sys, Ts, i_d= [3 ])
34 mpc1 = LinMPC (model, Hp= 15 )
45 @test isa (mpc1. estim, SteadyKalmanFilter)
5556end
5657
5758@testitem " LinMPC moves and getinfo" setup= [SetupMPCtests] begin
59+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
60+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
5861 linmodel = setop! (LinModel (tf (5 , [2 , 1 ]), 3 ), yop= [10 ])
5962 mpc1 = LinMPC (linmodel, Nwt= [0 ], Hp= 1000 , Hc= 1 )
6063 r = [15 ]
8891end
8992
9093@testitem " LinMPC step disturbance rejection" setup= [SetupMPCtests] begin
94+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
9195 linmodel = setop! (LinModel (tf (5 , [2 , 1 ]), 3.0 ), yop= [10 ])
9296 r = [15 ]
9397 outdist = [5 ]
130134end
131135
132136@testitem " LinMPC other methods" setup= [SetupMPCtests] begin
137+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
133138 linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
134139 mpc1 = LinMPC (linmodel1)
135140 @test initstate! (mpc1, [10 , 50 ], [50 , 30 + 1 ]) ≈ [zeros (3 ); [1 ]]
148153end
149154
150155@testitem " LinMPC set constraints" setup= [SetupMPCtests] begin
156+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
151157 model = LinModel (sys, Ts, i_d= [3 ])
152158 mpc = LinMPC (model, Hp= 1 , Hc= 1 )
153159
215221end
216222
217223@testitem " LinMPC constraint violation" setup= [SetupMPCtests] begin
224+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
218225 model = LinModel (tf ([2 ], [10 , 1 ]), 3.0 )
219226 mpc = LinMPC (model, Hp= 50 , Hc= 5 )
220227
273280end
274281
275282@testitem " LinMPC terminal cost" setup= [SetupMPCtests] begin
283+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
276284 model = LinModel (ss ([0.5 - 0.4 ;0.6 0.5 ], [1 0 ;0 1 ], [1 0 ; 0 1 ], 0 , 1 ))
277285 K = lqr (Discrete, model. A, model. Bu, I, 0.5 I)
278286 M_end = ControlSystemsBase. are (Discrete, model. A, model. Bu, I, 0.5 I)
300308end
301309
302310@testitem " LinMPC set model" setup= [SetupMPCtests] begin
311+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
303312 estim = KalmanFilter (setop! (LinModel (tf (5 , [2 , 1 ]), 3 ), yop= [10 ], uop= [1 ]))
304313 mpc = LinMPC (estim, Nwt= [0 ], Cwt= 1e4 , Hp= 1000 , Hc= 1 )
305314 mpc = setconstraint! (mpc, umin= [- 24 ], umax= [26 ])
339348end
340349
341350@testitem " LinMPC real-time simulations" setup= [SetupMPCtests] begin
351+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
342352 linmodel1 = LinModel (tf (2 , [10 , 1 ]), 0.1 )
343353 mpc1 = LinMPC (linmodel1)
344354 times1 = zeros (5 )
352362end
353363
354364@testitem " ExplicitMPC construction" setup= [SetupMPCtests] begin
365+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
355366 model = LinModel (sys, Ts, i_d= [3 ])
356367 mpc1 = ExplicitMPC (model, Hp= 15 )
357368 @test isa (mpc1. estim, SteadyKalmanFilter)
382393end
383394
384395@testitem " ExplicitMPC moves and getinfo" setup= [SetupMPCtests] begin
396+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
385397 mpc1 = ExplicitMPC (LinModel (tf (5 , [2 , 1 ]), 3 ), Nwt= [0 ], Hp= 1000 , Hc= 1 )
386398 r = [5 ]
387399 preparestate! (mpc1, [0 ])
409421
410422
411423@testitem " ExplicitMPC step disturbance rejection" setup= [SetupMPCtests] begin
424+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
412425 linmodel = setop! (LinModel (tf (5 , [2 , 1 ]), 3.0 ), yop= [10 ])
413426 r = [15 ]
414427 outdist = [5 ]
451464end
452465
453466@testitem " ExplicitMPC other methods" setup= [SetupMPCtests] begin
467+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
454468 linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
455469 mpc1 = ExplicitMPC (linmodel1)
456470 @test initstate! (mpc1, [10 , 50 ], [50 , 30 + 1 ]) ≈ [zeros (3 ); [1 ]]
@@ -465,12 +479,14 @@ end
465479end
466480
467481@testitem " ExplicitMPC constraints" setup= [SetupMPCtests] begin
482+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
468483 model = LinModel (sys, Ts, i_d= [3 ])
469484 mpc = ExplicitMPC (model, Hp= 1 , Hc= 1 )
470485 @test_throws ErrorException setconstraint! (mpc, umin= [0.0 , 0.0 ])
471486end
472487
473488@testitem " ExplicitMPC set model" setup= [SetupMPCtests] begin
489+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
474490 estim = KalmanFilter (setop! (LinModel (tf (5 , [2 , 1 ]), 3 ), yop= [10 ], uop= [1 ]))
475491 mpc = ExplicitMPC (estim, Nwt= [0 ], Hp= 1000 , Hc= 1 )
476492 @test mpc. Yop ≈ fill (10.0 , 1000 )
500516end
501517
502518@testitem " NonLinMPC construction" setup= [SetupMPCtests] begin
519+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP, Ipopt
503520 linmodel1 = LinModel (sys,Ts,i_d= [3 ])
504521 nmpc0 = NonLinMPC (linmodel1, Hp= 15 )
505522 @test isa (nmpc0. estim, SteadyKalmanFilter)
563580end
564581
565582@testitem " NonLinMPC moves and getinfo" setup= [SetupMPCtests] begin
583+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
566584 linmodel = setop! (LinModel (tf (5 , [2000 , 1 ]), 3000.0 ), yop= [10 ])
567585 Hp = 1000
568586 nmpc_lin = NonLinMPC (linmodel, Nwt= [0 ], Hp= Hp, Hc= 1 )
635653end
636654
637655@testitem " NonLinMPC step disturbance rejection" setup= [SetupMPCtests] begin
656+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
638657 linmodel = setop! (LinModel (tf (5 , [2000 , 1 ]), 3000.0 ), yop= [10 ])
639658 r = [15 ]
640659 outdist = [5 ]
677696end
678697
679698@testitem " NonLinMPC other methods" setup= [SetupMPCtests] begin
699+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
680700 linmodel = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
681701 f = (x,u,_,_) -> linmodel. A* x + linmodel. Bu* u
682702 h = (x,_,_) -> linmodel. C* x
694714end
695715
696716@testitem " NonLinMPC set constraints" setup= [SetupMPCtests] begin
717+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
697718 linmodel1 = LinModel (sys,Ts,i_d= [3 ])
698719 nmpc_lin = NonLinMPC (linmodel1, Hp= 1 , Hc= 1 )
699720
729750end
730751
731752@testitem " NonLinMPC constraint violation" setup= [SetupMPCtests] begin
753+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
732754 gc (Ue, Ŷe, _ ,p , ϵ) = [p[1 ]* (Ue[1 : end - 1 ] .- 4.2 .- ϵ); p[2 ]* (Ŷe[2 : end ] .- 3.14 .- ϵ)]
733755 Hp= 50
734756
737759
738760 setconstraint! (nmpc_lin, x̂min= [- 1e6 ,- Inf ], x̂max= [1e6 ,+ Inf ])
739761 setconstraint! (nmpc_lin, umin= [- 10 ], umax= [10 ])
740- setconstraint! (nmpc_lin, Δumin= [- 15 ], Δumax= [15 ])
762+ setconstraint! (nmpc_lin, Δumin= [- 1e6 ], Δumax= [1e6 ])
741763 setconstraint! (nmpc_lin, ymin= [- 100 ], ymax= [100 ])
742764 preparestate! (nmpc_lin, [0 ])
743765
805827 nonlinmodel = NonLinModel (f, h, linmodel. Ts, 1 , 1 , 1 , solver= nothing , p= linmodel)
806828 nmpc = NonLinMPC (nonlinmodel, Hp= 50 , Hc= 5 , gc= gc, nc= 2 Hp, p= [0 ; 0 ])
807829
808- setconstraint! (nmpc, x̂min= [- 1e6 ,- Inf ], x̂max= [1e6 ,+ Inf ])
809- setconstraint! (nmpc, umin= [- 10 ], umax= [10 ])
830+ setconstraint! (nmpc, x̂min= [- 1e6 ,- Inf ], x̂max= [+ 1e6 ,+ Inf ])
831+ setconstraint! (nmpc, umin= [- 1e6 ], umax= [+ 1e6 ])
810832 setconstraint! (nmpc, Δumin= [- 15 ], Δumax= [15 ])
811833 setconstraint! (nmpc, ymin= [- 100 ], ymax= [100 ])
812834 preparestate! (nmpc, [0 ])
818840 moveinput! (nmpc, [100 ])
819841 info = getinfo (nmpc)
820842 @test all (isapprox .(info[:U ], 4 ; atol= 1e-1 ))
821- setconstraint! (nmpc, umin= [- 10 ], umax= [10 ])
843+ setconstraint! (nmpc, umin= [- 1e6 ], umax= [+ 1e6 ])
822844
823845 setconstraint! (nmpc, Δumin= [- 1.5 ], Δumax= [1.25 ])
824846 moveinput! (nmpc, [- 100 ])
827849 moveinput! (nmpc, [100 ])
828850 info = getinfo (nmpc)
829851 @test all (isapprox .(info[:ΔU ], 1.25 ; atol= 1e-1 ))
830- setconstraint! (nmpc, Δumin= [- 15 ], Δumax= [15 ])
852+ setconstraint! (nmpc, Δumin= [- 1e6 ], Δumax= [+ 1e6 ])
831853
832854 setconstraint! (nmpc, ymin= [- 0.5 ], ymax= [0.9 ])
833855 moveinput! (nmpc, [- 100 ])
@@ -839,13 +861,13 @@ end
839861 setconstraint! (nmpc, ymin= [- 100 ], ymax= [100 ])
840862
841863 setconstraint! (nmpc, Ymin= [- 0.5 ; fill (- 100 , Hp- 1 )], Ymax= [0.9 ; fill (+ 100 , Hp- 1 )])
842- moveinput! (nmpc, [- 10 ])
864+ moveinput! (nmpc, [- 200 ])
843865 info = getinfo (nmpc)
844- @test info[:Ŷ ][end ] ≈ - 10 atol= 1e-1
866+ @test info[:Ŷ ][end ] ≈ - 100 atol= 1e-1
845867 @test info[:Ŷ ][begin ] ≈ - 0.5 atol= 1e-1
846- moveinput! (nmpc, [10 ])
868+ moveinput! (nmpc, [200 ])
847869 info = getinfo (nmpc)
848- @test info[:Ŷ ][end ] ≈ 10 atol= 1e-1
870+ @test info[:Ŷ ][end ] ≈ 100 atol= 1e-1
849871 @test info[:Ŷ ][begin ] ≈ 0.9 atol= 1e-1
850872 setconstraint! (nmpc, ymin= [- 100 ], ymax= [100 ])
851873
873895end
874896
875897@testitem " NonLinMPC set model" setup= [SetupMPCtests] begin
898+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
876899 estim = KalmanFilter (setop! (LinModel (tf (5 , [200 , 1 ]), 300 ), yop= [10 ], uop= [1 ]))
877900 mpc = NonLinMPC (estim, Nwt= [0 ], Cwt= 1e4 , Hp= 1000 , Hc= 1 )
878901 mpc = setconstraint! (mpc, umin= [- 24 ], umax= [26 ])
925948end
926949
927950@testitem " LinMPC v.s. NonLinMPC" setup= [SetupMPCtests] begin
951+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP, Ipopt
928952 linmodel = setop! (LinModel (sys,Ts,i_d= [3 ]), uop= [10 ,50 ], yop= [50 ,30 ], dop= [20 ])
929953 f = (x,u,d,_) -> linmodel. A* x + linmodel. Bu* u + linmodel. Bd* d
930954 h = (x,d,_) -> linmodel. C* x + linmodel. Dd* d
0 commit comments