C Code doesnt generate for nonlinear_ls cost type


This is regarding acados in Matlab interface. I am using cost type as nonlinear_ls and when I generate C-Code I get the following error:

Error using ocp_generate_c_code (line 39)
mex templating does only support linear_ls cost for now. Got cost_type: nonlinear_ls, cost_type_e: nonlinear_ls.
Notice that it might stillbe possible to solve the OCP from MATLAB.

Error in acados_ocp/generate_c_code (line 165)

Error in NLK_static_acados_main (line 134)

From this i suspect that, acados does not support C-Code generation for nonlinear_ls type cost. Does it also not support external cost type ext_cost. If it does, then I would like to know the application of external cost type so I can reformulate my cost function accordingly.

For your reference, my cost function looks like this:
f(x) + (x_ref - x)^2
Since i introduced a nonlinear f(x) I had to switch to nonlinear type of cost function from linear_ls.
Note: x here is the state.

I need to generate C-Code as I then generate S-functions for Simulink. It would be really helpful if you could add this support in acados.


Hi Smit,

I just added support for the nonlinear least square cost in Matlab for the templates on the master branch.

This test should show you how to use it:

Let me know, if it works for you.


Hi Jonathan,

Thank you very much for adding the support for nonlinear least squares cost in Matlab. I just checked with my simulations and it works perfectly :slight_smile:

Best regards,