Borrar filtros
Borrar filtros

Nonlinear optimal control by using yalmip

8 visualizaciones (últimos 30 días)
Kazu
Kazu el 10 de Oct. de 2013
Editada: Kazu el 9 de Oct. de 2016
I tried to implement the nonlinear optimal control by using YALMIP. The nonlinear dynamics involves sin and cos function and the code is;
%
yalmip('clear')
clear all
Q1 = eye(3);
R = 0.5*eye(2);
N=30;
u1 = sdpvar(N,1);
u2 = sdpvar(N,1);
x01 = sdpvar(1,1);
x02 = sdpvar(1,1);
x03 = sdpvar(1,1);
constraints = [];
objective = 0;
x1 = x01;
x2 = x02;
x3 = x03;
T=0.2; %sampling time
for k = 1:N
u1k = u1(k);
u2k = u2(k);
x1 = x1-u1k*T*cos(x3);
x2 = x2-u1k*T*sin(x3);
x3 = x3-u2k*T;
xk=[x1;x2;x3];
uk=[u1k;u2k];
objective = objective + norm(Q1*xk,1) + norm(R*uk,1);
constraints = [constraints, -3 <= u1k<= 3, -1 <= u2k<= 1,-pi<=x3<=pi];
end
options = sdpsettings('verbose',1,'solver','fmincon');
controller = optimizer(constraints,objective,options,[x01;x02;x03],[u1 u2]);
x=[10;15;pi];
uopt=controller{x}
%
Then I get the strange optimal control inputs, where all the components are "NaN". It seems that the reason is because I used the nonlinear operators "sin"and "cos". Anybody knows how to fix this problem?
Thank you

Respuestas (1)

Johan Löfberg
Johan Löfberg el 5 de Nov. de 2013
The problem is that you are creating a nonconvex nonlinear problem, and fmincon simply fails to find a solution. You see this if you catch the problem flag from the optimizer call
[uopt,problem]=controller{x}
The model you create is extremely complex. Since you declare the dynamics using assignments, x(N) will be an enormously complex function of the input variables. The computational tree will really deep. It is much better if you declare the MPC problem in implicit prediction form (i.e., optimize over both x and u and connect them using equality constraints). See the YALMIP Wiki for details on MPC examples.
Having said that, it will still be nonlinear and nonconvex and most likely fmincon will struggle to find a solution. Start with N=1, and if that doesn't work, well...

Categorías

Más información sobre Linear Least Squares en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by