function obj = formationControl2ndModelBuilder(edgeL,model,kp1,kp2,ki1,ki2,dScale,nNodeVref) addpath("./networks-toolbox"); % pkg load parallel obj = struct(); robStateLen = size(model.syscl.A,1) [obj.R, obj.K, obj.d] = rigidityMatrixFnc(edgeL,robStateLen); obj.m = length(obj.d); obj.n = numNodes(edgeL); obj.nodeStateLength = robStateLen*obj.n; obj.stateLength = 4 * obj.nodeStateLength + obj.m; % build matrix sistem obj.A1 = @(st) [zeros(obj.nodeStateLength), zeros(obj.nodeStateLength), zeros(obj.nodeStateLength),zeros(obj.nodeStateLength,obj.m), eye(obj.nodeStateLength)]; 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)',zeros(obj.nodeStateLength)]; obj.A3 = @(st) [zeros(obj.nodeStateLength), ki1*eye(obj.nodeStateLength), zeros(obj.nodeStateLength), zeros(obj.nodeStateLength,obj.m), zeros(obj.nodeStateLength)]; 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), zeros(obj.m,obj.nodeStateLength)]; obj.MOsgn =@(st) diag([model.sgn(st(1)) model.sgn(st(2)) model.sgn(st(3))]); obj.MOdist = @(st) [obj.MOsgn(st(31:33)) zeros(robStateLen) zeros(robStateLen); zeros(robStateLen) obj.MOsgn(st(34:36)) zeros(robStateLen); zeros(robStateLen) zeros(robStateLen) obj.MOsgn(st(37:39))]; obj.MO = @(st) [zeros(obj.nodeStateLength), kron(eye(robStateLen),model.syscl.B) , zeros(obj.nodeStateLength), zeros(obj.nodeStateLength,obj.m), kron(eye(robStateLen),model.syscl.A)+obj.MOdist(st)]; obj.A = @(st) [obj.A1(st); obj.A2(st); obj.A3(st); obj.A4(st); obj.MO(st)]; obj.sizeA = size(obj.A(ones(obj.stateLength,1))); % build matrix input 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); zeros(obj.nodeStateLength,obj.m)] 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; obj.Kb = [kron(obj.Kb,eye(robStateLen)); zeros(obj.m,robStateLen); zeros(obj.nodeStateLength,robStateLen)]; obj.d = obj.d*dScale; obj.dss = @(st,h,vRef) (eye(obj.sizeA) + (obj.A(st)*h))*st + obj.B(st)*h*obj.d + obj.Kb*h*vRef; obj.ss = @(st,vRef) obj.A(st)*st + obj.B(st)*obj.d + obj.Kb*vRef; printf("============== Formation Control ============ \n"); printf(" state model : %i \n", obj.nodeStateLength); 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