PID Controller tuning process

1 visualizzazione (ultimi 30 giorni)
Maria
Maria il 12 Lug 2014
Commentato: Image Analyst il 13 Lug 2014
Please if anyone could help I really need help I am working with tuning process for a close-loop system with two PIDs by using PSO (PARTICLE SWARM OPTIMIZATION) but the results of PIDs parameters that get from the algorithm don't give the desired values of the system , could anyone help me , what is the wrong thing in the code ? the code is below
%------------------%
% The code %
%------------------%
clc n = 50; % Size of the swarm " no of birds "
bird_setp =50; % Maximum number of "birds steps"
dim = 6;
K=0;
% Dimension of the problem
xmax=[200 10 100 200 10 100 ] xmin=[10 0 0 160 0 0 ]
c2 =1.2; % PSO parameter C1
c1 = 1.2; % PSO parameter C2
w =0.9; % pso momentum or inertia
fitness=0*ones(n,bird_setp);
R1 = rand(n,dim);
R2 = rand(n,dim);
current_fitness =0*ones(n,1);
for i= 1:n
for j= 1:dim
current_position (i,j)=rand*(xmax(j)-xmin(j))+xmin(j);
end
end
%current_position
velocity = .3*randn(n,dim) ;
local_best_position = current_position ;
K=current_position
for i=1:n
% Parameters of PID 1 P1=K(i,1); D1=K(i,2); I1=K(i,3);
% Parameters of PID 2 P2=K(i,4); D2=K(i,5); I2=K(i,6);
simopt = simset('solver','ode4','SrcWorkspace','Current','DstWorkspace','Current'); % Initialize sim options
[tout,xout,yout] = sim('PID_Simulink',[0 10],simopt);
e1=abs(Error_Velocity);
e1=sum(e1);
e2=abs(Error_theta);
e2=sum(e2);
F(i)=e1+e2;
end
local_best_fitness = F ;
[global_best_fitness,g] = min(local_best_fitness) ;
for i=1:n
globl_best_position(i,:) = local_best_position(g,:) ;
end
%globl_best_position
dif1=local_best_position-current_position;
dif2=globl_best_position-current_position; %-------------------% % VELOCITY UPDATE % %-------------------%
velocity = w velocity + c1(R1.*(local_best_position-current_position)) + c2*(R2.*(globl_best_position-current_position));
%------------------%
% SWARMUPDATE %
%------------------%
current_position = current_position + velocity ;
%------------------------%
% evaluate anew swarm %
%------------------------%
iter = 0 ; % Iterations’counter
while ( iter < bird_setp )
iter = iter + 1
for i = 1:n,
% Parameters of PID 1 P1=K(i,1); D1=K(i,2); I1=K(i,3);
% Parameters of PID 2 P2=K(i,4); D2=K(i,5); I2=K(i,6);
simopt = simset('solver','ode4','SrcWorkspace','Current','DstWorkspace','Current'); %
Initialize sim options
[tout,xout,yout] = sim('PID_Simulink',[0 10],simopt);
e1=abs(Error_Velocity);
e1=sum(e1);
e2=abs(Error_theta);
e2=sum(e2);
F(i)=e1+e2;
end
for i = 1 : n
if F(i) < local_best_fitness(i)
local_best_fitness(i) = F(i);
local_best_position(i,:) = current_position(i,:) ;
end
end
[current_global_best_fitness,g] = min(local_best_fitness);
if current_global_best_fitness < global_best_fitness
global_best_fitness = current_global_best_fitness;
for i=1:n
globl_best_position(i,:) = local_best_position(g,:);
end
end
velocity = w *velocity + c1*(R1.*(local_best_position-current_position)) + c2*(R2.*(globl_best_position-current_position));
current_position = current_position + velocity;
sprintf('The value of interation iter %3.0f ', iter );
end
globl_best_position(i,:)=K(1,:);
simopt = simset('solver','ode4','SrcWorkspace','Current','DstWorkspace','Current');
% Initialize sim options
[tout,xout,yout] = sim('PID_Simulink',[0 10],simopt);
plot(xd,yd,'r', x,y,'k')

Risposte (0)

Tag

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by