Build a model that takes prev shooting node's x and u as param

Hi :wave:

I am using acados python interface to build a NMPC problem.
I want to build a complex model that takes x[0] and u[0] (symbolics) at N = 0 as paramaters β€˜p’, and pass it to the model at N = 1. For example in casadi, I build this:

self.x = ca.MX.sym("x", self.nx, 1)
self.u = ca.MX.sym("u", self.nu, 1)
self.p = ca.MX.sym("p", 1, self.feature_size)
self.x_dot = ca.vertcat(
            ca.cos(self.x[2]) * self.x[3],
            ca.sin(self.x[2]) * self.x[3],
            self.x[4],
            self.u[0] + f1(p), # some function
            self.u[1] + f2(p) # some function
        )

And in a mpc problem:

self.X = ca.MX.sym('X', nx, self.N+1)  # State trajectory
self.U = ca.MX.sym('U', nu, self.N)  # Control inputs
self.X0 = ca.MX.sym('X0', nx)  # Initial state
for k in range(N):
    if k != 0:
        dynamic = self.model.create_discrete_nlp_model()
        inputs = ca.horzcat(self.X[:, k-1].T, self.U[:, k-1].T)
        x_next = dynamic(self.X[:, k], self.U[:, k], inputs ) # here we pass the inputs of k - 1 to the model at k

This create_discrete_nlp_model is a casadi Function takes x, u and p as params.
In this way, model at k = 1 will take x and u at k = 0 as params.

However, in acados, I don’t know how to achieve the same thing. As each u and x are seperated between shooting nodes.

Hi :waving_hand:

The acados formulation does not allow coupling between stages, i.e. the cost and constraints at stage n can only depend on x_n and u_n. To allow coupling you will need to augment your model, see:

Hope this is helpful!
Katrin

1 Like

Thank you for your answer! It seems like this will be a mess if the input is x [k-1, k-2, …], not 1 stage before, but 2 or 3 … Anyway, thanks again!