⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pid_ga.m

📁 -PID controller has been extensively used in the industrial world. But in this controller it is dif
💻 M
字号:

clc
clear
close all
global sys_controlled
global time
global sysrl
%____________________________________________________________________
den1=[1 6 11 6 0];
num1=[1];
sysrl=tf(num1,den1);
%____________________________________________________________________
%Initialising the genetic algorithm
populationSize=80;
variableBounds=[0 40;0 40;0 40];
evalFN='PID_objfun_ITAE';
evalOps=[];
options=[1e-6 1];
initPop=initializega(populationSize,variableBounds,evalFN,...
evalOps,options);
%____________________________________________________________________
%Setting the parameters for the genetic algorithm
bounds=[-100 100;-100 100;-100 100];
evalFN='PID_objfun_ITAE';
evalOps=[];
startPop=initPop;
opts=[1e-6 1 0];
termFN='maxGenTerm';
termOps=220;
selectFN='normGeomSelect';
selectOps=0.08;
xOverFNs='arithXover';
xOverOps=4;
mutFNs='unifMutation';
mutOps=8;
%____________________________________________________________________
%Iterating the genetic algorithm
[x,endPop,bPop,traceInfo]=ga(bounds,evalFN,evalOps,startPop,opts,...
termFN,termOps,selectFN,selectOps,xOverFNs,xOverOps,mutFNs,mutOps);
%____________________________________________________________________
%Plotting Genetic algorithm controller Vs Root locus controller
%den1=[1 6 11 6 0];
%num1=[1];
%sysrl=tf(num1,den1);
%Transfer function of the Root Locus PID controller
%den_pid=[1 0];
%num_pid=[4.74 6 1.91]; %Kd Kp Ki
%rl_pid=tf(num_pid,den_pid);
%Placing PID controller in unity feedback system with 'sysrl'
%sys1=series(rl_pid,sysrl);
%rl_sys=feedback(sys1,[1]);
%Creating the optimal PID controller from GA results
ga_pid=tf([x(1) x(2) x(3)],[1 0]);
ga_sys=feedback(series(ga_pid,sysrl),1);
figure(1)
hold on;
step(ga_sys,'g',0:0.01:30);%Green-genetic algorithm
%legend('GA Controlled Sys','ZN Controlled Sys',2);

%____________________________________________________________________
%Printing to screen the PID values and
%comparing them to the Zeigler Nichols values
fprintf(' Genetic Algorithm values : Kd = %7.5f  Kp = %7.5f  Ki = %7.4f ',x(1),x(2),x(3));
%disp( x );
%____________________________________________________________________
%Plotting best population progress
figure(2)
subplot(3,1,1),plot(bPop(:,1),bPop(:,3)),...
title('Kp Value'),, ylabel('Gain');
subplot(3,1,2),plot(bPop(:,1),bPop(:,4)),...
title('Ki Value'),, ylabel('Gain');
subplot(3,1,3),plot(bPop(:,1),bPop(:,2)),...
title('Kd Value'),xlabel('Generations'), ylabel('Gain');
%____________________________________________________________________

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -