Setting a terminal equality constraint in MATLAB

Hi :wave:

I am using the MATLAB interface on Windows and trying to do the following:

  1. solve a linear MPC tracking problem using a controller with a longer horizon (N=10)
  2. solve the same linear MPC problem with a shorter horizon (N=1), starting from the results obtained from 1.

Later, I would like to do the same with a nonlinear OCP and a different cost in the second controller.

So far, I have tried using the linear_mpc example with the following:

  • setup the two OCPs, where the only difference is the horizon and the terminal constraint
  • solve the first OCP and obtain x^* and u^* (optimal predicted states and inputs)
  • set the terminal constraint of the second problem equal to x_1^* (first predicted state) with ocp_solver.set('constr_lbx',...,1) and ocp_solver.set('constr_ubx',...,1)
  • set the initial guess of the second solver to x^* and u^*
  • solve the second OCP

However, the control input obtained from the second controller is not the same (in fact, it is approximately zero).

Is it possible to set the terminal equality constraint in that way? I guess that an alternative would be to use parameters, but that would complicate the formulation a bit.

A working example can be found here:

Thanks in advance!

Kind regards,
Josip

Don’t you need to get the second entry of the state trajectory here?

Oh that’s right, thank you very much Katrin! :slight_smile:

Best regards,
Josip

1 Like