Skip to content

Commit 34a1f13

Browse files
authored
Merge pull request #502 from JuliaControl/mhe_ss_debug
debug: use the most recent `d` in `MovingHorizonEstimator` with `SingleShooting`
2 parents 22e6d84 + 9ccd5fc commit 34a1f13

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

‎Project.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ModelPredictiveControl"
22
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
3-
version = "2.16.0"
3+
version = "2.16.1"
44
authors = ["Francis Gagnon"]
55

66
[deps]

‎src/estimator/mhe/transcription.jl‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,18 +1517,22 @@ function predict_mhe!(
15171517
i_d0arr = estim.direct ? 0 : nd # the first nd elements in D0 are useless if p=1
15181518
x̂0 = @views x̂0arr[1:nx̂]
15191519
for j=1:Nk
1520-
u0 = @views estim.U0[(1+nu*(j-1)):(nu*j)]
1521-
d0 = @views estim.D0[(1+nd*(j-1) + i_d0arr):(nd*j + i_d0arr)]
1522-
ŵ = @views Ŵ[(1+nŵ*(j-1)):(nŵ*j)]
1523-
k̄ = @views K̄[(1+nk̄*(j-1)):(nk̄*j)]
1524-
û0 = @views Û0[(1+nu*(j-1)):(nu*j)]
1525-
ûi = @views Ûi[(1 + nu*(j-1)):(nu*j)]
1526-
di = @views Di[(1 + nd*(j-1)):(nd*j)]
1527-
x̂0next = @views X̂0[(1+nx̂*(j-1)):(nx̂*j)]
1528-
d0next = @views (j < Nk) ? estim.D0[(1+nd*j + i_d0arr):(nd*(j+1) + i_d0arr)] : d0
1520+
u0 = @views estim.U0[(1+nu*(j-1)):(nu*j)]
1521+
d0 = @views estim.D0[(1+nd*(j-1) + i_d0arr):(nd*j + i_d0arr)]
1522+
ŵ = @views Ŵ[(1+nŵ*(j-1)):(nŵ*j)]
1523+
k̄ = @views K̄[(1+nk̄*(j-1)):(nk̄*j)]
1524+
û0 = @views Û0[(1+nu*(j-1)):(nu*j)]
1525+
ûi = @views Ûi[(1 + nu*(j-1)):(nu*j)]
1526+
di = @views Di[(1 + nd*(j-1)):(nd*j)]
1527+
x̂0next = @views X̂0[(1+nx̂*(j-1)):(nx̂*j)]
1528+
if estim.direct || j < Nk # d0(k+1) is never needed if estim.direct
1529+
d0next = @views estim.D0[(1+nd*j + i_d0arr):(nd*(j+1) + i_d0arr)]
1530+
else # special case, d0(k+1)≈d0(k), since d0(k+1) is not available at time k:
1531+
d0next = d0
1532+
end
15291533
if h > 0 && j < Nk
1530-
u0next = estim.U0[(1+nu*j):(nu*(j+1))]
1531-
else
1534+
u0next = @views estim.U0[(1+nu*j):(nu*(j+1))]
1535+
else # special case, û0(k+p)≈û0(k+p-1), since û0(k+p) is not available at time k:
15321536
u0next = u0
15331537
end
15341538
û0next = @views j < Nk ? Û0[(1+nu*j):(nu*(j+1))] : Û0[1:nu]

‎test/2_test_state_estim.jl‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,10 +1379,14 @@ end
13791379
model = NonLinModel(f!, h!, 100.0, 1, 1, 1, 1; p)
13801380
transcription = SingleShooting(1)
13811381
mhe_foh = MovingHorizonEstimator(model; He=3, transcription)
1382-
preparestate!(mhe_foh, [0.0], [0.0])
1383-
x̂ = updatestate!(mhe_foh, [1.0], [0.0], [0.0])
1384-
info = getinfo(mhe_foh)
13851382
@test mhe_foh.transcription.h == 1
1383+
for i in 1:50
1384+
preparestate!(mhe_foh, [1.5], [0.0])
1385+
updatestate!(mhe_foh, [0.0], [1.5], [0.0])
1386+
end
1387+
x̂ = preparestate!(mhe_foh, [1.5], [0.0])
1388+
@test mhe_foh([0.0]) ≈ [1.5]
1389+
info = getinfo(mhe_foh)
13861390
@test info[:x̂] ≈ x̂
13871391
end
13881392

0 commit comments

Comments
 (0)