Skip to content

Commit 10999f2

Browse files
committed
debug: prefilling Û0 to avoid race condition
1 parent b270e14 commit 10999f2

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/controller/transcription.jl

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,10 +1374,11 @@ function con_nonlinprogeq!(
13741374
nk = get_nk(model, transcription)
13751375
D̂0 = mpc.D̂0
13761376
X̂0_Z̃ = @views Z̃[(nΔU+1):(nΔU+nX̂)]
1377-
# prefilling Û0 to avoid race-condition:
1378-
# TODO: do the same in orthogonoal collocation and I will be able to interpolate
1379-
1380-
1377+
for j=0:Hp-1 # prefilling Û0 to avoid race-condition (both û0 and ûnext are needed):
1378+
x̂0_Z̃ = @views j < 1 ? mpc.estim.x̂0[1:nx̂] : X̂0_Z̃[(1 + nx̂*(j-1)):(nx̂*j)]
1379+
u0, û0 = @views U0[(1 + nu*j):(nu*(j+1))], Û0[(1 + nu*j):(nu*(j+1))]
1380+
f̂_input!(û0, mpc.estim, model, x̂0_Z̃, u0)
1381+
end
13811382
@threadsif f_threads for j=1:Hp
13821383
if j < 2
13831384
x̂0_Z̃ = @views mpc.estim.x̂0[1:nx̂]
@@ -1401,24 +1402,15 @@ function con_nonlinprogeq!(
14011402
fs!(x̂0next, mpc.estim, model, x̂0_Z̃)
14021403
ssnext .= @. xsnext - xsnext_Z̃
14031404
# ----------------- deterministic defects: trapezoidal collocation -------------
1404-
u0 = @views U0[(1 + nu*(j-1)):(nu*j)]
1405-
û0 = @views Û0[(1 + nu*(j-1)):(nu*j)]
1406-
f̂_input!(û0, mpc.estim, model, x̂0_Z̃, u0)
1405+
û0 = @views Û0[(1 + nu*(j-1)):(nu*j)]
1406+
û0next = @views h < 1 || j Hp ? û0 : Û0[(1 + nu*j):(nu*(j+1))]
14071407
if f_threads || h < 1 || j < 2
14081408
# we need to recompute k1 with multi-threading, even with h==1, since the
14091409
# last iteration (j-1) may not be executed (iterations are re-orderable)
14101410
model.f!(k̇1, x0_Z̃, û0, d̂0, p)
14111411
else
14121412
k̇1 .= @views K̇[(1 + nk*(j-1)-nx):(nk*(j-1))] # k2 of of the last iter. j-1
14131413
end
1414-
if h < 1 || j Hp
1415-
# j = Hp special case: u(k+Hp-1) = u(k+Hp) since Hc ≤ Hp implies Δu(k+Hp) = 0
1416-
û0next = û0
1417-
else
1418-
u0next = @views U0[(1 + nu*j):(nu*(j+1))]
1419-
û0next = @views Û0[(1 + nu*j):(nu*(j+1))]
1420-
f̂_input!(û0next, mpc.estim, model, x̂0next_Z̃, u0next)
1421-
end
14221414
model.f!(k̇2, x0next_Z̃, û0next, d̂0next, p)
14231415
sdnext .= @. x0_Z̃ - x0next_Z̃ + 0.5*Ts*(k̇1 + k̇2)
14241416
end

0 commit comments

Comments
 (0)