How to set weights of costs according to the time interval in MPC prediction horizon

You’re Welcome!

You’re right about the first part of your text.

However parameter are defined as loose symbols in acados. You can define everything as a parameter (e.g. your reference y_{ref}) with casadi/acados => those symbolic parameters can then used in your system dynamics, cost function, constraints, etc.

One example:
You want to change the weights of your external cost function in every control cycle. So you do something like this:

w = cs.SX.sym(‘w’)
ocp.model.p = w
ocp.model.parameter_values = 1

cost_func = w * (y - y_ref) * (y - y_ref)
ocp.model.cost_expr_ext_cost = cost_func

#run mpc

#change weight
for n in range(0,N+1)
ocp_solver.set(n, ‘p’, w_{new})

I hope you get what I mean. Maybe @FreyJo can point you towards a good example :slight_smile: !
Best Luck with your implementation!
Thorben

1 Like