@@ -1641,7 +1641,7 @@ end
16411641
16421642@testitem " MHE set model" setup= [SetupMPCtests] begin
16431643 using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
1644- linmodel = LinModel (ss ( 0.5 , 0.3 , 1.0 , 0 , 10.0 ) )
1644+ linmodel = LinModel ([ 0.5 ], [ 0.3 ], [ 1.0 ] , 0 , 0 , 10.0 )
16451645 linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
16461646 He = 5
16471647 mhe = MovingHorizonEstimator (linmodel; He, nint_ym= 0 , direct= false )
@@ -1651,7 +1651,7 @@ end
16511651 preparestate! (mhe, [50.0 ])
16521652 x̂ = updatestate! (mhe, [2.0 ], [50.0 ])
16531653 @test x̂ ≈ [3.0 ]
1654- newlinmodel = LinModel (ss ( 0.2 , 0.3 , 1.0 , 0 , 10.0 ) )
1654+ newlinmodel = LinModel ([ 0.2 ], [ 0.3 ], [ 1.0 ] , 0 , 0 , 10.0 )
16551655 newlinmodel = setop! (newlinmodel, uop= [3.0 ], yop= [55.0 ], xop= [3.0 ], fop= [3.0 ])
16561656 setmodel! (mhe, newlinmodel)
16571657 @test mhe. Â ≈ [0.2 ]
@@ -1676,18 +1676,49 @@ end
16761676 @test mhe. cov. invQ̂_He ≈ diagm (repeat ([1e3 ], He))
16771677 @test mhe. cov. R̂ ≈ [1e-6 ]
16781678 @test mhe. cov. invR̂_He ≈ diagm (repeat ([1e6 ], He))
1679+
1680+ linmodel = LinModel ([0.5 ], [0.3 ], [1.0 ], 0 , 0 , 10.0 )
1681+ linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
1682+ mhe2 = MovingHorizonEstimator (
1683+ linmodel; He, nint_ym= 0 , direct= false , transcription= SingleShooting ()
1684+ )
1685+ x̂ = updatestate! (mhe2, [2.0 + 1.0 ], [50.0 ])
1686+ @test x̂ ≈ [3.0 + 0.3 ] atol= 1e-3
1687+ newlinmodel = LinModel ([0.5 ], [0.9 ], [1.0 ], 0 , 0 , 10.0 )
1688+ newlinmodel = setop! (newlinmodel, uop= [3.0 ], yop= [55.0 ], xop= [8.0 ], fop= [8.0 ])
1689+ setmodel! (mhe2, newlinmodel)
1690+ initstate! (mhe2, [3.0 ], [55.0 ])
1691+ x̂ = updatestate! (mhe2, [3.0 + 1.0 ], [55.0 ])
1692+ @test x̂ ≈ [8.0 + 0.9 ] atol= 1e-3
1693+
1694+ linmodel = LinModel ([0.5 ], [0.3 ], [1.0 ], 0 , 0 , 10.0 )
1695+ linmodel = setop! (linmodel, uop= [2.0 ], yop= [50.0 ], xop= [3.0 ], fop= [3.0 ])
1696+ mhe3 = MovingHorizonEstimator (
1697+ linmodel; He, nint_ym= 0 , direct= false , transcription= MultipleShooting ()
1698+ )
1699+ x̂ = updatestate! (mhe3, [2.0 + 1.0 ], [50.0 ])
1700+ @test x̂ ≈ [3.0 + 0.3 ] atol= 1e-3
1701+ newlinmodel = LinModel ([0.5 ], [0.9 ], [1.0 ], 0 , 0 , 10.0 )
1702+ newlinmodel = setop! (newlinmodel, uop= [3.0 ], yop= [55.0 ], xop= [8.0 ], fop= [8.0 ])
1703+ setmodel! (mhe3, newlinmodel)
1704+ initstate! (mhe3, [3.0 ], [55.0 ])
1705+ x̂ = updatestate! (mhe3, [3.0 + 1.0 ], [55.0 ])
1706+ @test x̂ ≈ [8.0 + 0.9 ] atol= 1e-3
1707+
16791708 f (x,u,d,model) = model. A* x + model. Bu* u + model. Bd* d
16801709 h (x,d,model) = model. C* x + model. Du* d
16811710 nonlinmodel = NonLinModel (f, h, 10.0 , 1 , 1 , 1 , p= linmodel, solver= nothing )
1682- mhe2 = MovingHorizonEstimator (nonlinmodel; He, nint_ym= 0 )
1683- setmodel! (mhe2, Q̂= [1e-3 ], R̂= [1e-6 ])
1684- @test mhe2. cov. Q̂ ≈ [1e-3 ]
1685- @test mhe2. cov. invQ̂_He ≈ diagm (repeat ([1e3 ], He))
1686- @test mhe2. cov. R̂ ≈ [1e-6 ]
1687- @test mhe2. cov. invR̂_He ≈ diagm (repeat ([1e6 ], He))
1688- @test_throws ErrorException setmodel! (mhe2, deepcopy (nonlinmodel))
1711+ mhe5 = MovingHorizonEstimator (nonlinmodel; He, nint_ym= 0 )
1712+ setmodel! (mhe5, Q̂= [1e-3 ], R̂= [1e-6 ])
1713+ @test mhe5. cov. Q̂ ≈ [1e-3 ]
1714+ @test mhe5. cov. invQ̂_He ≈ diagm (repeat ([1e3 ], He))
1715+ @test mhe5. cov. R̂ ≈ [1e-6 ]
1716+ @test mhe5. cov. invR̂_He ≈ diagm (repeat ([1e6 ], He))
1717+
1718+ @test_throws ErrorException setmodel! (mhe5, deepcopy (nonlinmodel))
16891719 @test_throws ErrorException setmodel! (mhe, Q̂= diagm ([- 0.1 ]))
16901720 @test_throws ErrorException setmodel! (mhe, R̂= diagm ([- 0.1 ]))
1721+
16911722end
16921723
16931724@testitem " MHE v.s. Kalman filters" setup= [SetupMPCtests] begin
0 commit comments