Skip to content

Commit 279c38d

Browse files
committed
test: improving coverage of algebraic variable bounds
1 parent 6023e56 commit 279c38d

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

‎test/2_test_state_estim.jl‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,61 @@ end
20072007
@test getinfo(mhe2)[:Ŵ] ≈ zeros(nx̂) atol=5e-2
20082008
end
20092009

2010+
@testitem "MHE constraint violation (NonLinModelDAE)" setup=[SetupMPCtests] begin
2011+
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
2012+
2013+
function fq!(ẋ, res, x, a, u, d, p)
2014+
ẋ[] = -p[] * (x[] - 0.2 * u[] - 0.2 * d[])
2015+
res[] = x[] - a[]
2016+
return nothing
2017+
end
2018+
function h!(y, x, a, d, _ )
2019+
y[] = 2 * x[] + a[] + 0.1 * d[]
2020+
end
2021+
p = [0.001]
2022+
as_0, xs_0 = [-1.0], [1.0]
2023+
dae = NonLinModelDAE(fq!, h!, 1000.0, 1, 1, 1, 1, 1; p, xs_0, as_0)
2024+
#=
2025+
transcription = TrapezoidalCollocation()
2026+
mhe2 = MovingHorizonEstimator(dae, He=1, nint_ym=0; transcription)
2027+
2028+
setconstraint!(mhe2, âmin=[1], âmax=[100])
2029+
preparestate!(mhe2, [0.0], [0.0])
2030+
updatestate!(mhe2, [10.0], [0.0], [0.0])
2031+
2032+
info = getinfo(mhe2)
2033+
@test info[:â] ≈ [1.0] atol=5e-2
2034+
2035+
setconstraint!(mhe2, âmin=[-100], âmax=[-1])
2036+
preparestate!(mhe2, [0.0], [0.0])
2037+
updatestate!(mhe2, [10.0], [0.0], [0.0])
2038+
2039+
info = getinfo(mhe2)
2040+
@test info[:â] ≈ [-1.0] atol=5e-2
2041+
=#
2042+
transcription = TrapezoidalCollocation()#OrthogonalCollocation(0, 2, roots=:gausslegendre)
2043+
mhe3 = MovingHorizonEstimator(dae; He=1, nint_ym=0, Cwt=1e4, transcription)
2044+
2045+
setconstraint!(mhe3, c_âmin=[1], c_âmax=[1])
2046+
2047+
setconstraint!(mhe3, âmin=[1], âmax=[100])
2048+
preparestate!(mhe3, [0.0], [0.0])
2049+
updatestate!(mhe3, [10.0], [0.0], [0.0])
2050+
2051+
info = getinfo(mhe3)
2052+
@show info[:ε]
2053+
@test info[:â] ≈ [1.0] atol=5e-2
2054+
2055+
setconstraint!(mhe3, âmin=[-100], âmax=[-1])
2056+
preparestate!(mhe3, [0.0], [0.0])
2057+
updatestate!(mhe3, [10.0], [0.0], [0.0])
2058+
2059+
info = getinfo(mhe3)
2060+
@show info[:ε]
2061+
@test info[:â] ≈ [-1.0] atol=5e-2
2062+
2063+
end
2064+
20102065
@testitem "MHE set model" setup=[SetupMPCtests] begin
20112066
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
20122067
linmodel = LinModel([0.5], [0.3], [1.0], 0, 0, 10.0)

0 commit comments

Comments
 (0)