GA Algorithm for PID tuning

조회 수: 12 (최근 30일)
SURBHI GOEL
SURBHI GOEL 2020년 11월 8일
편집: Sam Chak 2023년 10월 31일
I have a second order transfer function which I want to control using PID controller. I want Kp, Ki, Kd values using GA toolbox in matlab. My question is if I want suppose 5% overshoot or 0.1s settling time, how can I specify it in fitness function/app?
Here is my fitness function
function J = pidtest(x)
s = tf('s');
G = 49/(s^2+7*s+49);
Kp=x(1); Ki=x(2); Kd=x(3);
controller = Kp + Ki/s + Kd*s;
Loop = series(controller,G);
ClosedLoop = feedback(Loop,1);
dt = 0.1;
t = 0:dt:30;
y = step(ClosedLoop,t);
J = sum(t'.*abs(1-y)*dt); %ITAE
  댓글 수: 1
krishna
krishna 2023년 10월 31일
thanks surbhi for this code . can you help me , if my plant is quadcopter(drone) whose output is position(x, y , z) and angle(phi, theta, psi) so how i can tune PID controller using Genetic algorithm?

댓글을 달려면 로그인하십시오.

답변 (1개)

Sam Chak
Sam Chak 2023년 10월 31일
편집: Sam Chak 2023년 10월 31일
Sometimes you can let GA randomly search during the initial run to observe if the performance requirements are satisfied.
s = tf('s');
Gp = 49/(s^2 + 7*s + 49)
Gp = 49 -------------- s^2 + 7 s + 49 Continuous-time transfer function.
step(Gp, 2), grid on
nvars = 3;
[K, fval] = ga(@pidtest, nvars)
ga stopped because the average change in the fitness value is less than options.FunctionTolerance.
K = 1×3
13.8153 96.6499 1.9877
fval = 3.5202e-05
Gc = K(1) + K(2)/s + K(3)*s; % ideal type
Gcl = feedback(Gc*Gp, 1);
step(Gcl, 2), grid on
S = stepinfo(Gcl)
S = struct with fields:
RiseTime: 0.0226 TransientTime: 0.0404 SettlingTime: 0.0404 SettlingMin: 0.9040 SettlingMax: 0.9989 Overshoot: 0 Undershoot: 0 Peak: 0.9989 PeakTime: 0.0751
function J = pidtest(K)
s = tf('s');
% plant
G = 49/(s^2 + 7*s + 49);
% pid controller
Kp = K(1);
Ki = K(2);
Kd = K(3);
controller = Kp + Ki/s + Kd*s; % ideal type
% closed-loop tf
Loop = series(controller, G);
ClosedLoop = feedback(Loop, 1);
% cost
dt = 0.1;
t = 0:dt:3;
y = step(ClosedLoop, t);
J = sum(t'.*abs(1-y)*dt); % ITAE
end

카테고리

Help CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by