 # Terminal value of input (unwanted terminal equality constraint)

Dear community,

I am using acados in matlab to solve an MPC problem for trajectory tracking. Hence, i have time varying references. I set these references in a loop with counter variable ii via

``````ocp.set('cost_y_ref', [x_ref(:,ii+1);u_ref(:,ii+1)], ii);
``````

(My stage cost is based on the expression `expr_y = [sym_x; sym_u];`)

It seems that the optimal input sequence of the ocp always ends exactly(!) at the last value of u_ref (even if put nonsense values in there which do not fit to the reference in the states). This looks like a terminal equality constraint on the inputs to me…

I am using cost_type = ‘linear_ls’;
The weights in my cost function are very high on the states and very low on the inputs. The weights for my terminal cost is zero and the terminal cost uses expr_y_e = [sym_x];. So there is no input involved in the terminal cost.

Does anyone knows how to explain that behavior? The optimal input sequence at the end of the prediction horizon is always exactly ending at its reference value even if this leads to a deviation in the state (which is weighted much stronger)?

Hi Janine,

first of all, welcome to the forum Be aware that the terminal node `N`, has no control input `u`, so it cannot be part of `expr_y_e`.

The weights for my terminal cost is zero and the terminal cost uses expr_y_e = [sym_x]

I think this is actually the issue.
If there is no terminal cost ( it is 0 always ), it doesn’t matter what the final state is, from an optimization point of view.
The last control input, which influences `x` between shooting node `N-1` and `N`, will just be chosen as the `u_ref`, because it does not matter how you influence `x` in the end, since `x` at stage `N` does not enter the cost.

Does that make sense to you?

Best,
Jonathan

1 Like

Dear Jonathan,
thanks for your fast and helpful reply! This totally makes sense and was indeed the reason for this behavior. Including a highly weighted terminal cost solved this issue. Thanks a lot!!!

Kind regards,
Janine

1 Like