@@ -564,7 +564,10 @@ function validate_args(mpc::PredictiveController, ry, d, D̂, R̂y, R̂u)
564564end
565565
566566@doc raw """
567- init_quadprog(model::LinModel, weights::ControllerWeights, Ẽ, P̃Δu, P̃u) -> H̃
567+ init_quadprog(
568+ model::LinModel, transcriptions::TranscriptionMethod, weights::ControllerWeights,
569+ Ẽ, P̃Δu, P̃u; warn_cond=1e6
570+ ) -> H̃
568571
569572Init the quadratic programming Hessian `H̃` for MPC.
570573
@@ -582,19 +585,43 @@ in which ``\mathbf{Ẽ}``, ``\mathbf{P̃_{Δu}}`` and ``\mathbf{P̃_{u}}`` matri
582585at [`relaxŶ`](@ref), [`relaxΔU`](@ref) and [`relaxU`](@ref) documentation, respectively. The
583586vector ``\m athbf{q̃}`` and scalar ``r`` need recalculation each control period ``k``, see
584587[`initpred!`](@ref). ``r`` does not impact the minima position. It is thus useless at
585- optimization but required to evaluate the minimal ``J`` value.
588+ optimization but required to evaluate the minimal ``J`` value. A `@warn` will be displayed
589+ if the condition number `cond(H̃) ≥ warn_cond` and `transcription` is a `SingleShooting`
590+ (`warn_cond=Inf` for no warning).
586591"""
587- function init_quadprog (:: LinModel , weights:: ControllerWeights , Ẽ, P̃Δu, P̃u)
592+ function init_quadprog (
593+ :: LinModel , transcription:: TranscriptionMethod , weights:: ControllerWeights ,
594+ Ẽ, P̃Δu, P̃u; warn_cond= 1e6
595+ )
588596 M_Hp, Ñ_Hc, L_Hp = weights. M_Hp, weights. Ñ_Hc, weights. L_Hp
589597 H̃ = Hermitian (2 * (Ẽ' * M_Hp* Ẽ + P̃Δu' * Ñ_Hc* P̃Δu + P̃u' * L_Hp* P̃u), :L )
598+ verify_cond (transcription, H̃, warn_cond)
590599 return H̃
591600end
592601" Return empty matrix if `model` is not a [`LinModel`](@ref)."
593- function init_quadprog (:: SimModel{NT} , weights:: ControllerWeights , _, _, _) where {NT<: Real }
602+ function init_quadprog (
603+ :: SimModel{NT} , :: TranscriptionMethod , :: ControllerWeights , args... ; kwargs...
604+ ) where {NT<: Real }
594605 H̃ = Hermitian (zeros (NT, 0 , 0 ), :L )
595606 return H̃
596607end
597608
609+ " Check the condition number of `H̃` and display a `@warn` if `cond(H̃) > warn_cond`."
610+ function verify_cond (:: SingleShooting , H̃, warn_cond)
611+ if ! isinf (warn_cond)
612+ cond_H̃ = cond (H̃)
613+ cond_H̃ > warn_cond && @warn (
614+ " The Hessian condition number cond_H̃ > $warn_cond . The optimization " *
615+ " problem may be ill-conditioned.\n Consider changing the tunings, using " *
616+ " MultipleShooting, or using an optimizer more robust to this like DAQP." ,
617+ cond_H̃,
618+ )
619+ end
620+ return nothing
621+ end
622+ " No check if `transcription` is not a `SingleShooting`."
623+ verify_cond (:: TranscriptionMethod ,_,_) = nothing
624+
598625"""
599626 init_defaultcon_mpc(
600627 estim::StateEstimator,
0 commit comments