Hello, everybody,
I use yalmip in Simulink, but the result is not correct, all the output is 0. That means the Constraints does not work. The solver is Mosek. And this is a convex nonlinear optimization. Thanks for your help.
The complete code is:
function F_Param = optimfcn(u_d,w_v_d,t)
persistent Controller
if t==0
l=2.7;s=1.48;
l_v = 1.43;
l_h = 1.27;
s_l = 0.74;
s_r = 0.74;
F_Z_F0= [4034;4034;4549;4549];
F_z0 = 4000;
k_Fz = 0.1;
G = [1 0 1 0 1 0 1 0;
0 1 0 1 0 1 0 1;
-s_l l_v s_r l_v -s_l -l_h s_r -l_h];
V = [1, 1, 1, 1;
s_l, -s_r, s_l, -s_r;
-l_v, -l_v, l_h, l_h];
G_plus = G'*inv(G*G');
G_rann = [1 0 0 0 -l/s;
0 0 1 0 0;
0 1 0 0 l/s;
0 0 -1 0 -1;
-1 0 0 0 0;
0 0 0 1 1;
0 -1 0 0 0;
0 0 0 -1 0;];
V_plus=V'*inv(V*V');
V_rann=[1;1;1;1];
yalmip('clear')
x=sdpvar(7,1);
rr=sdpvar(3,1);
uu=sdpvar(3,1);
M=eye(8,8);
N=eye(4,4);
constraints=[];
constraints=[constraints,-x(1)<=0];
for i=1:4
constraints=[constraints,-x(1)*(-(1*k_Fz/F_z0)*(N(i,:)*(V_plus*uu+V_rann*x(7)+F_Z_F0))^2+(1+k_Fz)*N(i,:)*(V_plus*uu+V_rann*x(7)+F_Z_F0))<=0];
end
j=1;
for i=1:4
constraints=[constraints,sqrt((M(j,:)*(G_plus*rr+G_rann*[x(2);x(3);x(4);x(5);x(6)]))^2+(M(j+1,:)*(G_plus*rr+G_rann*[x(2);x(3);x(4);x(5);x(6)]))^2)-x(1)*(-(1*k_Fz/F_z0)*(N(i,:)* (V_plus*uu+V_rann*x(7)+F_Z_F0))^2+(1+k_Fz)*N(i,:)*(V_plus*uu+V_rann*x(7)+F_Z_F0))<=0];
j=j+2;
end
objective=x(1)+x(2)^2+x(3)^2+x(4)^2+x(5)^2+x(6)^2+(x(7))^2;
ops=sdpsettings('solver','mosek','verbose',0);
Controller=optimizer(cc,objective,ops,{rr,uu},x);
Param=Controller({u_d,w_v_d});
else
Param=Controller({u_d,w_v_d});
end
F_Param=Param;