Skip to content

Commit a7346af

Browse files
committed
test: improve coverage of MovingHorizonEstimator constructor
Testing covariance matrices with non-zero off-diagonal coefficients.
1 parent 2ce8153 commit a7346af

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

‎test/2_test_state_estim.jl‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,15 +1020,34 @@ end
10201020
He = 3
10211021
nx̂ = linmodel.nx
10221022
nc = nx̂*(He+1)
1023-
mhe = MovingHorizonEstimator(linmodel, nint_ym=0, Cwt=1e5, He=He, gc=gcl, nc=nc, p=nc)
1024-
@test mhe.con.nc == nc
1025-
@test mhe.nε > 0
1026-
@test mhe.He == 3
1027-
1023+
mhe16 = MovingHorizonEstimator(linmodel, nint_ym=0, Cwt=1e5, He=He, gc=gcl, nc=nc, p=nc)
1024+
@test mhe16.con.nc == nc
1025+
@test mhe16.nε > 0
1026+
@test mhe16.He == 3
1027+
1028+
He, i_ym, nint_u, nint_ym = 1, 1:2, 0, 0
1029+
P̂_0 = fill(0.5, 4, 4)
1030+
P̂_0[diagind(P̂_0)] .= 1.0
1031+
Q̂, R̂ = 0.5*P̂_0, [0.1 0.01; 0.01 0.1]
1032+
mhe17 = MovingHorizonEstimator(linmodel, He, i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂)
1033+
@test mhe17.cov.invP̄ ≈ inv(P̂_0)
1034+
@test mhe17.cov.invQ̂_He ≈ inv(Q̂)
1035+
@test mhe17.cov.invR̂_He ≈ inv(R̂)
1036+
10281037
@test_throws ArgumentError MovingHorizonEstimator(linmodel)
10291038
@test_throws ArgumentError MovingHorizonEstimator(linmodel, He=0)
10301039
@test_throws ArgumentError MovingHorizonEstimator(linmodel, Cwt=-1)
10311040
@test_throws ArgumentError MovingHorizonEstimator(linmodel, He=1, σP_0=nothing)
1041+
@test_throws PosDefException MovingHorizonEstimator(
1042+
linmodel, He, i_ym, nint_u, nint_ym, zeros(4, 4), Q̂, R̂
1043+
)
1044+
@test_throws PosDefException MovingHorizonEstimator(
1045+
linmodel, He, i_ym, nint_u, nint_ym, P̂_0, zeros(4, 4), R̂
1046+
)
1047+
@test_throws PosDefException MovingHorizonEstimator(
1048+
linmodel, He, i_ym, nint_u, nint_ym, P̂_0, Q̂, zeros(2, 2)
1049+
)
1050+
10321051
end
10331052

10341053
@testitem "MHE construction (NonLinModel)" setup=[SetupMPCtests] begin

0 commit comments

Comments
 (0)