@@ -815,14 +815,10 @@ end
815815 @test_throws ErrorException setmodel! (ekf2, deepcopy (nonlinmodel))
816816end
817817
818- @testitem " MovingHorizonEstimator construction" setup= [SetupMPCtests] begin
818+ @testitem " MovingHorizonEstimator construction (LinModel) " setup= [SetupMPCtests] begin
819819 using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
820- using JuMP, Ipopt, DifferentiationInterface
821820 import FiniteDiff
822821 linmodel = LinModel (sys,Ts,i_d= [3 ])
823- f (x,u,d,model) = model. A* x + model. Bu* u + model. Bd* d
824- h (x,d,model) = model. C* x + model. Dd* d
825- nonlinmodel = NonLinModel (f, h, Ts, 2 , 4 , 2 , 1 , solver= nothing , p= linmodel)
826822
827823 mhe1 = MovingHorizonEstimator (linmodel, He= 5 )
828824 @test mhe1. nym == 2
@@ -831,46 +827,68 @@ end
831827 @test mhe1. nx̂ == 6
832828 @test size (mhe1. Ẽ, 2 ) == 6 * mhe1. nx̂
833829
834- mhe2 = MovingHorizonEstimator (nonlinmodel, He= 5 )
835- @test mhe2. nym == 2
836- @test mhe2. nyu == 0
837- @test mhe2. nxs == 2
838- @test mhe2. nx̂ == 6
839- @test size (mhe1. Ẽ, 2 ) == 6 * mhe1. nx̂
840-
841- mhe3 = MovingHorizonEstimator (nonlinmodel, He= 5 , i_ym= [2 ])
830+ mhe3 = MovingHorizonEstimator (linmodel, He= 5 , i_ym= [2 ])
842831 @test mhe3. nym == 1
843832 @test mhe3. nyu == 1
844833 @test mhe3. nxs == 1
845834 @test mhe3. nx̂ == 5
846835
847- mhe4 = MovingHorizonEstimator (nonlinmodel , He= 5 , σQ= [1 ,2 ,3 ,4 ], σQint_ym= [5 , 6 ], σR= [7 , 8 ])
836+ mhe4 = MovingHorizonEstimator (linmodel , He= 5 , σQ= [1 ,2 ,3 ,4 ], σQint_ym= [5 , 6 ], σR= [7 , 8 ])
848837 @test mhe4. cov. Q̂ ≈ Hermitian (diagm (Float64[1 , 4 , 9 ,16 , 25 , 36 ]))
849838 @test mhe4. cov. R̂ ≈ Hermitian (diagm (Float64[49 , 64 ]))
850839
851- mhe5 = MovingHorizonEstimator (nonlinmodel , He= 5 , nint_ym= [2 ,2 ])
840+ mhe5 = MovingHorizonEstimator (linmodel , He= 5 , nint_ym= [2 ,2 ])
852841 @test mhe5. nxs == 4
853842 @test mhe5. nx̂ == 8
854843
855- mhe6 = MovingHorizonEstimator (nonlinmodel , He= 5 , σP_0= [1 ,2 ,3 ,4 ], σPint_ym_0= [5 ,6 ])
844+ mhe6 = MovingHorizonEstimator (linmodel , He= 5 , σP_0= [1 ,2 ,3 ,4 ], σPint_ym_0= [5 ,6 ])
856845 @test mhe6. cov. P̂_0 ≈ Hermitian (diagm (Float64[1 , 4 , 9 ,16 , 25 , 36 ]))
857846 @test mhe6. P̂arr_old ≈ Hermitian (diagm (Float64[1 , 4 , 9 ,16 , 25 , 36 ]))
858847 @test mhe6. cov. P̂_0 != = mhe6. P̂arr_old
859848
860- mhe7 = MovingHorizonEstimator (nonlinmodel , He= 10 )
849+ mhe7 = MovingHorizonEstimator (linmodel , He= 10 )
861850 @test mhe7. He == 10
862851 @test length (mhe7. X̂0) == mhe7. He* 6
863852 @test length (mhe7. Y0m) == mhe7. He* 2
864853 @test length (mhe7. U0) == mhe7. He* 2
865854 @test length (mhe7. D0) == (mhe7. He+ mhe7. direct)* 1
866855 @test length (mhe7. Ŵ) == mhe7. He* 6
867856
868- mhe8 = MovingHorizonEstimator (nonlinmodel , He= 5 , nint_u= [1 , 1 ], nint_ym= [0 , 0 ])
857+ mhe8 = MovingHorizonEstimator (linmodel , He= 5 , nint_u= [1 , 1 ], nint_ym= [0 , 0 ])
869858 @test mhe8. nxs == 2
870859 @test mhe8. nx̂ == 6
871860 @test mhe8. nint_u == [1 , 1 ]
872861 @test mhe8. nint_ym == [0 , 0 ]
873862
863+ mhe12 = MovingHorizonEstimator (linmodel, He= 5 , Cwt= 1e3 )
864+ @test size (mhe12. Ẽ, 2 ) == 6 * mhe12. nx̂ + 1
865+ @test mhe12. C == 1e3
866+
867+ linmodel2 = LinModel {Float32} (0.5 * ones (1 ,1 ), ones (1 ,1 ), ones (1 ,1 ), zeros (1 ,0 ), zeros (1 ,0 ), 1.0 )
868+ mhe13 = MovingHorizonEstimator (linmodel2, He= 5 )
869+ @test isa (mhe13, MovingHorizonEstimator{Float32})
870+
871+ @test_throws ArgumentError MovingHorizonEstimator (linmodel)
872+ @test_throws ArgumentError MovingHorizonEstimator (linmodel, He= 0 )
873+ @test_throws ArgumentError MovingHorizonEstimator (linmodel, Cwt= - 1 )
874+ end
875+
876+ @testitem " MovingHorizonEstimator construction (NonLinModel)" setup= [SetupMPCtests] begin
877+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
878+ using JuMP, Ipopt, DifferentiationInterface
879+ import FiniteDiff
880+ linmodel = LinModel (sys,Ts,i_d= [3 ])
881+ f (x,u,d,model) = model. A* x + model. Bu* u + model. Bd* d
882+ h (x,d,model) = model. C* x + model. Dd* d
883+ nonlinmodel = NonLinModel (f, h, Ts, 2 , 4 , 2 , 1 , solver= nothing , p= linmodel)
884+
885+ mhe2 = MovingHorizonEstimator (nonlinmodel, He= 5 )
886+ @test mhe2. nym == 2
887+ @test mhe2. nyu == 0
888+ @test mhe2. nxs == 2
889+ @test mhe2. nx̂ == 6
890+ @test size (mhe2. Ẽ, 2 ) == 6 * mhe2. nx̂
891+
874892 I_6 = Matrix {Float64} (I, 6 , 6 )
875893 I_2 = Matrix {Float64} (I, 2 , 2 )
876894 optim = Model (Ipopt. Optimizer)
886904 )
887905 @test solver_name (mhe10. optim) == " Ipopt"
888906
889- mhe12 = MovingHorizonEstimator (nonlinmodel, He= 5 , Cwt= 1e3 )
890- @test size (mhe12. Ẽ, 2 ) == 6 * mhe12. nx̂ + 1
891- @test mhe12. C == 1e3
892-
893- linmodel2 = LinModel {Float32} (0.5 * ones (1 ,1 ), ones (1 ,1 ), ones (1 ,1 ), zeros (1 ,0 ), zeros (1 ,0 ), 1.0 )
894- mhe13 = MovingHorizonEstimator (linmodel2, He= 5 )
895- @test isa (mhe13, MovingHorizonEstimator{Float32})
896-
897907 mhe14 = MovingHorizonEstimator (
898908 nonlinmodel, He= 5 ,
899909 gradient= AutoFiniteDiff (),
904914 @test mhe14. jacobian == AutoFiniteDiff ()
905915 @test mhe14. hessian == AutoFiniteDiff ()
906916
907- @test_throws ArgumentError MovingHorizonEstimator (linmodel)
908- @test_throws ArgumentError MovingHorizonEstimator (linmodel, He= 0 )
909- @test_throws ArgumentError MovingHorizonEstimator (linmodel, Cwt= - 1 )
910917 @test_throws ErrorException MovingHorizonEstimator (
911918 nonlinmodel, 5 , 1 : 2 , 0 , [1 , 1 ], I_6, I_6, I_2, Inf ; optim,
912919 covestim = InternalModel (nonlinmodel)
0 commit comments