How to set linear constraints with acados?

Hi :wave:,

I want to seek some clarification on the constraints. I am using the Python interface on Ubuntu.

Initially, I encountered difficulties expressing linear constraints on two states of my state vector, x, such that a certain condition is satisfied (min < x[2]-x[3] < max). I tried various approaches, including an identity matrix, but faced issues with dimensions. Here is how I would do it. Say the dimension of constraints is k. Then the matrix kxn specifies how the constraints are defined. If you take the matrix that translates a matrix and a vector to a constraint expression such as: k x n * nx1, you get kxn, which describes the constraints. In other words, kx < kxn * nx1 < kx. So in my case, k is one, so my approach would have been.

self.__ocp.constraints.C = np.array([[0, 0, 1, -1, 0]])
self.__ocp.constraints.D = np.array([[0, 0]])
self.__ocp.constraints.lg = np.array([self.__min])
self.__ocp.constraints.ug = np.array([self.__max])

This gives the error:

Exception: Invalid constraint C value. Should be a 2-dimensional numpy array.

However, the following works.

python

self.__ocp.constraints.C = np.array([[0, 0, 1, -1, 0], [0, 0, 1, -1, 0]])
self.__ocp.constraints.D = np.array([[0, 0], [0, 0]])
self.__ocp.constraints.lg = np.array([self.__min, self.__min])
self.__ocp.constraints.ug = np.array([self.__max, self.__max])

Questions and Confusion: The solution above works, but Iā€™m puzzled as to why I have to restate the constraints. Additionally, I find it somewhat counterintuitive that to express the condition min < x-y < max, I need a 2D vector of the min and max values. Could you kindly shed some light on these aspects? Did I misunderstand something?

self.__ocp.constraints.C = np.array([[0, 0, 1, -1, 0], [0, 0, 0, 0, 0]])
self.__ocp.constraints.D = np.array([[0, 0], [0, 0]])
self.__ocp.constraints.lg = np.array([self.__min, self.__min*0])
self.__ocp.constraints.ug = np.array([self.__max, self.__max*0])

I did the above and it worked. So the dimension of C cant be R1xM but there has to be zeros?
I did try to remove the check but some code in the c-libray did not compile.

Hi,
I think there is some confusion.
This does not result in an error of the form

Exception: Invalid constraint C value. Should be a 2-dimensional numpy array.