0% found this document useful (0 votes)
4K views

PID Algorithm in Matlab M File

This document contains Matlab code that simulates a PID controller for a first order time delay system. The code defines system parameters, initializes variables, contains a for loop that runs an ODE solver at each time step to calculate the system output, and plots the output over time. The PID controller is used to control the system to follow a reference input of 10 units.

Uploaded by

jagateesan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4K views

PID Algorithm in Matlab M File

This document contains Matlab code that simulates a PID controller for a first order time delay system. The code defines system parameters, initializes variables, contains a for loop that runs an ODE solver at each time step to calculate the system output, and plots the output over time. The PID controller is used to control the system to follow a reference input of 10 units.

Uploaded by

jagateesan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

% This Matlab code simulates a PID controller for a first order time delay system % G(s) = (K*e(-theta*s))/(T*s+1)

% Graduate Student % Faculty of Engineering and Technology % Annamalai University % Jagateesan .K %Electronics and Instrumentation 2008 - 2012 % India

clear all; clc; T=360; K=14.9; theta= 80; % System Parameters refe = 10; Tf = 1000; yold = 0;yold1=0; yp = []; ys_prime = []; er = refe; er1 = 0; er2 = 0; % Error (Initial error = Reference) % First derivative of error % Second derivative of error % Reference to follow % Simulation time

eold = refe; eold2 = 0; dt = 1; for i=1:dt:Tf dtspan = [i i+dt]; eold2 = eold ; eold = er;

er = refe - yold; er2 = er + eold2 - 2*eold; er1 = er - eold; init_con = [yold ; (yold-yold1)]; % Initial conditions for the diffirential equations options = []; [t,y] = ode45(@pid_ctrl,dtspan,init_con,options,er,er1,er2); yold1 = yold; ys = y(length(y),1); if i <= theta ys_prime = [0 ys_prime]; else ys_prime = [ys ys_prime]; end yold = ys_prime(1); yp = [yp yold]; end

plot(yp); xlabel('Time'); ylabel('Output'); title('Output of the system with PID Controller'); grid on;

You might also like