0% found this document useful (0 votes)
41 views

PID Controller Lab

This document provides MATLAB code to simulate a PID controller. It defines a transfer function for a plant and applies feedback control using proportional, integral and derivative gains. The code is run twice, first with default gain values and then with increased Kp, Kd and Ki values. The second simulation shows reduced overshoot and oscillation, indicating a more stable response.

Uploaded by

Janup Pokharel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

PID Controller Lab

This document provides MATLAB code to simulate a PID controller. It defines a transfer function for a plant and applies feedback control using proportional, integral and derivative gains. The code is run twice, first with default gain values and then with increased Kp, Kd and Ki values. The second simulation shows reduced overshoot and oscillation, indicating a more stable response.

Uploaded by

Janup Pokharel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PID Controller:

MATLAB Code
1. 2.
>> %Example of PID controller >> %Example of PID controller
>> clear all; >> clear all;
>> num=[1]; >> num=[1];
>> den=[2 2 1]; >> den=[2 2 1];
>> sys=tf(num,den); >> sys=tf(num,den);
>> H=1; >> H=1;
>> Gs=feedback(sys,H); >> Gs=feedback(sys,H);
>> step(Gs) >> step(Gs)
>> hold on; >> hold on;
>> grid on; >> grid on;
>> Kp=1; >> Kp=12;
>> Kd=0; >> Kd=10;
>> Ki=0; >> Ki=5;
>> s=tf('s'); >> s=tf('s');
>> Gc=(Kp+(Ki/s)+(s*Kd)); >> Gc=(Kp+(Ki/s)+(s*Kd));
>> Go=feedback(Gc*sys,H); >> Go=feedback(Gc*sys,H);
>> step(Go) >> step(Go)
>> grid on; >> grid on;
On further changing the values of Kp=12, Kd=10 and Ki=5, obtained graph is shown below:

It is seen that peak overshoot as well as oscillation has decreased and system is in stable state.

You might also like