Templated code rendering fails when using polytopic constraints

Hi :wave:

I am using the Matlab interface to generate the template based code, but when I add polytopic constraints I get the the following error:

Error: Failed to render 'acados_solver.in.c'
Reason: Variable `constraints.C_e[j][k]` not found in context while rendering 'acados_solver.in.c': the evaluated version was `constraints.C_e.1.0`.
Maybe the index is out of bounds?

Actually I noticed that the error arises only when C_e has a lower number of rows than C, that is what I need.

You can reproduce the error by adding the following lines in the minimal_example_ocp.m, in which I just added polytopic constraints:

ocp_model.set('constr_C', zeros(2,nx));
ocp_model.set('constr_D', zeros(2,nu));
ocp_model.set('constr_lg', -ones(2,1));
ocp_model.set('constr_ug', ones(2,1));
ocp_model.set('constr_C_e', zeros(1,nx));
ocp_model.set('constr_lg_e', -ones(1,1));
ocp_model.set('constr_ug_e', ones(1,1));

I added these lines just below line 92. Then the code generation via β€œocp.generate_c_code” will fail.

Am I missing some setting?


Thanks for reporting this!
I just pushed a fix for this here:


1 Like