Error in generating code for dynamical functions. Variables are free

Hi :wave:

If you have an issue with acados and are looking for help here:

  • I’m using acados on Matlab
  • I want to create a mpc loop for quadcopter
I got this error message:

Error using casadi.Function/generate
.../casadi/core/sx_function.cpp:149: Code generation of 'Qdrone_dyn_expl_ode_fun' is
not possible since variables [dX, dY, dZ, dphi, dtheta, dpsi, u1, u2, u3, u4, theta,
phi] are free.

Error in indexing (line 1753)
        [varargout{1:nargout}] = builtin('subsref',self,s);

Error in generate_c_code_explicit_ode (line 185)
expl_ode_fun.generate([model_name,'_expl_ode_fun'], casadi_opts);

Error in ocp_generate_casadi_ext_fun (line 47)
        generate_c_code_explicit_ode(model_struct, opts_struct);

Error in acados_ocp (line 205)
                ocp_generate_casadi_ext_fun(obj.model_struct, obj.opts_struct);

Error in main_acados_amit (line 100)
ocp = acados_ocp(ocp_model, ocp_opts);
Thank you very much

This means your variables are free, i.e. not part of the acados model.

Hi @FreyJo,

Sorry to jump in, but I am facing a similar error, and I thought I would add to this discussion. I noticed I only get the error above when using MX type symbolic variables in casadi (i.e., model compiles when using SX varibales). Was wondering if there is an specific reason for that. In my case I will be forced to use MX variables in the future since I would like to use the interpolant functionality. Would you suggest any workaround?

Many thanks,


what you describe seems to be a CasADi issue. Not sure which version you are on there.
But, if variables are free, newer CasADi versions complain, which is desired behavior.
Can just run with SX to see which variables are free and add them in the acados symbolics too?


I’m encountering a similar issue as @mbertoli.
I specifically require the use of symbolic variables (MX) due to my reliance on the casadi function “casadi.interpolant(‘LUT’,‘bspline’,{xgrid}, V);”.
Has anyone discovered a workaround for this problem in the meantime?


whenever I ran into the “variables are free” error, there were actually free variables.
I think it would make sense to make a minimal example and a new post if you think that error is raised where it shouldn’t be.
If this is actually the case, I think it would be a CasADi issue.