External Cost function formulation in MATLAB

Hello fellow acadosers,

First of all I am new to acados. I am trying to formulate an MPC problem for an autonomous car using acados. I succeeded to formulate the cost function using linear_ls cost function, but now I am trying to formulate it as an external function. I checked the example already present in the example folders but it is not straightforward how should I achieve my task. My supervisor informed me that in order to feed in the reference trajectory I need to exploit the sym_p, but I am not quite sure how should do it. Thus any advises and suggestions on where to look would be highly appreciated!!

Thanks in advance,

Hi :wave:

… and welcome to the acados forum!

In case your cost is only time varying due to a time-varying reference trajectory, you might still use a linear least squares cost and update the reference cost_y_ref before each solve, cf. this example.

In case you really need the external cost module, you might want to check this example. The main idea is to simply provide a CasADi expression for the stage cost which can depend on x, u and in your case also p.

Best, Katrin

1 Like