Adding slack variables crashes Matlab

Hi :wave:

unfortunately I am having troubles adding slack variables to my OCP and I wanted to report that issue.

In my formuation I have used constr_expr_h so far for bounding one state and the input. This caused the automatic reformulation of the bounds to bounds on x1 and u.

Now I want to add slacks to my OCP. Due to the automatic reformulation I am unable to use constr_Jsh, as acados returns the error that the dimension of constr_Jsh should be 0x1. This seems legit, as constr_expr_h has been reformulated.

Therefore I reformulated my OCP so that I use constr_Jbx and constr_Jbu right away. Now, as soon as I try to set constr_Jsbx Matlab crashes in the compilation of the solver. According to Matlab’s log, the crash happens in ocp_create.mexw64

I am using acados version with tag 016. The minimal example will follow in the next post :slight_smile:

Best Regards

So I was able to quickly create a minimal example that causes the crash.

Just take minimal_example_ocp.m and replace lines 87-92 with the followiing code:

%% constraints
ocp_model.set('constr_type', 'bgh');

U_max = 80;
ocp_model.set('constr_lbu', -U_max); % lower bound on u
ocp_model.set('constr_ubu', U_max);  % upper bound on u
x1_max = 100;
Jbx = zeros(1,nx);
Jbx(1,1) = 1;
ocp_model.set('constr_lbx', -x1_max); % lower bound on x1
ocp_model.set('constr_ubx', x1_max);  % upper bound on x2
ocp_model.set('constr_x0', x0);

%% Configure constraint slack variables
ns = 2;

ocp_model.set('constr_Jsbu', 1);
ocp_model.set('constr_Jsbx', 1);
% Set cost on slack
% L1 slack (linear term)
ocp_model.set('cost_zl', 100 * ones(ns,1));
ocp_model.set('cost_zu', 100 * ones(ns,1));
% L2 slack (squared term)
ocp_model.set('cost_Zl', 0 * ones(ns,ns));
ocp_model.set('cost_Zu', 0 * ones(ns,ns));

Hi Chris,

Thanks for reporting and adding the example!

I just found the bug and pushed a fix:

It is now merged into the acados master branch.


Hello Jonathan,

thank you for the quick fix! :slight_smile:

I just updated my source folder, reinstalled acados and tested your fix:

  • Now, minimal_example.m works with the above mentioned slacks.
  • Unfortunately, now when I execute simulink_example.m Matlab/Simulink crashes as soon as I run the simulink model with the generated sFunction.

I tried to inspect the error. The only helpful line in Matlab’s crash logs seems to be:
C:\WINDOWS\System32\msvcrt.dll+00239557 initterm_e+00000581

Setting contr_Jsbu doesn’t cause problems, only when setting constr_Jsbx.

Is there any other information I can provide to help you find the bug?


Hi Chris,

I just pushed another fix

I also tested the modified example in Simulink, let me know if you have further issues.