Thanks for the quick reply. The external_function_param_generic interface is definitely in the right direction.
Ideally, what I’m looking is just a way to supply the cost function and its Jacobian as pure C functions.
That is, be able to define the pure C code behind model.cost_y_expr and model.cost_y_expr_e with no library dependencies, no algorithmic differentiation etc.
With Forces this was not quite possible, but I was able to achieve something very close by using their External Function interface: https://forces.embotech.com/Documentation/high_level_interface/index.html#expected-function-signature
void myfunctions (
double *x, /* primal vars */
double *y, /* eq. constraint multiplers */
double *l, /* ineq . constraint multipliers */
double *p, /* runtime parameters */
double *f, /* objective function ( incremented in this function ) */
double *nabla_f , /* gradient of objective function */
double *c, /* dynamics */
double *nabla_c , /* Jacobian of the dynamics ( column major ) */
double *h, /* inequality constraints */
double *nabla_h , /* Jacobian of inequality constraints ( column major ) */
double *H, /* Hessian ( column major ) */
int stage, /* stage number (0 indexed ) */
int iteration /* Solver iteration count */
Although this requires everything to be specified in that C function it is acceptable for now.
So the question is if something similar can be achieved with Acados? So without using CasADi.
Both the example you provided and what I have found at
https://github.com/acados/acados/tree/master/experimental/interfaces/matlab/external_function_generation is using CasADi. For the latter, is the generated code used in another example anywhere?
Maybe I can achieve the above with ocp_nlp_cost_external_model_set with the field set to ext_cost_fun and ext_cost_fun_jac respectively? If so I would greatly appreciate some directions or hints, especially on the prerequisites before calling this function?
Or maybe this is exactly the example I am looking for: https://github.com/acados/acados/blob/master/examples/c/no_interface_examples/mass_spring_nmpc_example.c#L158-L262 ?
PS: The main reason for not using CasADi is that I’m unable to use CasADi since the function evaluations relies on an external array of data - which I don’t expect to be able to set as an online parameter
Again, thanks for your help.