www.gusucode.com > control 案例程序 matlab源码代码 > control/ArrayOf2DOFStdPIDControllersExample.m
%% Array of 2-DOF PID Controllers % Create a 2-by-3 grid of 2-DOF PI controllers in standard form. The % proportional gain ranges from 1–2 across the array rows, and % the integrator time constant ranges from 5–9 across columns. %% % To build the array of PID controllers, start with arrays % representing the gains. % Copyright 2015 The MathWorks, Inc. Kp = [1 1 1;2 2 2]; Ti = [5:2:9;5:2:9]; %% % When you pass these arrays to the |pidstd2| command, the command returns the % array of controllers. pi_array = pidstd2(Kp,Ti,0,Inf,0.5,0,'Ts',0.1,'IFormula','BackwardEuler'); size(pi_array) %% % If you provide scalar values for some coefficients, |pidstd2| automatically % expands them and assigns the same value to all entries in the array. For % instance, in this example, |Td| = 0, so that all entries in the array are % PI controllers. Also, all entries in the array have |b| = 0.5. % % Access entries in the array using array indexing. For dynamic system % arrays, the first two dimensions are the I/O dimensions of the model, and % the remaining dimensions are the array dimensions. Therefore, the % following command extracts the (2,3) entry in the array. pi23 = pi_array(:,:,2,3) %% % You can also build an array of PID % controllers using the |stack| command. C2 = pidstd2(1,5,0.1,Inf,0.5,0.5); % PID controller C2f = pidstd2(1,5,0.1,0.5,0.5,0.5); % PID controller with filter pid_array = stack(2,C2,C2f); % stack along 2nd array dimension %% % These commands return a 1-by-2 array of controllers. size(pid_array) %% % All PID controllers in an array must have the same sample time, discrete % integrator formulas, and dynamic system properties such as |InputName| % and |OutputName|.