# Terminal constraints from MATLAB interface

Hi.

Not sure if I have discovered a bug or unintended usage of the MATLAB interface (still haven’t got time to investigate). But here follows my observations:

1. When I call ocp.generate_c_code I get the following error Reference to non-existent field 'dim_nbxe_0' from the script set_up_acados_ocp_nlp_json. I’m using the latest master branch.
2. Why can’t constr_lbx and constr_ubx be used with stage = N without setting constr_Jbx_e, constr_lbx_e and constr_ubx_e?
3. It seems like the state and input inequality constraints for the terminal stage is not defined/set with constr_lbx and constr_ubx?

Furthermore it would be nice if the problem formulation document (PDF) on GitHub could be updated to reflect the discretized problem formulation (i.e. cost and constraints for each stage) similar to the picture below taken from the ACADOS paper.

Best regards
Thomas Jespersen

Hi Thomas,

1. I guess you did not set constr_x0 in your problem formulation, which then internally sets dim_nbxe_0 and constr_idxbxe_0. It should be fixed with this commit: https://github.com/FreyJo/acados/pull/60/commits/0ebdf682c58986bdd65358d2308e9c111b6a7390
2. This was a design choice made at some point when the interface was introduced.
The reason was, that it one might have different state constraints on the terminal shooting node. Especially, with a different dimension.
3. I guess you mean when running ocp.set('constr_lbx', lbx), i.e. without the last argument (stag index).
Note that the default, if no stage index is provided, is that the value is set for the stages with index 0 to N-1.

A design choice of the high level interfaces is to let the user formulate the problem in continuous time and carry out the discretization, then create a corresponding acados OCP solver, that one can interact with.
For example, one does specify the cost function l from the continuous formulation, this is discretized by weighting the cost of each shooting node corresponding to the time interval, (mostly relevant for nonuniform discretizations).
Moreover, typically, it is more convenient to describe the system dynamics in continuous time and one wants to use acados’ efficient integrators.

Best,
Jonathan

Thanks a lot for your answers which indeed explains some of the issues I was observing.

I guess you mean when running ocp.set(‘constr_lbx’, lbx), i.e. without the last argument (stag index).

So calling this function without the stage index will not set the constraints for the terminal stage?

A design choice of the high level interfaces is to let the user formulate the problem in continuous time and carry out the discretization, then create a corresponding acados OCP solver, that one can interact with.

But what does the actual problem formulation look like that ACADOS implements when using discrete dynamics: dyn_type = discrete?

Also is there any way to apply custom non-linear equality constraints (which the discrete dynamics is as well)?

Regards Thomas

Hi Thomas,

So calling this function without the stage index will not set the constraints for the terminal stage?

It is definitely the cleanest to always call the function with stage index IMO.

But what does the actual problem formulation look like that ACADOS implements when using discrete dynamics: dyn_type = discrete?

Basically, if you look at the problem formulation in Section 2.3 here: https://arxiv.org/pdf/1910.13753.pdf
The discrete dynamics function implements the function \phi_k(\cdot) .

I guess the easiest would be to formulate them as nonlinear constraints h with upper and lower bounds being equal.
But “custom” does mean non CasADi compatible for you?
And “nonlinear” equalities can obviously yield to numerical difficulties.

Best,
Jonathan