Slack variables for linear constraints

Hi :wave:

I am trying to introduce slack varibles for linear constraints and I am getting following error. Number of linear constraints =3, number of states =4.

Code
nsh = nh;%nh =1
% Jsh_0 = eye(0);
% Jsh = eye(nh);
% Jsbu = eye(1);
Jsg = eye(3);
% ocp_model.set('constr_Jsh_0', Jsh_0);
% ocp_model.set('constr_Jsh', Jsh);
% ocp_model.set('constr_Jsbu', Jsbu);
ocp_model.set('constr_Jsg', Jsg);
% Set cost on slack
% L1 slack (linear term)
ocp_model.set('cost_zl_0', 100 * ones(3,1));
ocp_model.set('cost_zu_0', 100 * ones(3,1));
% % % L2 slack (squared term)
ocp_model.set('cost_Zl_0', 1*eye(3));
ocp_model.set('cost_Zu_0', 1*eye(3));

% L1 slack (linear term)
ocp_model.set('cost_zl', 100 * ones(3,1));
ocp_model.set('cost_zu', 100 * ones(3,1));
% % L2 slack (squared term)
ocp_model.set('cost_Zl', 1*eye(3));
ocp_model.set('cost_Zu', 1*eye(3));

interface output.

>> solver
Warning: codgen_model is deprecated and has no effect. 
> In acados_ocp_opts/set (line 131)
In solver (line 164) 
Warning: acados_ocp will be deprecated in the future. Use AcadosOcpSolver instead. For
more information on the major acados Matlab interface overhaul, see
https://github.com/acados/acados/releases/tag/v0.4.0 
> In acados_ocp (line 33)
In solver (line 189) 
Warning: cost_type_0 not set, using path cost 
> In AcadosOcp/detect_cost_and_constraints (line 820)
In AcadosOcp/make_consistent (line 107)
In AcadosOcpSolver (line 51)
In acados_ocp (line 41)
In solver (line 189) 
Warning: self.parameter_values are not set.
Using zeros(np,1) by default.
You can update them later using set(). 
> In AcadosOcp/make_consistent (line 131)
In AcadosOcpSolver (line 51)
In acados_ocp (line 41)
In solver (line 189) 
NOTE: The selected QP solver FULL_CONDENSING_QPOASES does not support one-sided constraints yet.
compiling C:\Solvers\acados_2\acados\examples\acados_matlab_octave\..\..\interfaces\acados_matlab_octave\ocp_get_cost.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
compiling C:\Solvers\acados_2\acados\examples\acados_matlab_octave\..\..\interfaces\acados_matlab_octave\ocp_get.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
compiling C:\Solvers\acados_2\acados\examples\acados_matlab_octave\..\..\interfaces\acados_matlab_octave\ocp_eval_param_sens.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
acados MEX interface compiled successfully
Warning: KKT_residuals now computes the residuals of the output iterate in SQP_RTI,
this leads to increased computation time, turn off this port if it is not needed. See
https://github.com/acados/acados/pull/1346. 
> In AcadosOcp/get_template_list (line 1070)
In AcadosOcp/render_templates (line 980)
In AcadosOcpSolver (line 61)
In acados_ocp (line 41)
In solver (line 189) 

It gives me the following error.

Error using render_file (line 51)
rendering acados_solver.in.c failed.
 command:
 C:\Solvers\acados_2\acados\examples\acados_matlab_octave\..\..\bin\t_renderer.exe
 "C:\Solvers\acados_2\acados\examples\acados_matlab_octave\..\..\interfaces\acados_template\acados_template\c_templates_tera\**\*"
 "acados_solver.in.c"
 "C:\Model\mpc_model_current_dynamics_deltaudot(change)_constraints\acados_ocp_nlp.json"
 "acados_solver_PMSM_model.c"
 returned status 1, got result:
Error: Failed to render 'acados_solver.in.c'
Reason: Variable `constraints.lsg[i]` not found in context while rendering
'acados_solver.in.c': the evaluated version was `constraints.lsg.0`. Maybe the index is
out of bounds?




Error in AcadosOcp/render_templates (line 991)
                render_file( in_file, out_file, json_fullfile )
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in AcadosOcpSolver (line 61)
            ocp.render_templates()
            ^^^^^^^^^^^^^^^^^^^^^^
Error in acados_ocp (line 41)
    solver = AcadosOcpSolver(ocp, output_dir);
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in solver (line 189)
ocp_solver = acados_ocp(ocp_model, ocp_opts);
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I tried chnaging the dimensions of cost matrices and slacks but it still results in error.

Hi :wave:

how are the linear constraints defined? Could you check the value of nsg in the generated .json? Also cost_Zl and cost_Zu should be vectors providing the diagonal values of Z_l, Z_u, respectively.

Also note that your are using the legacy MATLAB interface, please consider migrating to the new interface.

Best, Katrin

sorry, my mistake. In the legacy interface cost_Zl and cost_Zu are diagonal matrices, so this should not be the problem!