Fitness Function In the PSO algorithm

6 views (last 30 days)
Maria
Maria on 15 May 2014
Answered: Walter Roberson on 31 Dec 2018
My problem it is about PSO with PID controller , i just tried to tune PID parameters with PSO for tracking circular path as input (input is circular path ) with desired velocity = 0.25 [meter/sec] and desired azimuth given by = (2 * 3.14 * f(t)/m) rad , with m = -40 where m is the slop, f(t)=t , 0=t=40 and sampling time = 0.01 sec . I wrote the code of PSO but it does not work , I think the problem is in the fitness function structure of PSO algorithm and I don't know what is the bugs in the code below ,the fitness function should compute the Mean Square Error , please I hope from you to help me .
In the picture below the desired input is a circular path with a above parameters and the actual output is should be as the desired input .
Many thanks
the fitness function that I wrote :
function F = FitnessFun(pid)
Kp1 = pid(1);
Ki1 = pid(2);
Kd1 = pid(3);
Kp2 = pid(4);
Ki2 = pid(5);
Kd2 = pid(6);
sprintf('The value of interation Kp= %3.0f, Kd= %3.0f', pid(1),pid(2),pid(3),pid(4),pid(5),pid(6));
% Compute function value
simopt = simset('solver','ode5','SrcWorkspace','Current','DstWorkspace','Current'); % Initialize sim options
[tout,xout,yout] = sim('sim1',[0 100],simopt);
n=1;m=-40;
for t=0.3:.3:2*pi
theta_d(n)=((2*pi)* t/m);
n=n+1;
end
t=1:20;
v=step(1,t);
[theta,t]=lsim(theta_d,t);
for k=1:20
eth(k)=theta(k)-theta_d(k);
end
ev=(-v+1);
out=sum((ev.^2)+sum(eth.^2))/20;
F=out;
end
  2 Comments
Maria
Maria on 18 May 2014
Any one can answer ? please
Adityabaradwaj Sixth sem
Adityabaradwaj Sixth sem on 31 Dec 2018
Could you post the complete code?? I think there maybe an error in
subsequent lines of code.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 31 Dec 2018
step requires a tf or genss as input, or else a system object of some kind such as aa cascade object detector.

Tags

Community Treasure Hunt

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

Start Hunting!