1

I am trying to find the the closed loop dynamic model of my quadcopter using MATLAB and connect(). Here is my system and code:

%      throttle --------------------- 1450 ----------------
%                                           throtScaled   |
%                                                         |
%                                                         |
%                       e                             cs  |+  u                 y 
% r_phi,pitch,psi --->O---> PID array -----> Mapping ---->O-------> ssModel -----------
%                     ^                                   +                            |
%                     |                                                                |
%                     |                                                                |
%                     |                                                                |
%                     |----------------------------------------------------------------|                                                        

function closedLoopPoles

clc

% create the estimated blackbox nonlinear ARX model
nlArxSys   = nonLinARXmodel(getDataSet());

% linearize the model about the operating points:
U0         = ones(4,1);  
X0         = findstates(nlArxSys,getDataSet());
linTfSys   = linearize(nlArxSys,U0, X0); % returns a tf

% Create the SS model
ssModel    = ss(linTfSys);

%Define the PID controllers array
pidGains     = [180 4 20; ...
                160 4 20; ...
                150 4 10];
pidTF_array  = ones(3,3) * tf(0,1);
Ts           = 0.0083;
for i = 1:size(pidGains,1)
    pidTF_array(i,i)  = pid( pidGains(i,1), pidGains(i,2), pidGains(i,3), 'Ts', Ts );
end

% Assign the signals names and the systems structure
mapping     = 0.5 * [1 1 2; 1 -1 -2; -1 -1 2; -1 1 -2];
C           = mapping * pidTF_array;
C.u         = 'e';
C.y         = 'cs'; 
ssModel.u   = 'u';
ssModel.y   = 'y';
throt_gain  = tf(1450,1);
throt_gain.u = 'throttle';
throt_gain.y = 'throtScaled';
sum1        = sumblk('e = r - y',3);
sum2        = sumblk('u = throtScaled + cs',4);

% Find the closed loop system
clTF        = minreal( connect(ssModel,sum2,C,sum1,{'throttle';'r'},'y') );

end

function nlArxSys = nonLinARXmodel(data)
na        = [0 0 0; 0 0 0; 1 1 1];
nb        = [4 4 4 4; 4 4 4 4; 3 3 3 3];
nk        = [0 0 0 0; 0 0 0 0; 4 4 4 4];
Orders    = [na, nb, nk]; % found blackbox per-hand tuning
nlArxSys  = nlarx(data,Orders,'treepartition');
end

But I am getting the following error even though I clearly define throttle as the input signal to the throt_gain transfer function:

Error using DynamicSystem/connect (line 226)
No block lists "throttle" as an input name.

Error in closedLoopPoles (line 55)
clTF        = minreal( connect(ssModel,sum2,C,sum1,{'throttle';'r'},'y') );

To my understanding, the way how I am creating the system and connecting it is correct, then what am I doing wrong?

M.A.
  • 169
  • 1
  • 1
  • 18

0 Answers0