FormationControlSimulation/SOURCE/formationControl2ndBuilder.m

38 lines
2.1 KiB
Matlab
Raw Normal View History

2020-07-29 11:31:38 +07:00
function obj = formationControl2ndBuilder(edgeL,robStateLen,kp1,kp2,ki1,ki2,dScale,nNodeVref)
2020-07-28 13:32:25 +07:00
addpath("./networks-toolbox");
obj = struct();
2020-07-29 11:31:38 +07:00
[obj.R, obj.K, obj.d] = rigidityMatrixFnc(edgeL,robStateLen);
2020-07-28 13:32:25 +07:00
obj.m = length(obj.d);
obj.n = numNodes(edgeL);
2020-07-29 11:31:38 +07:00
obj.nodeStateLength = robStateLen*obj.n;
obj.stateLength = 3 * obj.nodeStateLength + obj.m;
2020-07-28 13:32:25 +07:00
% build matrix sistem
2020-07-29 11:31:38 +07:00
obj.A1 = @(st) [zeros(obj.nodeStateLength), eye(obj.nodeStateLength), zeros(obj.nodeStateLength), zeros(obj.nodeStateLength,obj.m)];
obj.A2 = @(st) [-kp2*obj.R(st(1:(obj.nodeStateLength)),obj.K)'*obj.R(st(1:(obj.nodeStateLength)),obj.K), -kp1*eye(obj.nodeStateLength), -eye(obj.nodeStateLength), -obj.R(st(1:(obj.nodeStateLength)),obj.K)'];
obj.A3 = @(st) [zeros(obj.nodeStateLength), ki1*eye(obj.nodeStateLength), zeros(obj.nodeStateLength), zeros(obj.nodeStateLength,obj.m)];
obj.A4 = @(st) [ki2*obj.R(st(1:(obj.nodeStateLength)),obj.K), zeros(obj.m,obj.nodeStateLength), zeros(obj.m,obj.nodeStateLength), zeros(obj.m)];
2020-07-28 13:32:25 +07:00
obj.A = @(st) [obj.A1(st); obj.A2(st); obj.A3(st); obj.A4(st)];
obj.sizeA = size(obj.A(ones(obj.stateLength,1)));
% build matrix input
2020-07-29 11:31:38 +07:00
obj.B = @(st) [zeros(obj.nodeStateLength,obj.m); kp2*obj.R(st(1:(obj.nodeStateLength)),obj.K)'; zeros(obj.nodeStateLength,obj.m); -ki2*eye(obj.m,obj.m)]
2020-07-28 13:32:25 +07:00
obj.sizeB = size(obj.B(ones(obj.stateLength,1)));
%build state space
obj.Kb = zeros(obj.n*3,1);
obj.Kb(obj.n+nNodeVref) = 1;
2020-07-29 11:31:38 +07:00
obj.Kb = [kron(obj.Kb,eye(robStateLen)); zeros(obj.m,robStateLen)];
2020-07-28 13:32:25 +07:00
obj.d = obj.d*dScale;
obj.ssDisc = @(st,vRef,h) (eye(obj.sizeA) + (obj.A(st)*h))*st + obj.B(st)*h*obj.d + obj.Kb*vRef;
obj.ss = @(st,vRef) obj.A(st)*st + obj.B(st)*obj.d + obj.Kb*vRef;
printf("============== Formation Control ============ \n");
printf(" Node : %i \n", obj.n);
printf(" Edge : %i \n", obj.m);
printf("Dimention State : %i \n", obj.stateLength);
printf(" Dimention A : %i x %i \n", obj.sizeA);
printf(" Dimention B : %i x %i \n", obj.sizeB);
printf("============================================= \n");
endfunction