I have formulated an MPC using ACADOS. I am using the cost module “auto” and I want to use a model parameter (sym_p = PDem) in the cost function (I want to track some given power PDem). It looks something like this:
When I create an OCP solver instance, I am getting the following error:
“Error using casadi.Function/call (line 942)
…/casadi/core/sx_function.cpp:71: Cannot evaluate “jac_fun:(i0[3])->(o0[3]) SXFunction” since variables [PDem] are free.”
Is it possible to use a parameter in the cost function, or can I only use them in the process model?
I know, I can also use the cost module “nonlinear least squares”, and give sym_p (PDem) as the reference (y_ref). However, the formulation of my cost function would be much simpler if I use the cost module “auto”.
Is it possible to use a parameter in the cost function, or can I only use them in the process model?
Yes, that should be possible.
Please double check that you set the parameters correctly in your model.
Otherwise, you can provide a minimal example to reproduce the error?
I have created a minimal example with the ‘pendulum_on_cart_model’.
In the ‘pendulum_on_cart_model’ I have created a parameter called pRef, which is the reference position I would like to track. In the function, line 52, 57 and 114 are added by me, otherwise it is the default ‘pendulum_on_cart_model’
In the main I define the cost in line 121 to line 129.
When calling main I get the error I mentioned earlier:
…/casadi/core/sx_function.cpp:71: Cannot evaluate “jac_fun:(i0[3])->(o0[3]) SXFunction” since variables [pRef] are free.
I took a look at the new interface and I wondered how to include the simulink_opts for specifying the in and output of the s-function in the new interface?