Skip to content

Commit e11147f

Browse files
committed
test: new tests with modification in setstate!
1 parent ce959e4 commit e11147f

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/estimator/execute.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ end
334334
335335
Set `estim.x̂0` to `x̂ - estim.x̂op` from the argument `x̂`, and `estim.P̂` to `P̂` if applicable.
336336
337-
The covariance error estimate `P̂` can be set only if `estim` computes it.
337+
The covariance error estimate `P̂` can be set only if `estim` is a [`StateEstimator`](@ref)
338+
that computes it.
338339
"""
339340
function setstate!(estim::StateEstimator, x̂, P̂=nothing)
340341
size(x̂) == (estim.nx̂,) || error("x̂ size must be $((estim.nx̂,))")

test/2_test_state_estim.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ end
115115
@test [0, 0]
116116
@test isa(x̂, Vector{Float32})
117117
@test_throws ArgumentError updatestate!(skalmanfilter1, [10, 50])
118+
@test_throws ErrorException setstate!(skalmanfilter1, [1,2,3,4], diagm(.1:.1:.4))
118119
end
119120

120121
@testitem "SteadyKalmanFilter set model" setup=[SetupMPCtests] begin
@@ -211,8 +212,9 @@ end
211212
@test evaloutput(kalmanfilter1, d) kalmanfilter1(d) [50, 30]
212213
@test_skip @allocations(evaloutput(kalmanfilter1, d)) == 0
213214
@test initstate!(kalmanfilter1, [10, 50], [50, 30+1]) [zeros(3); [1]]
214-
setstate!(kalmanfilter1, [1,2,3,4])
215+
setstate!(kalmanfilter1, [1,2,3,4], diagm(.1:.1:.4))
215216
@test kalmanfilter1.x̂0 [1,2,3,4]
217+
@test kalmanfilter1. diagm(.1:.1:.4)
216218
for i in 1:40
217219
preparestate!(kalmanfilter1, [50, 30])
218220
updatestate!(kalmanfilter1, [11, 52], [50, 30])
@@ -363,6 +365,7 @@ end
363365
= updatestate!(lo3, [0], [0])
364366
@test [0, 0]
365367
@test isa(x̂, Vector{Float32})
368+
@test_throws ErrorException setstate!(lo1, [1,2,3,4], diagm(.1:.1:.4))
366369
end
367370

368371
@testitem "Luenberger set model" setup=[SetupMPCtests] begin
@@ -484,6 +487,7 @@ end
484487
= updatestate!(internalmodel3, [0], [0])
485488
@test [0]
486489
@test isa(x̂, Vector{Float32})
490+
@test_throws ErrorException setstate!(internalmodel1, [1,2,3,4], diagm(.1:.1:.4))
487491
end
488492

489493
@testitem "InternalModel set model" setup=[SetupMPCtests] begin
@@ -598,8 +602,9 @@ end
598602
@test evaloutput(ukf1, d) ukf1(d) [50, 30]
599603
@test_skip @allocations(evaloutput(ukf1, d)) == 0
600604
@test initstate!(ukf1, [10, 50], [50, 30+1]) zeros(4) atol=1e-9
601-
setstate!(ukf1, [1,2,3,4])
605+
setstate!(ukf1, [1,2,3,4], diagm(.1:.1:.4))
602606
@test ukf1.x̂0 [1,2,3,4]
607+
@test ukf1. diagm(.1:.1:.4)
603608
for i in 1:40
604609
preparestate!(ukf1, [50, 30])
605610
updatestate!(ukf1, [11, 52], [50, 30])
@@ -757,8 +762,9 @@ end
757762
@test evaloutput(ekf1, d) ekf1(d) [50, 30]
758763
@test_skip @allocations(evaloutput(ekf1, d)) == 0
759764
@test initstate!(ekf1, [10, 50], [50, 30+1]) zeros(4);
760-
setstate!(ekf1, [1,2,3,4])
765+
setstate!(ekf1, [1,2,3,4], diagm(.1:.1:.4))
761766
@test ekf1.x̂0 [1,2,3,4]
767+
@test ekf1. diagm(.1:.1:.4)
762768
for i in 1:40
763769
preparestate!(ekf1, [50, 30])
764770
updatestate!(ekf1, [11, 52], [50, 30])
@@ -1055,6 +1061,7 @@ end
10551061
= preparestate!(mhe6, [50, 30], [5])
10561062
@test zeros(6) atol=1e-9
10571063
@test_nowarn ModelPredictiveControl.info2debugstr(info)
1064+
@test_throws ErrorException setstate!(mhe1, [1,2,3,4,5,6], diagm(.1:.1:.6))
10581065
end
10591066

10601067
@testitem "MovingHorizonEstimator fallbacks for arrival covariance estimation" setup=[SetupMPCtests] begin

test/3_test_predictive_control.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ end
163163
@testitem "LinMPC other methods" setup=[SetupMPCtests] begin
164164
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
165165
linmodel1 = setop!(LinModel(sys,Ts,i_u=[1,2]), uop=[10,50], yop=[50,30])
166-
mpc1 = LinMPC(linmodel1)
166+
mpc1 = LinMPC(KalmanFilter(linmodel1))
167167
@test initstate!(mpc1, [10, 50], [50, 30+1]) [zeros(3); [1]]
168-
setstate!(mpc1, [1,2,3,4])
168+
setstate!(mpc1, [1,2,3,4], diagm(.1:.1:.4))
169169
@test mpc1.estim.x̂0 [1,2,3,4]
170-
setstate!(mpc1, [0,0,0,0])
170+
@test mpc1.estim. diagm(.1:.1:.4)
171+
setstate!(mpc1, [0,0,0,0], mpc1.estim.P̂_0)
171172
preparestate!(mpc1, [50, 30])
172173
updatestate!(mpc1, mpc1.estim.model.uop, [50, 30])
173174
@test mpc1.estim.x̂0 [0,0,0,0]

0 commit comments

Comments
 (0)