Skip to content

Commit 0b11288

Browse files
committed
debug: correct cache handling in MovingHorizonEstimator and NonLinMPC
1 parent 24a5afc commit 0b11288

2 files changed

Lines changed: 18 additions & 19 deletions

File tree

src/controller/nonlinmpc.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,9 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
583583
)
584584
∇J_prep = prepare_gradient(Jfunc!, grad, Z̃_∇J, ∇J_context...; strict)
585585
∇J = Vector{JNT}(undef, nZ̃)
586-
function update_objective!(J, ∇J, , Z̃arg)
587-
if isdifferent(Z̃arg, )
588-
.= Z̃arg
586+
function update_objective!(J, ∇J, Z̃_∇J, Z̃arg)
587+
if isdifferent(Z̃arg, Z̃_∇J)
588+
Z̃_∇J .= Z̃arg
589589
J[], _ = value_and_gradient!(Jfunc!, ∇J, ∇J_prep, grad, Z̃_∇J, ∇J_context...)
590590
end
591591
end
@@ -620,10 +620,10 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
620620
∇g_prep = prepare_jacobian(gfunc!, g, jac, Z̃_∇g, ∇g_context...; strict)
621621
mpc.con.i_g[1:end-nc] .= false
622622
∇g = init_diffmat(JNT, jac, ∇g_prep, nZ̃, ng)
623-
function update_con!(g, ∇g, , Z̃arg)
624-
if isdifferent(Z̃arg, )
625-
.= Z̃arg
626-
value_and_jacobian!(gfunc!, g, ∇g, ∇g_prep, jac, , ∇g_context...)
623+
function update_con!(g, ∇g, Z̃_∇g, Z̃arg)
624+
if isdifferent(Z̃arg, Z̃_∇g)
625+
Z̃_∇g .= Z̃arg
626+
value_and_jacobian!(gfunc!, g, ∇g, ∇g_prep, jac, Z̃_∇g, ∇g_context...)
627627
end
628628
end
629629
gfuncs = Vector{Function}(undef, ng)
@@ -662,10 +662,10 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
662662
)
663663
∇geq_prep = prepare_jacobian(geqfunc!, geq, jac, Z̃_∇geq, ∇geq_context...; strict)
664664
∇geq = init_diffmat(JNT, jac, ∇geq_prep, nZ̃, neq)
665-
function update_con_eq!(geq, ∇geq, , Z̃arg)
666-
if isdifferent(Z̃arg, )
667-
.= Z̃arg
668-
value_and_jacobian!(geqfunc!, geq, ∇geq, ∇geq_prep, jac, , ∇geq_context...)
665+
function update_con_eq!(geq, ∇geq, Z̃_∇geq, Z̃arg)
666+
if isdifferent(Z̃arg, Z̃_∇geq)
667+
Z̃_∇geq .= Z̃arg
668+
value_and_jacobian!(geqfunc!, geq, ∇geq, ∇geq_prep, jac, Z̃_∇geq, ∇geq_context...)
669669
end
670670
end
671671
geqfuncs = Vector{Function}(undef, neq)

src/estimator/mhe/construct.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,15 +1356,14 @@ function get_optim_functions(
13561356
∇J_prep = prepare_gradient(Jfunc!, grad, Z̃_∇J, ∇J_context...; strict)
13571357
estim.Nk[] = 0
13581358
∇J = Vector{JNT}(undef, nZ̃)
1359-
function update_objective!(J, ∇J, , Z̃arg)
1360-
if isdifferent(Z̃arg, )
1361-
.= Z̃arg
1359+
function update_objective!(J, ∇J, Z̃_∇J, Z̃arg)
1360+
if isdifferent(Z̃arg, Z̃_∇J)
1361+
Z̃_∇J .= Z̃arg
13621362
J[], _ = value_and_gradient!(Jfunc!, ∇J, ∇J_prep, grad, Z̃_∇J, ∇J_context...)
13631363
end
13641364
end
13651365
function Jfunc(Z̃arg::Vararg{T, N}) where {N, T<:Real}
13661366
update_objective!(J, ∇J, Z̃_∇J, Z̃arg)
1367-
@show J
13681367
return J[]::T
13691368
end
13701369
∇Jfunc! = function (∇Jarg::AbstractVector{T}, Z̃arg::Vararg{T, N}) where {N, T<:Real}
@@ -1388,10 +1387,10 @@ function get_optim_functions(
13881387
estim.con.i_g .= false
13891388
estim.Nk[] = 0
13901389
∇g = init_diffmat(JNT, jac, ∇g_prep, nZ̃, ng)
1391-
function update_con!(g, ∇g, , Z̃arg)
1392-
if isdifferent(Z̃arg, )
1393-
.= Z̃arg
1394-
value_and_jacobian!(gfunc!, g, ∇g, ∇g_prep, jac, , ∇g_context...)
1390+
function update_con!(g, ∇g, Z̃_∇g, Z̃arg)
1391+
if isdifferent(Z̃arg, Z̃_∇g)
1392+
Z̃_∇g .= Z̃arg
1393+
value_and_jacobian!(gfunc!, g, ∇g, ∇g_prep, jac, Z̃_∇g, ∇g_context...)
13951394
end
13961395
end
13971396
gfuncs = Vector{Function}(undef, ng)

0 commit comments

Comments
 (0)