diff --git a/docs/src/public/predictive_control.md b/docs/src/public/predictive_control.md index ed85b05a..994cfc4c 100644 --- a/docs/src/public/predictive_control.md +++ b/docs/src/public/predictive_control.md @@ -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} @@ -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} diff --git a/example/juMPC.jl b/example/juMPC.jl index 85f533b0..348ffa28 100644 --- a/example/juMPC.jl +++ b/example/juMPC.jl @@ -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 diff --git a/src/controller/linmpc.jl b/src/controller/linmpc.jl index f8f56cc4..98f0319b 100644 --- a/src/controller/linmpc.jl +++ b/src/controller/linmpc.jl @@ -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.q̃) return nothing end diff --git a/src/predictive_control.jl b/src/predictive_control.jl index 8f96b280..cf5bd1f9 100644 --- a/src/predictive_control.jl +++ b/src/predictive_control.jl @@ -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)" @@ -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)