11@testitem " SteadyKalmanFilter construction" setup= [SetupMPCtests] begin
2+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
23 linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
34 skalmanfilter1 = SteadyKalmanFilter (linmodel1)
45 @test skalmanfilter1. nym == 2
6162end
6263
6364@testitem " SteadyKalmanFilter estimator methods" setup= [SetupMPCtests] begin
65+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
6466 linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
6567 skalmanfilter1 = SteadyKalmanFilter (linmodel1, nint_ym= [1 , 1 ])
6668 preparestate! (skalmanfilter1, [50 , 30 ])
112114end
113115
114116@testitem " SteadyKalmanFilter set model" setup= [SetupMPCtests] begin
117+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
115118 linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
116119 linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
117120 skalmanfilter = SteadyKalmanFilter (linmodel, nint_ym= 0 )
@@ -122,19 +125,21 @@ end
122125end
123126
124127@testitem " SteadyKalmanFilter real-time simulations" setup= [SetupMPCtests] begin
125- linmodel1 = LinModel (tf (2 , [10 , 1 ]), 0.1 )
128+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
129+ linmodel1 = LinModel (tf (2 , [10 , 1 ]), 0.25 )
126130 skalmanfilter1 = SteadyKalmanFilter (linmodel1)
127131 times1 = zeros (5 )
128132 for i= 1 : 5
129133 times1[i] = savetime! (skalmanfilter1)
130134 preparestate! (skalmanfilter1, [1 ])
131135 updatestate! (skalmanfilter1, [1 ], [1 ])
132- periodsleep (skalmanfilter1)
136+ periodsleep (skalmanfilter1, true )
133137 end
134- @test all (isapprox .(diff (times1[2 : end ]), 0.1 , atol= 0.01 ))
138+ @test all (isapprox .(diff (times1[2 : end ]), 0.25 , atol= 0.01 ))
135139end
136140
137141@testitem " KalmanFilter construction" setup= [SetupMPCtests] begin
142+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
138143 linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
139144 kalmanfilter1 = KalmanFilter (linmodel1)
140145 @test kalmanfilter1. nym == 2
186191end
187192
188193@testitem " KalmanFilter estimator methods" setup= [SetupMPCtests] begin
194+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
189195 linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
190196 kalmanfilter1 = KalmanFilter (linmodel1)
191197 preparestate! (kalmanfilter1, [50 , 30 ])
232238end
233239
234240@testitem " KalmanFilter set model" setup= [SetupMPCtests] begin
241+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
235242 linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
236243 linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
237244 kalmanfilter = KalmanFilter (linmodel, nint_ym= 0 )
260267end
261268
262269@testitem " Luenberger construction" setup= [SetupMPCtests] begin
270+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
263271 linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
264272 lo1 = Luenberger (linmodel1)
265273 @test lo1. nym == 2
300308end
301309
302310@testitem " Luenberger estimator methods" setup= [SetupMPCtests] begin
311+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
303312 linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
304313 lo1 = Luenberger (linmodel1, nint_ym= [1 , 1 ])
305314 preparestate! (lo1, [50 , 30 ])
345354end
346355
347356@testitem " Luenberger set model" setup= [SetupMPCtests] begin
357+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
348358 linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
349359 linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
350360 lo = Luenberger (linmodel, nint_ym= 0 )
353363end
354364
355365@testitem " InternalModel construction" setup= [SetupMPCtests] begin
366+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
356367 linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
357368 internalmodel1 = InternalModel (linmodel1)
358369 @test internalmodel1. nym == 2
422433end
423434
424435@testitem " InternalModel estimator methods" setup= [SetupMPCtests] begin
436+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
425437 linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]) , uop= [10 ,50 ], yop= [50 ,30 ])
426438 internalmodel1 = InternalModel (linmodel1)
427439 preparestate! (internalmodel1, [50 , 30 ] .+ 1 )
459471end
460472
461473@testitem " InternalModel set model" setup= [SetupMPCtests] begin
474+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
462475 linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
463476 linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
464477 internalmodel = InternalModel (linmodel)
484497end
485498
486499@testitem " UnscentedKalmanFilter construction" setup= [SetupMPCtests] begin
500+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
487501 linmodel1 = LinModel (sys,Ts,i_d= [3 ])
488502 f (x,u,d,_) = linmodel1. A* x + linmodel1. Bu* u + linmodel1. Bd* d
489503 h (x,d,_) = linmodel1. C* x + linmodel1. Du* d
541555end
542556
543557@testitem " UnscentedKalmanFilter estimator methods" setup= [SetupMPCtests] begin
558+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
544559 linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
545560 f (x,u,_,_) = linmodel1. A* x + linmodel1. Bu* u
546561 h (x,_,_) = linmodel1. C* x
589604end
590605
591606@testitem " UnscentedKalmanFilter set model" setup= [SetupMPCtests] begin
607+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
592608 linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
593609 linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
594610 ukf1 = UnscentedKalmanFilter (linmodel, nint_ym= 0 )
625641end
626642
627643@testitem " ExtendedKalmanFilter construction" setup= [SetupMPCtests] begin
644+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
628645 linmodel1 = LinModel (sys,Ts,i_d= [3 ])
629646 f (x,u,d,_) = linmodel1. A* x + linmodel1. Bu* u + linmodel1. Bd* d
630647 h (x,d,_) = linmodel1. C* x + linmodel1. Du* d
678695end
679696
680697@testitem " ExtendedKalmanFilter estimator methods" setup= [SetupMPCtests] begin
698+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
681699 linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
682700 f (x,u,_,_) = linmodel1. A* x + linmodel1. Bu* u
683701 h (x,_,_) = linmodel1. C* x
726744end
727745
728746@testitem " ExtendedKalmanFilter set model" setup= [SetupMPCtests] begin
747+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
729748 linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
730749 linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
731750 ekf1 = ExtendedKalmanFilter (linmodel, nint_ym= 0 )
762781end
763782
764783@testitem " MovingHorizonEstimator construction" setup= [SetupMPCtests] begin
784+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP, Ipopt
765785 linmodel1 = LinModel (sys,Ts,i_d= [3 ])
766786 f (x,u,d,_) = linmodel1. A* x + linmodel1. Bu* u + linmodel1. Bd* d
767787 h (x,d,_) = linmodel1. C* x + linmodel1. Du* d
843863end
844864
845865@testitem " MovingHorizonEstimator estimation and getinfo" setup= [SetupMPCtests] begin
866+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP, Ipopt, ForwardDiff
846867 linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ], i_d= [3 ]), uop= [10 ,50 ], yop= [50 ,30 ], dop= [5 ])
847868 f (x,u,d,_) = linmodel1. A* x + linmodel1. Bu* u + linmodel1. Bd* d
848869 h (x,d,_) = linmodel1. C* x + linmodel1. Dd* d
@@ -935,12 +956,12 @@ end
935956 preparestate! (mhe2, [50 , 30 ], [5 ])
936957 updatestate! (mhe2, [11 , 52 ], [50 , 30 ], [5 ])
937958 end
938- @test mhe2 ([5 ]) ≈ [50 , 30 ] atol= 1e-3
959+ @test mhe2 ([5 ]) ≈ [50 , 30 ] atol= 1e-2
939960 for i in 1 : 40
940961 preparestate! (mhe2, [51 , 32 ], [5 ])
941962 updatestate! (mhe2, [10 , 50 ], [51 , 32 ], [5 ])
942963 end
943- @test mhe2 ([5 ]) ≈ [51 , 32 ] atol= 1e-3
964+ @test mhe2 ([5 ]) ≈ [51 , 32 ] atol= 1e-2
944965 linmodel3 = LinModel {Float32} (0.5 * ones (1 ,1 ), ones (1 ,1 ), ones (1 ,1 ), zeros (1 ,0 ), zeros (1 ,0 ), 1.0 )
945966 mhe3 = MovingHorizonEstimator (linmodel3, He= 1 )
946967 preparestate! (mhe3, [0 ])
973994end
974995
975996@testitem " MovingHorizonEstimator fallbacks for arrival covariance estimation" setup= [SetupMPCtests] begin
997+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
976998 linmodel = setop! (LinModel (sys,Ts,i_u= [1 ,2 ], i_d= [3 ]), uop= [10 ,50 ], yop= [50 ,30 ], dop= [5 ])
977999 f (x,u,d,_) = linmodel. A* x + linmodel. Bu* u + linmodel. Bd* d
9781000 h (x,d,_) = linmodel. C* x + linmodel. Dd* d
@@ -1017,6 +1039,7 @@ end
10171039end
10181040
10191041@testitem " MovingHorizonEstimator set constraints" setup= [SetupMPCtests] begin
1042+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
10201043 linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
10211044 mhe1 = MovingHorizonEstimator (linmodel1, He= 1 , nint_ym= 0 , Cwt= 1e3 )
10221045 setconstraint! (mhe1, x̂min= [- 51 ,- 52 ], x̂max= [53 ,54 ])
@@ -1098,6 +1121,7 @@ end
10981121end
10991122
11001123@testitem " MovingHorizonEstimator constraint violation" setup= [SetupMPCtests] begin
1124+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
11011125 linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
11021126 mhe = MovingHorizonEstimator (linmodel1, He= 1 , nint_ym= 0 )
11031127
@@ -1196,6 +1220,7 @@ end
11961220end
11971221
11981222@testitem " MovingHorizonEstimator set model" setup= [SetupMPCtests] begin
1223+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
11991224 linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
12001225 linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
12011226 mhe = MovingHorizonEstimator (linmodel, He= 1 , nint_ym= 0 , direct= false )
@@ -1240,6 +1265,7 @@ end
12401265end
12411266
12421267@testitem " MovingHorizonEstimator v.s. Kalman filters" setup= [SetupMPCtests] begin
1268+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
12431269 linmodel1 = setop! (LinModel (sys,Ts,i_d= [3 ]), uop= [10 ,50 ], yop= [50 ,30 ], dop= [20 ])
12441270 mhe = MovingHorizonEstimator (linmodel1, He= 3 , nint_ym= 0 , direct= false )
12451271 kf = KalmanFilter (linmodel1, nint_ym= 0 , direct= false )
@@ -1316,6 +1342,7 @@ end
13161342end
13171343
13181344@testitem " MovingHorizonEstimator LinModel v.s. NonLinModel" setup= [SetupMPCtests] begin
1345+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP, Ipopt
13191346 linmodel = setop! (LinModel (sys,Ts,i_d= [3 ]), uop= [10 ,50 ], yop= [50 ,30 ], dop= [20 ])
13201347 f = (x,u,d,_) -> linmodel. A* x + linmodel. Bu* u + linmodel. Bd* d
13211348 h = (x,d,_) -> linmodel. C* x + linmodel. Dd* d
0 commit comments