Skip to content

Commit

Permalink
debug: only update objective linear coef before solving LinMPC
Browse files Browse the repository at this point in the history
  • Loading branch information
franckgaga committed Aug 10, 2023
1 parent 36618eb commit 61ab8a9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions docs/src/public/predictive_control.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ over the prediction horizon ``H_p`` are defined as:
\end{bmatrix} \: , \quad
\mathbf{Ŷ} = \begin{bmatrix}
\mathbf{ŷ}(k+1) \\ \mathbf{ŷ}(k+2) \\ \vdots \\ \mathbf{ŷ}(k+H_p)
\end{bmatrix} \: \text{and} \quad
\end{bmatrix} \quad \text{and} \quad
\mathbf{R̂_y} = \begin{bmatrix}
\mathbf{r̂_y}(k+1) \\ \mathbf{r̂_y}(k+2) \\ \vdots \\ \mathbf{r̂_y}(k+H_p)
\end{bmatrix}
Expand All @@ -36,7 +36,7 @@ The vectors for the manipulated input ``\mathbf{u}`` are shifted by one time ste
```math
\mathbf{U} = \begin{bmatrix}
\mathbf{u}(k+0) \\ \mathbf{u}(k+1) \\ \vdots \\ \mathbf{u}(k+H_p-1)
\end{bmatrix} \: \text{and} \quad
\end{bmatrix} \quad \text{and} \quad
\mathbf{R̂_u} = \begin{bmatrix}
\mathbf{r_u} \\ \mathbf{r_u} \\ \vdots \\ \mathbf{r_u}
\end{bmatrix}
Expand Down
2 changes: 1 addition & 1 deletion example/juMPC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Preferences
set_preferences!(ModelPredictiveControl, "precompile_workload" => false; force=true)


#using JuMP, DAQP
using JuMP, DAQP
#using JuMP, HiGHS
using JuMP, Ipopt
using LinearAlgebra
Expand Down
6 changes: 3 additions & 3 deletions src/controller/linmpc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ function init_optimization!(mpc::LinMPC)
return nothing
end

"Set quadratic programming `q̃` vector just before optimization."
function set_objective!(mpc::LinMPC, ΔŨ)
set_objective_function(mpc.optim, obj_quadprog(ΔŨ, mpc.P̃, mpc.q̃))
"For [`LinMPC`](@ref), set the QP linear coefficient `q̃` just before optimization."
function set_objective_linear_coef!(mpc::LinMPC, ΔŨvar)
set_objective_coefficient.(mpc.optim, ΔŨvar, mpc.)
return nothing
end
26 changes: 13 additions & 13 deletions src/predictive_control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -525,18 +525,18 @@ function optim_objective!(mpc::PredictiveController)
# if soft constraints, append the last slack value ϵ_{k-1}:
!isinf(mpc.C) && (ΔŨ0 = [ΔŨ0; lastΔŨ[end]])
set_start_value.(ΔŨvar, ΔŨ0)
set_objective!(mpc, ΔŨvar)
#try
set_objective_linear_coef!(mpc, ΔŨvar)
try
optimize!(optim)
#catch err
# if isa(err, MOI.UnsupportedAttribute{MOI.VariablePrimalStart})
# # reset_optimizer to unset warm-start, set_start_value.(nothing) seems buggy
# MOIU.reset_optimizer(optim)
# optimize!(optim)
# else
# rethrow(err)
# end
#end
catch err
if isa(err, MOI.UnsupportedAttribute{MOI.VariablePrimalStart})
# reset_optimizer to unset warm-start, set_start_value.(nothing) seems buggy
MOIU.reset_optimizer(optim)
optimize!(optim)
else
rethrow(err)
end
end
status = termination_status(optim)
if !(status == OPTIMAL || status == LOCALLY_SOLVED)
@warn "MPC termination status not OPTIMAL or LOCALLY_SOLVED ($status)"
Expand All @@ -546,8 +546,8 @@ function optim_objective!(mpc::PredictiveController)
return mpc.ΔŨ
end

"By default, no change to the objective function."
set_objective!(::PredictiveController, _ ) = nothing
"By default, no need to modify the objective function."
set_objective_linear_coef!(::PredictiveController, _ ) = nothing

@doc raw"""
init_ΔUtoU(nu, Hp, Hc, C, c_Umin, c_Umax)
Expand Down

0 comments on commit 61ab8a9

Please sign in to comment.