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

Control Project Code

This document contains MATLAB code to analyze and design a closed-loop control system. It defines system parameters, builds transfer functions for the open-loop and closed-loop systems, and simulates step responses. It then performs root locus analysis to calculate PD controller gains to improve the step response settling time to 6 seconds. With these gains, a new closed-loop simulation is run and shows the improved step response.

Uploaded by

ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Control Project Code

This document contains MATLAB code to analyze and design a closed-loop control system. It defines system parameters, builds transfer functions for the open-loop and closed-loop systems, and simulates step responses. It then performs root locus analysis to calculate PD controller gains to improve the step response settling time to 6 seconds. With these gains, a new closed-loop simulation is run and shows the improved step response.

Uploaded by

ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

%closed loop system

N1=50;
N2=250
N3=250;
Ja=0.05
JL=5
Da=0.01
DL=3
Kt=1;
Ra=5;
Kb=1;
kg1=(N1/N2);
kg2=(N2/N3);
J=Ja+JL*(kg1)^2
Dm=Da+DL*(kg1)^2
a=100;
k=3;
k1=100;
kpotout=1.5;
kpotin=2;
km=Kt/(J*Ra)
am=(Dm*Ra+Kb*Kt)/(J*Ra)
G=(kpotin*k*k1*km*kg1);
C=tf([G],conv([1 0],conv([1 am],[1 a])));
F=tf([kpotout*kg2/kpotin],[1]);
closedloop=feedback(C,F,-1)
step(closedloop)

Step Response
1.4

1.2

1
Amplitude

0.8

0.6

0.4

0.2

0
0 2 4 6 8 10 12 14
Time (seconds)

%S_S error zero


N1=50;
N2=250
N3=250;
Ja=0.05
JL=5
Da=0.01
DL=3
Kt=1;
Ra=5;
Kb=1;
kg1=(N1/N2);
kg2=(N2/N3);
J=Ja+JL*(kg1)^2
Dm=Da+DL*(kg1)^2
a=100;
k=3;
k1=100;
kpotout=1;
kpotin=1;
km=Kt/(J*Ra)
am=(Dm*Ra+Kb*Kt)/(J*Ra)
G=(kpotin*k*k1*km*kg1);
C=tf([G],conv([1 0],conv([1 am],[1 a])));
F=tf([kpotout*kg2/kpotin],[1]);
closedloop=feedback(C,F,-1)
step(closedloop)

Step Response
1

0.9

0.8

0.7

0.6
Amplitude

0.5

0.4

0.3

0.2

0.1

0
0 2 4 6 8 10 12
Time (seconds)

%CS vs OS
N1=50;
N2=250
N3=250;
Ja=0.05
JL=5
Da=0.01
DL=3
Kt=1;
Ra=5;
Kb=1;
kg1=(N1/N2);
kg2=(N2/N3);
J=Ja+JL*(kg1)^2
Dm=Da+DL*(kg1)^2
a=100;
k=3;
k1=100;
kpotout=1.5;
kpotin=2;
km=Kt/(J*Ra)
am=(Dm*Ra+Kb*Kt)/(J*Ra)
G=(kpotin*k*k1*km*kg1);
C=tf([G],conv([1 0],conv([1 am],[1 a])));
F=tf([kpotout*kg2/kpotin],[1]);
closedloop=feedback(C,F,-1)
%step(closedloop)
%parameters ouwww hell of a life
Os=1.68; % over shoot
Ts=5; % settling time
pi=3.141592654; % pi
x1=Os*0.01;
zt=-1*log(x1)/((pi*pi)+(log(x1)^2))^0.5 % zeta
wn=4/(Ts*zt) % natural frequency
sd=complex(-zt*wn,wn*(1-zt^2)^0.5) % dominant pole
D=abs(sd) % absolute value of dominant pole
E=sd+am % value of the denominator of gsd
E1=0.2526; % real value of E
y1=0.6150; % imaginary value of sd and all other roots
F=sd+a % second value of the denominator of sd
F1=49.2; % real value of F
EE=(atand(y1/E1)); % finding angle of E
FF=(atand(y1/F1)); % finding angle of F
beta=180-(atand(wn*(1-zt^2)^0.5/(zt*wn))) % the value of phase angle
Ad=G/((D)*abs(E)*abs(F)) % magnitude
OD=0-beta-EE-FF
kp= -1*sind( beta+ OD)/(Ad*sind(beta)) % the value of kp
kd=sind(OD)/(Ad*D*sind(beta)) % the value of kd
sdkp=sd+(kp/kd);
sdkpabs=abs(sdkp);
GCSGSD=kd*sdkpabs*Ad % proving that the point is a root locus
%PD controller, this is entertaining it had me sweat...
figure(1)
CC=tf(G*[kd kp],conv([1 0],conv([1 1.053],[1 50])));
Fd=tf([1],[1]);
T=feedback(CC,Fd,-1)
step (T,closedloop);
Step Response
1.4

1.2

1
Amplitude

0.8

0.6

0.4

0.2

0
0 2 4 6 8 10 12 14
Time (seconds)

%ST is 6 sec
N1=50;
N2=250
N3=250;
Ja=0.05
JL=5
Da=0.01
DL=3
Kt=1;
Ra=5;
Kb=1;
kg1=(N1/N2);
kg2=(N2/N3);
J=Ja+JL*(kg1)^2
Dm=Da+DL*(kg1)^2
a=100;
k=3;
k1=100;
kpotout=1.5;
kpotin=2;
km=Kt/(J*Ra)
am=(Dm*Ra+Kb*Kt)/(J*Ra)
G=(kpotin*k*k1*km*kg1);
C=tf([G],conv([1 0],conv([1 am],[1 a])));
F=tf([kpotout*kg2/kpotin],[1]);
closedloop=feedback(C,F,-1)
step(closedloop)
%parameters ouwww hell of a life
Os=1.68; % over shoot
Ts=6; % settling time
pi=3.141592654; % pi
x1=Os*0.01;
zt=-1*log(x1)/((pi*pi)+(log(x1)^2))^0.5 % zeta
wn=4/(Ts*zt) % natural frequency
sd=complex(-zt*wn,wn*(1-zt^2)^0.5) % dominant pole
D=abs(sd) % absolute value of dominant pole
E=sd+am % value of the denominator of gsd
E1=0.3860; % real value of E
y1=0.5125; % imaginary value of sd and all other roots
F=sd+a % second value of the denominator of sd
F1=49.3333; % real value of F
EE=(atand(y1/E1)); % finding angle of E
FF=(atand(y1/F1)); % finding angle of F
beta=180-(atand(wn*(1-zt^2)^0.5/(zt*wn))) % the value of phase angle
Ad=G/((D)*abs(E)*abs(F)) % magnitude
OD=0-beta-EE-FF
kp= -1*sind( beta+ OD)/(Ad*sind(beta)) % the value of kp
kd=sind(OD)/(Ad*D*sind(beta)) % the value of kd
sdkp=sd+(kp/kd);
sdkpabs=abs(sdkp);
GCSGSD=kd*sdkpabs*Ad % proving that the point is a root locus
%PD controller, this is entertaining it had me sweat...
figure(1)
CC=tf(G*[kd kp],conv([1 0],conv([1 1.053],[1 50])));
Fd=tf([1],[1]);
T=feedback(CC,Fd,-1)
step (T,closedloop);

Step Response
1.4

1.2

1
Amplitude

0.8

0.6

0.4

0.2

0
0 2 4 6 8 10 12 14
Time (seconds)

You might also like