You are on page 1of 1

clc;clear all;close all;

%simulation time
t_sim=2;
%systeme parametres
J=0.22;
b=0.5e-3;
ke=1.2;
kt=1.2;
R=2.45;
L=0.035;
%transfert function
n=[kt];
d=[J*L ,(J*R+b*L) ,(b*R+ke*kt)];
G=tf(n,d);
tsim=0:0.1:t_sim;
u=ones(size(tsim));
y=lsim(G,u,tsim);
%plot the output figure(1)
plot(tsim,y,'k ','Linewidth',2),xlabel('Time[s]'),ylabel('Amplitude')
%pso parameters
itr=20;
N=40;
c=2;
wmax=0.7;
wmin=0.2;
var=3;
%search space
ib=0;
%lower bound
ub=100;
%upper bound
%optimisation
steps c_cf=0;
%ref
r_s=1;
%initialization
for m=1:N
for n=1:var v(m,n)=0;
%velocity particles
x(m,n)=ib+rand*(ub-ib);
%position particles
xp(m,n)=x(m,n);
end
%model parameters
kp=x(m,1);
ki=x(m,2);
kd=x(m,3);
%simulation model
Gc=pid(kp,ki,kd);
Gcf=feedback(Gc*G,1);
tsim=0:0.1:t_sim;
u=ones(size(tsim));
y=lsim(Gcf,u,tsim);
%objective function %itae
ffb(m)=0;
for m

You might also like