Error when requesting constraint variables results

Hi all,

i’am using the matlab interface of acados for modelling a hybrid powertrain. The power demand is preset by a parameter trajectory. This works fine, as the resulting states and controls look reasonable. Unfortunately matlab returns an error when requesting the trajectory of constraint variables.

This is made, using

for i = 0:N-1
    constraint.P_inv2eng(ocp.get('x',i), ocp.get('u',i)));

There I get the error:

 Error using casadi.Function/call (line 942)
.../casadi/core/sx_function.cpp:71: Cannot evaluate "P_inv2eng:(i0[2],i1)->(o0) SXFunction" since variables [P_inert] are free.

The parameter P_inert is set before solving the problem as:

for i = 0:N-2
    ocp.set('p', P_inert(i+1), i);

I don’t understand the error since the paramer is defined before solving.

Thanks for your help.
Greetings Max

Hi Max,

It seems that constraint is a CasADi SX function, so not an acados object.
You only set the parameter values for the acados OCP solver object, in the for loop you posted.
If you check how the constraint function is set up and set the parameter value for it too, it should work.

Good luck!

Hi Jonathan,

this worked,

Thanks a lot!