Why algebraic variables cannot be handled in terminal least-squares cost?

Hi, I’m using python interface of acados.
And I’m curious about why algebraic variables cannot be handled in terminal least-squares cost.

According to the OCP in the problem formulation sheet, Mayer term can be dependent on state variables and algebraic variables.
(https://github.com/acados/acados/blob/master/docs/problem_formulation/problem_formulation_ocp_mex.pdf)
But it only supports state variables currently.

Presumably, the reason is algebraic variables can be dependent on control variables and terminal term cannot include them.
Is it so?

And how can I achieve terminal cost with algebraic variables which are not dependent on control variables?
I want to avoid using external cost.

Thank you.

Do you think it works properly and be a plausible way to achieve my goal?

  1. Set the number of stages N+1 if I actually want N stages.
  2. Set W_e = 0.
  3. Set input weights in W at Nth stage = 0.

I think this can make the virtual last stage(N+1th) disappear and acutal last stage(Nth) only depend on state and algebraic variables.

I feel this is a clever approach. Additionally, a more convenient way is to not call statements like ocp.cost.W_e and ocp.cost.yref_e when constructing the solver. By default, it will not need to consider various quantities related to the last point (the virtual point). Also, although external costs are troublesome to use, it can help validate the previous “virtual point” method. This is because *cost_expr_ext_cost_e seems to allow specifying the cost expression for just the last point separately. We can compare the results from the two methods to see if they are close.