Lab4 108 CS P
Lab4 108 CS P
Objectives:
To Design PID Controller for different systems.
In-Lab Experiments:
Mass-Spring-Damper Model
clc
close all
clear all
%%
M = 1;
B = 10;
K = 20;
Kp = 350; %propotional
Kd = 50; %derivative
Ki = 300; %integral
%%
num = [1];
den = [M B K];
system = pid(Kp, Ki, Kd)
System=tf(num, den)
subplot(211)
step(System)
legend('step responance')
s = series(system, System);
sys = feedback(s, 1);
subplot(212)
step(sys)
steady_error = abs(dcgain(1-sys))
stepinfo(sys)
legend('step responance')
Simulink
clc
clear all
close all
M = 1;
b = 10;
k = 20;
F = 1;
Task 2
clc
close all
clear all
%%
m = 0.111;
R = 0.015;
g = -9.8;
L = 1;
d = 0.03;
J = 9.99e-6;
Kp =100;
Ki = 120;
Kd = 250;
%%
num = [-(m.*g.*d)];
den = [L.*(J./(R.^2)+m) 0 0];
sys1 = tf(num, den)
sys2 = pid(Kp, Ki, Kd)
s = series(sys1, sys2);
system = feedback(s, 1)
step(system)
grid on
legend('step responance')
stepinfo(system)
steady_error = abs(dcgain(1-system))
Simulink
Post lab 1
clc
close all
clear all
%%
Kp = input ('Enter the value of Kp = ');
Ki = input ('Enter the value of Ki = ');
Kd = input ('Enter the value of Kd = ');
%%
C = pid(Kp,Ki,Kd);
num = [Kd Kp Ki];
den = [0 1 0];
PID = tf(num , den);
num1 = [400];
den1 = [1 48.5 0];
Tf1 = tf(num1 , den1)
figure
step(Tf1)
grid on
legend('step responance')
OTF = series(PID , Tf1)
OFTF = feedback(OTF , 1)
figure
step(OFTF)
stepinfo(OFTF)
grid on
legend('step responance')
Post lab 2
clc
close all
clear all
%%
Kp = input('Enter the value of Kp = ');
Ki = input('Enter the value of Ki = ');
Kd = input('Enter the value of Kd = ');
%%
C = pid(Kp,Ki,Kd);
num = [Kd Kp Ki];
den= [0 1 0];
PID = tf(num , den);
B=10;
K=20;
J = 9.9.*(10.^-9); L=1;
R = 0.015;
num2 = [K];350
den2=[J.*L ((J.*R)+(B.*L).*(B.*R)+(K.^2))];
TF = tf(num2 , den2)
figure
grid on
legend('step responance')
step(TF)
OTF = series(PID,TF)
OFTF = feedback(OTF,1)
figure
step(OFTF)
grid on
legend('step responance')
Info = stepinfo(OFTF)
err = abs(dcgain(1 - OFTF))