Also, while continuing to experiment I am running into an issue with your optimizer command. For instance, I am changing your code into a three dimensional problem (for real world issues).
Here is the code:
A = [1 0 0 0 0 0; .1 1 0 0 0 0; 0 0 1 0 0 0; 0 0 .1 1 0 0; 0 0 0 0 1 0; 0 0 0 0 .1 1];
B = [.1 0 0; .005 0 0; 0 .1 0; 0 .005 0; 0 0 .1; 0 0 .005];
C = [ 0 1 0 0 0 0 ; 0 0 0 1 0 0 ; 0 0 0 0 0 1];
nu = size(B,2);
nx = size(A,1);
Q = eye(3);
R = .1*eye(3);
N = 10;
u = sdpvar(repmat(nu,1,N),repmat(1,1,N));
x = sdpvar(repmat(nx,1,N+1),repmat(1,1,N+1));
constraints = [];
objective = 0;
for k = 1:N
objective = objective + norm(C*x{k},1)+norm(R*u{k},1);
constraints = [constraints, x{k+1} == A*x{k}+B*u{k}];
constraints = [constraints, -2<C*x{k}<2,-1<u{k}<1];
end
% Plot the playing field and regions to avoid.
clf
plot(-2 < C*x{1} < 2,[],'FaceAlpha',0);hold on
plot(norm(C*x{1}+[.2;-.3;.4],inf)<0.2);
plot(norm(C*x{1}+[-.2;0.3;.2],inf)<0.2);
plot3(0,0,0,'.b','MarkerSize',50)
axis([-2 2 -2 2 -2 2]);
controller = optimizer(constraints,objective,[],x{1},u{1});
count = 1;
x_(:,count) = [ -2 ; .27 ; -2 ; .4184; -2; .9977]
while norm(x_(:,count)) > 1e-2
drawrobot(x_(:,count));
u_(:,count) = controller{x_(:,count)};
x_(:,count+1) = A*x_(:,count)+B*u_(:,count);
count = count+1;
pause(.01)
end
I am getting an error in the "WHILE" loop at the controller{x_(:,count)} command. I instituted a count variable in order to store the values throughout the simulation just for sanity checking later.
Any ideas?
Best
Corbin