1
1
@testitem " SteadyKalmanFilter construction" setup= [SetupMPCtests] begin
2
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
2
3
linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
3
4
skalmanfilter1 = SteadyKalmanFilter (linmodel1)
4
5
@test skalmanfilter1. nym == 2
61
62
end
62
63
63
64
@testitem " SteadyKalmanFilter estimator methods" setup= [SetupMPCtests] begin
65
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
64
66
linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
65
67
skalmanfilter1 = SteadyKalmanFilter (linmodel1, nint_ym= [1 , 1 ])
66
68
preparestate! (skalmanfilter1, [50 , 30 ])
112
114
end
113
115
114
116
@testitem " SteadyKalmanFilter set model" setup= [SetupMPCtests] begin
117
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
115
118
linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
116
119
linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
117
120
skalmanfilter = SteadyKalmanFilter (linmodel, nint_ym= 0 )
@@ -122,19 +125,21 @@ end
122
125
end
123
126
124
127
@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 )
126
130
skalmanfilter1 = SteadyKalmanFilter (linmodel1)
127
131
times1 = zeros (5 )
128
132
for i= 1 : 5
129
133
times1[i] = savetime! (skalmanfilter1)
130
134
preparestate! (skalmanfilter1, [1 ])
131
135
updatestate! (skalmanfilter1, [1 ], [1 ])
132
- periodsleep (skalmanfilter1)
136
+ periodsleep (skalmanfilter1, true )
133
137
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 ))
135
139
end
136
140
137
141
@testitem " KalmanFilter construction" setup= [SetupMPCtests] begin
142
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
138
143
linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
139
144
kalmanfilter1 = KalmanFilter (linmodel1)
140
145
@test kalmanfilter1. nym == 2
186
191
end
187
192
188
193
@testitem " KalmanFilter estimator methods" setup= [SetupMPCtests] begin
194
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
189
195
linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
190
196
kalmanfilter1 = KalmanFilter (linmodel1)
191
197
preparestate! (kalmanfilter1, [50 , 30 ])
232
238
end
233
239
234
240
@testitem " KalmanFilter set model" setup= [SetupMPCtests] begin
241
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
235
242
linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
236
243
linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
237
244
kalmanfilter = KalmanFilter (linmodel, nint_ym= 0 )
260
267
end
261
268
262
269
@testitem " Luenberger construction" setup= [SetupMPCtests] begin
270
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
263
271
linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
264
272
lo1 = Luenberger (linmodel1)
265
273
@test lo1. nym == 2
300
308
end
301
309
302
310
@testitem " Luenberger estimator methods" setup= [SetupMPCtests] begin
311
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
303
312
linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
304
313
lo1 = Luenberger (linmodel1, nint_ym= [1 , 1 ])
305
314
preparestate! (lo1, [50 , 30 ])
345
354
end
346
355
347
356
@testitem " Luenberger set model" setup= [SetupMPCtests] begin
357
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
348
358
linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
349
359
linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
350
360
lo = Luenberger (linmodel, nint_ym= 0 )
353
363
end
354
364
355
365
@testitem " InternalModel construction" setup= [SetupMPCtests] begin
366
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
356
367
linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
357
368
internalmodel1 = InternalModel (linmodel1)
358
369
@test internalmodel1. nym == 2
422
433
end
423
434
424
435
@testitem " InternalModel estimator methods" setup= [SetupMPCtests] begin
436
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
425
437
linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]) , uop= [10 ,50 ], yop= [50 ,30 ])
426
438
internalmodel1 = InternalModel (linmodel1)
427
439
preparestate! (internalmodel1, [50 , 30 ] .+ 1 )
459
471
end
460
472
461
473
@testitem " InternalModel set model" setup= [SetupMPCtests] begin
474
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
462
475
linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
463
476
linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
464
477
internalmodel = InternalModel (linmodel)
484
497
end
485
498
486
499
@testitem " UnscentedKalmanFilter construction" setup= [SetupMPCtests] begin
500
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
487
501
linmodel1 = LinModel (sys,Ts,i_d= [3 ])
488
502
f (x,u,d,_) = linmodel1. A* x + linmodel1. Bu* u + linmodel1. Bd* d
489
503
h (x,d,_) = linmodel1. C* x + linmodel1. Du* d
541
555
end
542
556
543
557
@testitem " UnscentedKalmanFilter estimator methods" setup= [SetupMPCtests] begin
558
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
544
559
linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
545
560
f (x,u,_,_) = linmodel1. A* x + linmodel1. Bu* u
546
561
h (x,_,_) = linmodel1. C* x
589
604
end
590
605
591
606
@testitem " UnscentedKalmanFilter set model" setup= [SetupMPCtests] begin
607
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
592
608
linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
593
609
linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
594
610
ukf1 = UnscentedKalmanFilter (linmodel, nint_ym= 0 )
625
641
end
626
642
627
643
@testitem " ExtendedKalmanFilter construction" setup= [SetupMPCtests] begin
644
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
628
645
linmodel1 = LinModel (sys,Ts,i_d= [3 ])
629
646
f (x,u,d,_) = linmodel1. A* x + linmodel1. Bu* u + linmodel1. Bd* d
630
647
h (x,d,_) = linmodel1. C* x + linmodel1. Du* d
678
695
end
679
696
680
697
@testitem " ExtendedKalmanFilter estimator methods" setup= [SetupMPCtests] begin
698
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
681
699
linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
682
700
f (x,u,_,_) = linmodel1. A* x + linmodel1. Bu* u
683
701
h (x,_,_) = linmodel1. C* x
726
744
end
727
745
728
746
@testitem " ExtendedKalmanFilter set model" setup= [SetupMPCtests] begin
747
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
729
748
linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
730
749
linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
731
750
ekf1 = ExtendedKalmanFilter (linmodel, nint_ym= 0 )
762
781
end
763
782
764
783
@testitem " MovingHorizonEstimator construction" setup= [SetupMPCtests] begin
784
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP, Ipopt
765
785
linmodel1 = LinModel (sys,Ts,i_d= [3 ])
766
786
f (x,u,d,_) = linmodel1. A* x + linmodel1. Bu* u + linmodel1. Bd* d
767
787
h (x,d,_) = linmodel1. C* x + linmodel1. Du* d
843
863
end
844
864
845
865
@testitem " MovingHorizonEstimator estimation and getinfo" setup= [SetupMPCtests] begin
866
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP, Ipopt, ForwardDiff
846
867
linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ], i_d= [3 ]), uop= [10 ,50 ], yop= [50 ,30 ], dop= [5 ])
847
868
f (x,u,d,_) = linmodel1. A* x + linmodel1. Bu* u + linmodel1. Bd* d
848
869
h (x,d,_) = linmodel1. C* x + linmodel1. Dd* d
@@ -935,12 +956,12 @@ end
935
956
preparestate! (mhe2, [50 , 30 ], [5 ])
936
957
updatestate! (mhe2, [11 , 52 ], [50 , 30 ], [5 ])
937
958
end
938
- @test mhe2 ([5 ]) ≈ [50 , 30 ] atol= 1e-3
959
+ @test mhe2 ([5 ]) ≈ [50 , 30 ] atol= 1e-2
939
960
for i in 1 : 40
940
961
preparestate! (mhe2, [51 , 32 ], [5 ])
941
962
updatestate! (mhe2, [10 , 50 ], [51 , 32 ], [5 ])
942
963
end
943
- @test mhe2 ([5 ]) ≈ [51 , 32 ] atol= 1e-3
964
+ @test mhe2 ([5 ]) ≈ [51 , 32 ] atol= 1e-2
944
965
linmodel3 = LinModel {Float32} (0.5 * ones (1 ,1 ), ones (1 ,1 ), ones (1 ,1 ), zeros (1 ,0 ), zeros (1 ,0 ), 1.0 )
945
966
mhe3 = MovingHorizonEstimator (linmodel3, He= 1 )
946
967
preparestate! (mhe3, [0 ])
973
994
end
974
995
975
996
@testitem " MovingHorizonEstimator fallbacks for arrival covariance estimation" setup= [SetupMPCtests] begin
997
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
976
998
linmodel = setop! (LinModel (sys,Ts,i_u= [1 ,2 ], i_d= [3 ]), uop= [10 ,50 ], yop= [50 ,30 ], dop= [5 ])
977
999
f (x,u,d,_) = linmodel. A* x + linmodel. Bu* u + linmodel. Bd* d
978
1000
h (x,d,_) = linmodel. C* x + linmodel. Dd* d
@@ -1017,6 +1039,7 @@ end
1017
1039
end
1018
1040
1019
1041
@testitem " MovingHorizonEstimator set constraints" setup= [SetupMPCtests] begin
1042
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
1020
1043
linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
1021
1044
mhe1 = MovingHorizonEstimator (linmodel1, He= 1 , nint_ym= 0 , Cwt= 1e3 )
1022
1045
setconstraint! (mhe1, x̂min= [- 51 ,- 52 ], x̂max= [53 ,54 ])
@@ -1098,6 +1121,7 @@ end
1098
1121
end
1099
1122
1100
1123
@testitem " MovingHorizonEstimator constraint violation" setup= [SetupMPCtests] begin
1124
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
1101
1125
linmodel1 = setop! (LinModel (sys,Ts,i_u= [1 ,2 ]), uop= [10 ,50 ], yop= [50 ,30 ])
1102
1126
mhe = MovingHorizonEstimator (linmodel1, He= 1 , nint_ym= 0 )
1103
1127
@@ -1196,6 +1220,7 @@ end
1196
1220
end
1197
1221
1198
1222
@testitem " MovingHorizonEstimator set model" setup= [SetupMPCtests] begin
1223
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
1199
1224
linmodel = LinModel (ss (0.5 , 0.3 , 1.0 , 0 , 10.0 ))
1200
1225
linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
1201
1226
mhe = MovingHorizonEstimator (linmodel, He= 1 , nint_ym= 0 , direct= false )
@@ -1240,6 +1265,7 @@ end
1240
1265
end
1241
1266
1242
1267
@testitem " MovingHorizonEstimator v.s. Kalman filters" setup= [SetupMPCtests] begin
1268
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
1243
1269
linmodel1 = setop! (LinModel (sys,Ts,i_d= [3 ]), uop= [10 ,50 ], yop= [50 ,30 ], dop= [20 ])
1244
1270
mhe = MovingHorizonEstimator (linmodel1, He= 3 , nint_ym= 0 , direct= false )
1245
1271
kf = KalmanFilter (linmodel1, nint_ym= 0 , direct= false )
@@ -1316,6 +1342,7 @@ end
1316
1342
end
1317
1343
1318
1344
@testitem " MovingHorizonEstimator LinModel v.s. NonLinModel" setup= [SetupMPCtests] begin
1345
+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP, Ipopt
1319
1346
linmodel = setop! (LinModel (sys,Ts,i_d= [3 ]), uop= [10 ,50 ], yop= [50 ,30 ], dop= [20 ])
1320
1347
f = (x,u,d,_) -> linmodel. A* x + linmodel. Bu* u + linmodel. Bd* d
1321
1348
h = (x,d,_) -> linmodel. C* x + linmodel. Dd* d
0 commit comments