Skip to content

Commit de25b56

Browse files
committed
debug MHE setconstraint!
1 parent 0be344b commit de25b56

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/controller/execute.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,33 +581,36 @@ function setmodel!(
581581
nu, ny, Hp, Hc, nϵ = model.nu, model.ny, mpc.Hp, mpc.Hc, mpc.
582582
setmodel!(mpc.estim, model; kwargs...)
583583
if isnothing(M_Hp) && !isnothing(Mwt)
584-
size(Mwt) == (ny,) || throw(ArgumentError("Mwt should be a vector of length ny"))
584+
size(Mwt) == (ny,) || throw(ArgumentError("Mwt should be a vector of length $ny"))
585585
any(x -> x < 0, Mwt) && throw(ArgumentError("Mwt values should be nonnegative"))
586586
for i=1:ny*Hp
587587
mpc.M_Hp[i, i] = Mwt[(i-1) % ny + 1]
588588
end
589589
elseif !isnothing(M_Hp)
590-
size(M_Hp) == (ny*Hp, ny*Hp) || throw(ArgumentError("M_Hp size should be (ny*Hp, ny*Hp)"))
590+
nŶ = ny*Hp
591+
size(M_Hp) == (nŶ, nŶ) || throw(ArgumentError("M_Hp size should be ($nŶ, $nŶ)"))
591592
mpc.M_Hp .= to_hermitian(M_Hp)
592593
end
593594
if isnothing(Ñ_Hc) && !isnothing(Nwt)
594-
size(Nwt) == (nu,) || throw(ArgumentError("Nwt should be a vector of length nu"))
595+
size(Nwt) == (nu,) || throw(ArgumentError("Nwt should be a vector of length $nu"))
595596
any(x -> x < 0, Nwt) && throw(ArgumentError("Nwt values should be nonnegative"))
596597
for i=1:nu*Hc
597598
mpc.Ñ_Hc[i, i] = Nwt[(i-1) % nu + 1]
598599
end
599600
elseif !isnothing(Ñ_Hc)
600-
size(Ñ_Hc) == (nu*Hc+nϵ, nu*Hc+nϵ) || throw(ArgumentError("Ñ_Hc size should be (nu*Hc+nϵ, nu*Hc+nϵ)"))
601+
nΔŨ = nu*Hc+
602+
size(Ñ_Hc) == (nΔŨ, nΔŨ) || throw(ArgumentError("Ñ_Hc size should be ($nΔŨ, $nΔŨ)"))
601603
mpc.Ñ_Hc .= to_hermitian(Ñ_Hc)
602604
end
603605
if isnothing(L_Hp) && !isnothing(Lwt)
604-
size(Lwt) == (nu,) || throw(ArgumentError("Lwt should be a vector of length nu"))
606+
size(Lwt) == (nu,) || throw(ArgumentError("Lwt should be a vector of length $nu"))
605607
any(x -> x < 0, Lwt) && throw(ArgumentError("Lwt values should be nonnegative"))
606608
for i=1:nu*Hp
607609
mpc.L_Hp[i, i] = Lwt[(i-1) % nu + 1]
608610
end
609611
elseif !isnothing(L_Hp)
610-
size(L_Hp) == (nu*Hp, nu*Hp) || throw(ArgumentError("L_Hp size should be (nu*Hp, nu*Hp)"))
612+
nU = nu*Hp
613+
size(L_Hp) == (nU, nU) || throw(ArgumentError("L_Hp size should be ($nU, $nU)"))
611614
mpc.L_Hp .= to_hermitian(L_Hp)
612615
end
613616
setmodel_controller!(mpc, x̂op_old, M_Hp, Ñ_Hc, L_Hp)

src/estimator/mhe/construct.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ function setconstraint!(
466466
con.X̂0max .= @views X̂max[nx̂+1:end] .- estim.X̂op
467467
end
468468
if isnothing(Ŵmin) && !isnothing(ŵmin)
469-
size(ŵmin) == (nŵ*He,) || throw(ArgumentError("ŵmin size must be $((nŵ*He,))"))
469+
size(ŵmin) == (nŵ,) || throw(ArgumentError("ŵmin size must be $((nŵ,))"))
470470
for i in 1:nŵ*He
471471
con.Ŵmin[i] = ŵmin[(i-1) % nŵ + 1]
472472
end
@@ -475,7 +475,7 @@ function setconstraint!(
475475
con.Ŵmin .= Ŵmin
476476
end
477477
if isnothing(Ŵmax) && !isnothing(ŵmax)
478-
size(ŵmax) == (nŵ*He,) || throw(ArgumentError("ŵmax size must be $((nŵ*He,))"))
478+
size(ŵmax) == (nŵ,) || throw(ArgumentError("ŵmax size must be $((nŵ,))"))
479479
for i in 1:nŵ*He
480480
con.Ŵmax[i] = ŵmax[(i-1) % nŵ + 1]
481481
end
@@ -484,7 +484,7 @@ function setconstraint!(
484484
con.Ŵmax .= Ŵmax
485485
end
486486
if isnothing(V̂min) && !isnothing(v̂min)
487-
size(v̂min) == (nym*He,) || throw(ArgumentError("v̂min size must be $((nym*He,))"))
487+
size(v̂min) == (nym,) || throw(ArgumentError("v̂min size must be $((nym,))"))
488488
for i in 1:nym*He
489489
con.V̂min[i] = v̂min[(i-1) % nym + 1]
490490
end
@@ -493,7 +493,7 @@ function setconstraint!(
493493
con.V̂min .= V̂min
494494
end
495495
if isnothing(V̂max) && !isnothing(v̂max)
496-
size(v̂max) == (nym*He,) || throw(ArgumentError("v̂max size must be $((nym*He,))"))
496+
size(v̂max) == (nym,) || throw(ArgumentError("v̂max size must be $((nym,))"))
497497
for i in 1:nym*He
498498
con.V̂max[i] = v̂max[(i-1) % nym + 1]
499499
end

0 commit comments

Comments
 (0)