I am implementing a mhe algorithm with acados python interface. For the mhe I would like to formulate a external cost function. Is there a example, that I can refer to?
Especially, how to set the reference variable?
for example, set x_prior, ymeas as reference.
arrival_cost = 2 * (eta ** N) * mtimes((x - x_prior).T, mtimes(P, (x - x_prior)))
measurement_error_cost = sum(disc_factor[j] * mtimes((y - ymeas).T, mtimes(R, (y - ymeas))) for j in range(N))
Here is an example that showcases different cost formulations
Note that you will need to additionally define a separate cost for the initial stage via model.cost_expr_ext_cost_0 in order to additionally include the arrival cost term.
I have formulated a external cost function. But I have still the issue: how to set the reference term. For βLSβ or βNLSβ man can give the arrival cost and measurement though set the yref for initial stage and other stage, respectively. Apparently this term yref is useless for external cost function. How can I tell acados, which term is a reference in the function equation so that the values can be provided to the solver in the main process?
I have already successfully implemented mhe using external cost function. It performs well in the modified example -pendulum on cart.
for this topic I have just one question:
In which situation should I compute the Hessian matrix manually? for now, I let acados compute it automatically.