Issue in setting slack variable on control input

Hi, I am experiencing an issue when trying to set soft constraints on the control input after upgrading Acados to release v0.3.0. It seems that the cost on slack variables is handled separately at stage 0, but there are no setters for this stage in the MATLAB interface. This results in the following error:

Error using ocp_generate_c_code
error while reshaping cost.Zl_0 to dimension 1  4, got 0  0
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.

For instance, you can reproduce the error by adding the following lines in the linear_mpc example (example_closed_loop.m, line 84):

ocp_model.set('constr_Jsbu',eye(model.nu));
ocp_model.set('cost_Zl',1e6.*eye(model.nu));
ocp_model.set('cost_Zu',1e6.*eye(model.nu));
ocp_model.set('cost_zl',1e6.*ones(model.nu,1));
ocp_model.set('cost_zu',1e6.*ones(model.nu,1));

Thanks for any help!

Hi Francesco,

this is because we split the soft constraints for the initial shooting stage and the path stages.

I implemented that you can specify them at the initial stage too in Matlab on this branch: Support soft u constraints in MEX interface by FreyJo · Pull Request #1037 · acados/acados · GitHub
Adding these lines should work on this branch.

ocp_model.set('constr_Jsbu',eye(model.nu));
ocp_model.set('cost_Zl',1e6.*eye(model.nu));
ocp_model.set('cost_Zu',1e6.*eye(model.nu));
ocp_model.set('cost_zl',1e6.*ones(model.nu,1));
ocp_model.set('cost_zu',1e6.*ones(model.nu,1));


ocp_model.set('constr_Jsbu_0',eye(model.nu));
ocp_model.set('cost_Zl_0',1e6.*eye(model.nu));
ocp_model.set('cost_Zu_0',1e6.*eye(model.nu));
ocp_model.set('cost_zl_0',1e6.*ones(model.nu,1));
ocp_model.set('cost_zu_0',1e6.*ones(model.nu,1));

Let me know if it works for you!

Best,
Jonathan

It works, thanks!
What about general linear constraints? Are they splitted as well?

The convention is as follows now:

  • bounds on u and general linear constraints are also enforced on the initial node
  • bounds on x and nonlinear constraints are fully split and have to be explicitly stated with _0 correspondence to be enforced on the stage.

After my last reply, I realized, that there is no Jsbu_0, as it is assumed to be the same as Jsbu.
I changed that in my PR and you can not set Jsbu_0 in ocp_model.

1 Like