Skip to content

Commit dd15601

Browse files
committed
debug: init_defectmat correct Eŝ matrix
1 parent 0f95475 commit dd15601

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

src/controller/transcription.jl

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ end
141141
init_ZtoU_Smat( _ , transcription::SingleShooting, _ , _ , Sdagger) = Sdagger
142142

143143
function init_ZtoU_Smat(estim, transcription::MultipleShooting, Hp, _ , Sdagger)
144-
return [Sdagger; zeros(eltype(Sdagger), estim.model.nu*Hp, estim.nx̂*Hp)]
144+
return [Sdagger zeros(eltype(Sdagger), estim.model.nu*Hp, estim.nx̂*Hp)]
145145
end
146146

147147
@doc raw"""
@@ -326,8 +326,10 @@ function init_predmat(
326326
nu, nx̂, ny, nd = model.nu, estim.nx̂, model.ny, model.nd
327327
# --- state estimates x̂ ---
328328
K = zeros(NT, Hp*ny, nx̂)
329+
kx̂ = zeros(NT, nx̂, nx̂)
329330
# --- manipulated inputs u ---
330331
V = zeros(NT, Hp*ny, nu)
332+
vx̂ = zeros(NT, nx̂, nu)
331333
# --- decision variables Z ---
332334
E = [zeros(NT, Hp*ny, Hc*nu) repeatdiag(Ĉ, Hp)]
333335
ex̂ = [zeros(NT, nx̂, Hc*nu + (Hp-1)*nx̂) I]
@@ -338,7 +340,7 @@ function init_predmat(
338340
jx̂ = zeros(NT, nx̂, Hp*nd)
339341
# --- state x̂op and state update f̂op operating points ---
340342
B = zeros(NT, Hp*ny, 1)
341-
bx̂ = zeros(NT, nx̂, 1)
343+
bx̂ = zeros(NT, nx̂)
342344
return E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂
343345
end
344346

@@ -377,7 +379,7 @@ function init_predmat(
377379
V = zeros(NT, 0, nu)
378380
B = zeros(NT, 0)
379381
ex̂ = [zeros(NT, nx̂, Hc*nu + (Hp-1)*nx̂) I]
380-
gx̂, jx̂, kx̂, vx̂, bx̂ = E, G, J, K, V
382+
gx̂, jx̂, kx̂, vx̂, bx̂ = E, G, J, K, V, B
381383
return E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂
382384
end
383385

@@ -423,23 +425,23 @@ matrices ``\mathbf{E_ŝ, G_ŝ, J_ŝ, K_ŝ, V_ŝ, B_ŝ}`` are defined in th
423425
```math
424426
\begin{aligned}
425427
\mathbf{E_ŝ} &= \begin{bmatrix}
426-
\mathbf{B̂_u} & \mathbf{0} & \cdots & \mathbf{0} & -\mathbf{I} & \mathbf{0} & \cdots & \mathbf{0} \\
427-
\mathbf{B̂_u} & \mathbf{B̂_u} & \cdots & \mathbf{0} & \mathbf{Â} & -\mathbf{I} & \cdots & \mathbf{0} \\
428-
\vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots \\
429-
\mathbf{B̂_u} & \mathbf{B̂_u} & \cdots & \mathbf{B̂_u} & \mathbf{0} & \mathbf{0} & \cdots & -\mathbf{I} \end{bmatrix} \\
428+
\mathbf{B̂_u} & \mathbf{0} & \cdots & \mathbf{0} & -\mathbf{I} & \mathbf{0} & \cdots & \mathbf{0} \\
429+
\mathbf{B̂_u} & \mathbf{B̂_u} & \cdots & \mathbf{0} & \mathbf{Â} & -\mathbf{I} & \cdots & \mathbf{0} \\
430+
\vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots \\
431+
\mathbf{B̂_u} & \mathbf{B̂_u} & \cdots & \mathbf{B̂_u} & \mathbf{0} & \mathbf{0} & \cdots & -\mathbf{I} \end{bmatrix} \\
430432
\mathbf{G_ŝ} &= \begin{bmatrix}
431-
\mathbf{B̂_d} \\ \mathbf{0} \\ \vdots \\ \mathbf{0} \end{bmatrix} \\
433+
\mathbf{B̂_d} \\ \mathbf{0} \\ \vdots \\ \mathbf{0} \end{bmatrix} \\
432434
\mathbf{J_ŝ} &= \begin{bmatrix}
433-
\mathbf{0} & \mathbf{0} & \cdots & \mathbf{0} & \mathbf{0} \\
434-
\mathbf{B̂_d} & \mathbf{0} & \cdots & \mathbf{0} & \mathbf{0} \\
435-
\vdots & \vdots & \ddots & \vdots & \vdots \\
436-
\mathbf{0} & \mathbf{0} & \cdots & \mathbf{B̂_d} & \mathbf{0} \end{bmatrix} \\
435+
\mathbf{0} & \mathbf{0} & \cdots & \mathbf{0} & \mathbf{0} \\
436+
\mathbf{B̂_d} & \mathbf{0} & \cdots & \mathbf{0} & \mathbf{0} \\
437+
\vdots & \vdots & \ddots & \vdots & \vdots \\
438+
\mathbf{0} & \mathbf{0} & \cdots & \mathbf{B̂_d} & \mathbf{0} \end{bmatrix} \\
437439
\mathbf{K_ŝ} &= \begin{bmatrix}
438-
\mathbf{Â} \\ \mathbf{0} \\ \vdots \\ \mathbf{0} \end{bmatrix} \\
440+
\mathbf{Â} \\ \mathbf{0} \\ \vdots \\ \mathbf{0} \end{bmatrix} \\
439441
\mathbf{V_ŝ} &= \begin{bmatrix}
440-
\mathbf{B̂_u} \\ \mathbf{B̂_u} \\ \vdots \\ \mathbf{B̂_u} \end{bmatrix} \\
442+
\mathbf{B̂_u} \\ \mathbf{B̂_u} \\ \vdots \\ \mathbf{B̂_u} \end{bmatrix} \\
441443
\mathbf{B_ŝ} &= \begin{bmatrix}
442-
\mathbf{f̂_{op} - x̂_{op}} \\ \mathbf{f̂_{op} - x̂_{op}} \\ \vdots \\ \mathbf{f̂_{op} - x̂_{op}} \end{bmatrix}
444+
\mathbf{f̂_{op} - x̂_{op}} \\ \mathbf{f̂_{op} - x̂_{op}} \\ \vdots \\ \mathbf{f̂_{op} - x̂_{op}} \end{bmatrix}
443445
\end{aligned}
444446
```
445447
"""
@@ -453,13 +455,18 @@ function init_defectmat(
453455
# --- manipulated inputs u ---
454456
Vŝ = repeat(B̂u, Hp)
455457
# --- decision variables Z ---
456-
nI_nu = Matrix{NT}(-I, nu, nu)
457-
Eŝ = [LowerTriangular(repeat(B̂u, Hc, Hc)) repeatdiag(nI_nu, Hp)]
458+
nI_nx̂ = Matrix{NT}(-I, nx̂, nx̂)
459+
Eŝ = [zeros(nx̂*Hp, nu*Hc) repeatdiag(nI_nx̂, Hp)]
460+
for j=1:Hc, i=j:Hp
461+
iRow = (1:nx̂) .+ nx̂*(i-1)
462+
iCol = (1:nu) .+ nu*(j-1)
463+
Eŝ[iRow, iCol] = B̂u
464+
end
458465
# --- measured disturbances d ---
459466
Gŝ = [B̂d; zeros(NT, (Hp-1)*nx̂, nd)]
460-
Jŝ = [zeros(NT, nx̂, Hp*nd); repeatdiag(B̂d, Hp-1) zeros(NT, (Hp-1)*nd, nd)]
467+
Jŝ = [zeros(nx̂, nd*Hp); repeatdiag(B̂d, Hp-1) zeros(NT, nx̂*(Hp-1), nd)]
461468
# --- state x̂op and state update f̂op operating points ---
462-
B̂s = repeat(estim.f̂op - estim.x̂op, Hp)
469+
Bŝ = repeat(estim.f̂op - estim.x̂op, Hp)
463470
return Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ
464471
end
465472

0 commit comments

Comments
 (0)