Skip to content

Commit 5093ab0

Browse files
authored
Merge pull request #42 from JuliaControl/mhe_covestim_tests
added: tests for MHE custom covariance estimator
2 parents d19acc4 + 265ba65 commit 5093ab0

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

test/test_state_estim.jl

+26-7
Original file line numberDiff line numberDiff line change
@@ -610,16 +610,22 @@ end
610610
@test mhe9. I(6)
611611
@test mhe9. I(2)
612612

613-
mhe10 = MovingHorizonEstimator(nonlinmodel, He=5, optim=Model(OSQP.Optimizer))
614-
@test solver_name(mhe10.optim) == "OSQP"
613+
optim = Model(Ipopt.Optimizer)
614+
covestim = ExtendedKalmanFilter(nonlinmodel, 1:2, 0, [1, 1], I_6, I_6, I_2)
615+
mhe10 = MovingHorizonEstimator(
616+
nonlinmodel, 5, 1:2, 0, [1, 1], I_6, I_6, I_2, Inf, optim, covestim
617+
)
618+
619+
mhe11 = MovingHorizonEstimator(nonlinmodel, He=5, optim=Model(OSQP.Optimizer))
620+
@test solver_name(mhe11.optim) == "OSQP"
615621

616-
mhe11 = MovingHorizonEstimator(nonlinmodel, He=5, Cwt=1e3)
617-
@test size(mhe11.Ẽ, 2) == 6*mhe11.nx̂ + 1
618-
@test mhe11.C == 1e3
622+
mhe12 = MovingHorizonEstimator(nonlinmodel, He=5, Cwt=1e3)
623+
@test size(mhe12.Ẽ, 2) == 6*mhe12.nx̂ + 1
624+
@test mhe12.C == 1e3
619625

620626
linmodel2 = LinModel{Float32}(0.5*ones(1,1), ones(1,1), ones(1,1), zeros(1,0), zeros(1,0), 1.0)
621-
mhe11 = MovingHorizonEstimator(linmodel2, He=5)
622-
@test isa(mhe11, MovingHorizonEstimator{Float32})
627+
mhe13 = MovingHorizonEstimator(linmodel2, He=5)
628+
@test isa(mhe13, MovingHorizonEstimator{Float32})
623629

624630
@test_throws ArgumentError MovingHorizonEstimator(linmodel1)
625631
@test_throws ArgumentError MovingHorizonEstimator(linmodel1, He=0)
@@ -679,6 +685,19 @@ end
679685
@test g_X̂max_end((1.0, 1.0, 1.0, 1.0)) 0.0 # test gfunc_i(i,::NTuple{N, Float64})
680686
# test gfunc_i(i,::NTuple{N, ForwardDiff.Dual}) :
681687
@test ForwardDiff.gradient(g_X̂max_end, [1.0, 1.0, 1.0, 1.0]) [0.0, 0.0, 0.0, 0.0]
688+
689+
= diagm([1/4, 1/4, 1/4, 1/4].^2)
690+
= diagm([1, 1].^2)
691+
optim = Model(Ipopt.Optimizer)
692+
covestim = ExtendedKalmanFilter(nonlinmodel, 1:2, 0, 0, Q̂, Q̂, R̂)
693+
mhe5 = MovingHorizonEstimator(nonlinmodel, 1, 1:2, 0, 0, Q̂, Q̂, R̂, Inf, optim, covestim)
694+
= updatestate!(mhe5, [10, 50], [50, 30], [5])
695+
@test zeros(4) atol=1e-9
696+
@test mhe5. zeros(4) atol=1e-9
697+
@test evaloutput(mhe5, [5]) mhe5([5]) [50, 30]
698+
info = getinfo(mhe5)
699+
@test info[:x̂] x̂ atol=1e-9
700+
@test info[:Ŷ][end-1:end] [50, 30] atol=1e-9
682701
end
683702

684703
@testset "MovingHorizonEstimator set constraints" begin

0 commit comments

Comments
 (0)