Nonlinear least squares MPC

Hello all,

I am a new user of the library, trying to solve an MPC problem for a multi-agent system through acados’ Matlab interface. My lagrange objective term is the sum of nonlinear terms like this: f_1(x(t))^2+f_2(x(t))^2+f_3(x(t))^2.

First of all, is there any example about the use of the ‘nonlinear_ls’ cost type? Also, any reference for when and how to prefer ‘cost_expr_y’?

I have tried to implement my problem by adding the nonlinear terms to the ‘cost_expr_y’ vector, with zero reference ‘cost_yr’. I am using ‘nonlinear_ls’ as cost type. The C code is generated successfully. However, the result is not as expected and in ‘ocp.model_struct.cost_expr_y’ I do not find the same function I assigned to ‘cost_expr_y’: sums and multiplications seem to be messed up and some ‘sq’ appear. Any clue of why this happens? Does ‘sq’ stands for ‘sqrt’?

Many thanks,

Hi Enrica, thanks for your interest in acados! Could you share your example such that we can have a look?

Hi Enrica,

the nonlinear least squares objective is in the form || y(x,u) - y_ref ||^2_W. The nonlinear term y(x,u) is the one which should get in the cost_expr_y. Both y_ref and W are treated as numerical, and should be represented by matlab matrices.

So in your case it would be y(x,u) = [f_1; f_2; f_3], y_ref=zeros(...), W=eye(...).
If this is what you already did, you could send us a small self-contained code example which creates the expression for ‘cost_expr_y’ and the corresponding function you say it is not the one you assigned.

About constraints, there are three types: bounds b (comprising state bounds bx and input bounds bu), general affine g and nonlinear h constraints.
These suffixes are combined with the prefixes n for dimensions (e.g. nbx), l/u for upper and lower constraint vector (e.g. lg).
The prefix J (e.g. Jbx) represents a matrix made of rows from an identity matrix. This is a way to encode which of your states or inputs are bounded.



Thank you for your reply, I’ll share the example asap!