Skip to content

Commit 89200e5

Browse files
committed
debug: MHE getinfo now works
1 parent f472910 commit 89200e5

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/estimator/mhe/execute.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ function getinfo(estim::MovingHorizonEstimator{NT}) where NT<:Real
132132
nx̃ = !isinf(estim.C) + nx̂
133133
MyTypes = Union{JuMP._SolutionSummary, Hermitian{NT, Matrix{NT}}, Vector{NT}, NT}
134134
info = Dict{Symbol, MyTypes}()
135-
V̂, X̂0 = similar(estim.Y0m[1:nym*Nk]), similar(estim.X̂0[1:nx̂*Nk])
135+
V̂, X̂0 = similar(estim.Y0m[1:nym*Nk]), similar(estim.X̂0[1:nx̂*Nk])
136136
û0, ŷ0 = similar(model.uop), similar(model.yop)
137-
V̂, X̂0 = predict!(V̂, X̂0, û0, ŷ0, estim, model, estim.Z̃)
137+
V̂, X̂0 = predict!(V̂, X̂0, û0, ŷ0, estim, model, estim.Z̃)
138138
x̂0arr = @views estim.Z̃[nx̃-nx̂+1:nx̃]
139139
= estim.x̂0arr_old - x̂0arr
140140
X̂0 = [x̂0arr; X̂0]
@@ -158,8 +158,8 @@ function getinfo(estim::MovingHorizonEstimator{NT}) where NT<:Real
158158
info[:x̂arr] = x̂0arr + estim.x̂op
159159
info[] = isinf(estim.C) ? NaN : estim.Z̃[begin]
160160
info[:J] = obj_nonlinprog!(x̄, estim, estim.model, V̂, estim.Z̃)
161-
info[:X̂] = X̂0 + [estim.x̂op; estim.X̂op]
162-
info[:x̂] = estim.x̂0 + estim.x̂op
161+
info[:X̂] = X̂0 .+ @views [estim.x̂op; estim.X̂op[1:nx̂*Nk]]
162+
info[:x̂] = estim.x̂0 .+ estim.x̂op
163163
info[:V̂] =
164164
info[:P̄] = estim.P̂arr_old
165165
info[:x̄] =

test/test_state_estim.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,10 @@ end
646646

647647
mhe7 = MovingHorizonEstimator(nonlinmodel, He=10)
648648
@test mhe7.He == 10
649-
@test length(mhe7.) == 10*6
650-
@test length(mhe7.Ym) == 10*2
651-
@test length(mhe7.U) == 10*2
652-
@test length(mhe7.D) == 10*1
649+
@test length(mhe7.X̂0) == 10*6
650+
@test length(mhe7.Y0m) == 10*2
651+
@test length(mhe7.U0) == 10*2
652+
@test length(mhe7.D0) == 10*1
653653
@test length(mhe7.Ŵ) == 10*6
654654

655655
mhe8 = MovingHorizonEstimator(nonlinmodel, He=5, nint_u=[1, 1], nint_ym=[0, 0])
@@ -762,8 +762,8 @@ end
762762
linmodel1 = setop!(LinModel(sys,Ts,i_u=[1,2]), uop=[10,50], yop=[50,30])
763763
mhe1 = MovingHorizonEstimator(linmodel1, He=1, nint_ym=0, Cwt=1e3)
764764
setconstraint!(mhe1, x̂min=[-51,-52], x̂max=[53,54])
765-
@test all((mhe1.con.X̂min, mhe1.con.X̂max) .≈ ([-51,-52], [53,54]))
766-
@test all((mhe1.con.x̃min[2:end], mhe1.con.x̃max[2:end]) .≈ ([-51,-52], [53,54]))
765+
@test all((mhe1.con.X̂0min, mhe1.con.X̂0max) .≈ ([-51,-52], [53,54]))
766+
@test all((mhe1.con.x̃0min[2:end], mhe1.con.x̃0max[2:end]) .≈ ([-51,-52], [53,54]))
767767
setconstraint!(mhe1, ŵmin=[-55,-56], ŵmax=[57,58])
768768
@test all((mhe1.con.Ŵmin, mhe1.con.Ŵmax) .≈ ([-55,-56], [57,58]))
769769
setconstraint!(mhe1, v̂min=[-59,-60], v̂max=[61,62])
@@ -778,8 +778,8 @@ end
778778

779779
mhe2 = MovingHorizonEstimator(linmodel1, He=4, nint_ym=0, Cwt=1e3)
780780
setconstraint!(mhe2, X̂min=-1(1:10), X̂max=1(1:10))
781-
@test all((mhe2.con.X̂min, mhe2.con.X̂max) .≈ (-1(3:10), 1(3:10)))
782-
@test all((mhe2.con.x̃min[2:end], mhe2.con.x̃max[2:end]) .≈ (-1(1:2), 1(1:2)))
781+
@test all((mhe2.con.X̂0min, mhe2.con.X̂0max) .≈ (-1(3:10), 1(3:10)))
782+
@test all((mhe2.con.x̃0min[2:end], mhe2.con.x̃0max[2:end]) .≈ (-1(1:2), 1(1:2)))
783783
setconstraint!(mhe2, Ŵmin=-1(11:18), Ŵmax=1(11:18))
784784
@test all((mhe2.con.Ŵmin, mhe2.con.Ŵmax) .≈ (-1(11:18), 1(11:18)))
785785
setconstraint!(mhe2, V̂min=-1(31:38), V̂max=1(31:38))

0 commit comments

Comments
 (0)