@@ -40,15 +40,23 @@ function Base.convert(::Type{LinearMPC.MPC}, mpc::ModelPredictiveControl.LinMPC)
4040 # ---- Constraint softening ---
4141 only_hard = weights. isinf_C
4242 if ! only_hard
43+ issoft(C) = any(x -> x > 0 , C)
44+ C_u = - mpc. con. A_Umin[:, end ]
45+ C_Δu = - mpc. con. A_ΔŨmin[1 : nΔU, end ]
46+ C_y = - mpc. con. A_Ymin[:, end ]
47+ c_x̂ = - mpc. con. A_x̂min[:, end ]
48+ if sum(mpc. con. i_b) > 1 # ignore the slack variable ϵ bound
49+ if issoft(C_u) || issoft(C_Δu) || issoft(C_y) || issoft(C_x̂)
50+ @warn " The LinearMPC conversion applies an approximate conversion " *
51+ " of the soft constraints.\n You may need to adjust the soft_weight " *
52+ " field of the LinearMPC.MPC object to replicate behaviors."
53+ end
54+ end
4355 # LinearMPC relies on a different softening mechanism (new implicit slacks for each
4456 # softened bounds), so we apply an approximate conversion factor on the Cwt weight:
4557 Cwt = weights. Ñ_Hc[end , end ]
4658 nsoft = sum((mpc. con. A[:,end ] .< 0 ) .& (mpc. con. i_b)) - 1
4759 newmpc. settings. soft_weight = 10 * sqrt(nsoft* Cwt)
48- C_u = - mpc. con. A_Umin[:, end ]
49- C_Δu = - mpc. con. A_ΔŨmin[1 : nΔU, end ]
50- C_y = - mpc. con. A_Ymin[:, end ]
51- c_x̂ = - mpc. con. A_x̂min[:, end ]
5260 else
5361 C_u = zeros(nu* Hp)
5462 C_Δu = zeros(nu* Hc)
@@ -195,14 +203,6 @@ function validate_constraints(mpc::ModelPredictiveControl.LinMPC)
195203 )
196204 error(" LinearMPC only supports identical softness parameters for lower and upper bounds." )
197205 end
198- issoft(C) = any(x -> x > 0 , C)
199- if ! mpc. weights. isinf_C && sum(mpc. con. i_b) > 1 # ignore the slack variable ϵ bound
200- if issoft(C_umin) || issoft(C_Δumin) || issoft(C_ymin) || issoft(C_x̂min)
201- @warn " The LinearMPC conversion applies an approximate conversion " *
202- " of the soft constraints.\n You may need to adjust the soft_weight " *
203- " field of the LinearMPC.MPC object to replicate behaviors."
204- end
205- end
206206 return nothing
207207end
208208
0 commit comments