Skip to content

Commit 2cfe593

Browse files
committed
test: new SingleShooting tests for setmodel!(mhe)
1 parent 3a48ec2 commit 2cfe593

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

‎test/2_test_state_estim.jl‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,15 +1677,19 @@ end
16771677
@test mhe.cov.R̂ ≈ [1e-6]
16781678
@test mhe.cov.invR̂_He ≈ diagm(repeat([1e6], He))
16791679

1680-
f(x,u,d,model) = model.A*x + model.Bu*u + model.Bd*d
1681-
h(x,d,model) = model.C*x + model.Du*d
1682-
nonlinmodel = NonLinModel(f, h, 10.0, 1, 1, 1, p=linmodel, solver=nothing)
1683-
mhe2 = MovingHorizonEstimator(nonlinmodel; He, nint_ym=0)
1684-
setmodel!(mhe2, Q̂=[1e-3], R̂=[1e-6])
1685-
@test mhe2.cov.Q̂ ≈ [1e-3]
1686-
@test mhe2.cov.invQ̂_He ≈ diagm(repeat([1e3], He))
1687-
@test mhe2.cov.R̂ ≈ [1e-6]
1688-
@test mhe2.cov.invR̂_He ≈ diagm(repeat([1e6], He))
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
16891693

16901694
linmodel = LinModel([0.5], [0.3], [1.0], 0, 0, 10.0)
16911695
linmodel = setop!(linmodel, uop=[2.0], yop=[50.0], xop=[3.0], fop=[3.0])
@@ -1700,10 +1704,20 @@ end
17001704
initstate!(mhe3, [3.0], [55.0])
17011705
x̂ = updatestate!(mhe3, [3.0 + 1.0], [55.0])
17021706
@test x̂ ≈ [8.0 + 0.9] atol=1e-3
1707+
1708+
f(x,u,d,model) = model.A*x + model.Bu*u + model.Bd*d
1709+
h(x,d,model) = model.C*x + model.Du*d
1710+
nonlinmodel = NonLinModel(f, h, 10.0, 1, 1, 1, p=linmodel, solver=nothing)
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))
17031717

1704-
@test_throws ErrorException setmodel!(mhe2, deepcopy(nonlinmodel))
1718+
@test_throws ErrorException setmodel!(mhe5, deepcopy(nonlinmodel))
17051719
@test_throws ErrorException setmodel!(mhe, Q̂=diagm([-0.1]))
1706-
@test_throws ErrorException setmodel!(mhe, R̂=diagm([-0.1]))=#
1720+
@test_throws ErrorException setmodel!(mhe, R̂=diagm([-0.1]))
17071721

17081722
end
17091723

0 commit comments

Comments
 (0)