0% found this document useful (0 votes)
8 views32 pages

CS Lab Report

The document is a lab report on control systems, detailing various exercises involving relay logic, PLC programming, and MATLAB applications. It includes group member names, lab activities focusing on controlling systems like doors and conveyors, and MATLAB code for mathematical computations and control system design. Each lab section outlines objectives, procedures, and results for practical applications in control engineering.

Uploaded by

ab636185
Copyright
© © All Rights Reserved
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)
8 views32 pages

CS Lab Report

The document is a lab report on control systems, detailing various exercises involving relay logic, PLC programming, and MATLAB applications. It includes group member names, lab activities focusing on controlling systems like doors and conveyors, and MATLAB code for mathematical computations and control system design. Each lab section outlines objectives, procedures, and results for practical applications in control engineering.

Uploaded by

ab636185
Copyright
© © All Rights Reserved
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/ 32

Lab Report

Subject: Control System


Submitted To: Dr. Saad Hassan

Group Members:
Abdullah Arif FA20-BEE-142
Yasharah Idrees FA21-BEE-044
Abdul Hakeem FA20-BEE-153
Zain Hussain Khan FA20-BEE-154

Class: 8C/6C
Lab 1
Relay logic Introductory Lab
The I/O Simulator
For this exercise we will be using the I/O simulator section, which consists of 32 switches and
lights. Two groups of 16 toggle switches are shown connected to 2 Input cards of our simulated
PLC. Likewise two groups of 16 Lights are connected to two output cards of our PLC. The two
input cards are addressed as "I:1" and "I:3" while the output cards are addressed "O:2" and
"O:4".

Editing your Program

Click on the "Toggle" button of the PLC Panel which will put the PLC into the PGM mode and
bring the Edit Panel back into view.

Now add a second rung to your program as shown below. This time instead of entering the
addresses as you did before, try dragging the appropriate address which is displayed in the I/O
simulation and dropping it onto the instruction.

Stop/Start utilizing OTL and OTU


For this exercise we need two Normally Open momentary switches. Using your right mouse
button, click on switch "I:1/2" and "I:1/3", changing them to N.O. pushbuttons. Now add the
following two rungs to your program. Once you have the rungs entered correctly, download
and run your modified program.
Once you have the lamp ON, could you turn it off if power was lost in the Stop Switch circuit?
Ans: Yes, we can turn off the lamp by deactivating the I:1/0 switch.

Emulating Standard Stop/Start Control


Erase your program by selecting "New" from the "File" menu selection at the top of the screen.
When the dialog box appears just click on "OK" to select the default PLC type. Now enter the
following program. To enter a branch, just drag the branch (button) onto the rung and then
insert or drag instructions into the branch.
When someone presses the Stop Switch, will bit I:1/04 go True or False? Will the XIC instruction
go True or False when the Switch is pressed? Is this the logic we are seeking in this case? .... Run
the program and see if you're right! .... If we lose power in the Stop Switch circuit, what state
will the lamp go to?
Ans: If the bit I:1/04 is pressed the bit will be high but it will have no effect I:1/3 is high. This is
not the logic we want to see in this case since we have to turn off the output with stop switch
but in this case is having no effect If the I:1/3 is high and if we lose the power in the stop switch
circuit the output will still remain high.

Output Branching with RS Logix


Controlling One Light from two Locations
Create, enter and test a program which will perform the common electrical function of
controlling a light from two different locations. Clear your program and utilize toggle switch
(I:1/00) and switch (I:1/01) to control Lamp (O:2/00)... (Hint: If both switches are On or if both
switches are Off, then the Lamp should be On! This of course is just one approach to solving this
problem)
Lab 2
Door Simulation by applying Relay Logics
In this exercise we want you to apply your knowledge of Relay Logic Instructions to design a
program which will control the LogixPro Door Simulation. The Door System includes a
Reversible Motor, a pair of Limit Switches and an Operator Control Panel, all connected to your
PLC.

Student Exercise 1:
• In this exercise the Open and Close pushbuttons will be used to control the movement of the
door. Movement will not be maintained when either switch is released, and therefore the Stop
switch is neither required nor used in this exercise. However, all other available Inputs and
Outputs are employed in this exercise.
• Pressing the Open Switch will cause the door to move upwards (open) if not already fully open.
The opening operation will continue as long as the switch is held down. If the switch is released,
or if limit switch LS1 opens, the door movement will halt immediately.
• Pressing the Close Switch will cause the door to move down (close) if not already fully closed.
The closing operation will continue as long as the switch is held down. If the switch is released,
or if limit switch LS2 closes, the door movement will halt immediately.
• If the Door is already fully opened, Pressing the Open Switch will Not energize the motor.
• If the Door is already fully closed, Pressing the Close Switch will Not energize the motor.
• Under no circumstance will both motor windings be energized at the same time.
• The Open Lamp will be illuminated if the door is in the Fully Open position.
• The Shut Lamp will be illuminated if the door is in the Fully Closed position.
Student Exercise 2:
In this exercise we want you to apply your knowledge of Relay Logic Instructions to design a
program which will maintain the appropriate door movement once initiated by the operator.
The Opening or Closing operation of the door will continue to completion even if the operator
releases the pushbutton which initiated the movement. The program will adhere to the
following criteria:

• Door movement will halt immediately when the Stop Switch is initially pressed, and will
remain halted if the switch is released.
• Pressing the Open Switch will cause the door to Open if not already fully open. The
opening operation will continue to completion even if the switch is released.
• Pressing the Close Switch will cause the door to Close if not already fully shut. The
closing operation will continue to completion even if the Switch is released.
• If the Door is already fully opened, Pressing the Open Switch will Not energize the
motor.
• If the Door is already fully closed, Pressing the Close Switch will Not energize the motor.
• Under no circumstance will both motor windings be energized at the same time.
• The Ajar Lamp will be illuminated if the door is NOT in either the fully closed or fully
opened position.
• The Open Lamp will be illuminated if the door is in the Fully Open position.
• The Shut Lamp will be illuminated if the door is in the Fully Closed position.
Student Exercise 3:
In this exercise we want to introduce you to a simple programming technique for adding a bit of
"Flash" to your program. We want you to make use of the PLC's Free Running Timer which can
be viewed in the Data Table Display at location S2:4. This integer word contains a count which is
incremented continuously by the PLC when it is in the Run mode, and it can come in quite
handy at times for variety of purposes. In this exercise we want you to utilize this word as
follows:
With the PLC in the Run mode, Display word S2:4 utilizing the Data Table display. Ensure that
the Radix is set to Binary so that you can view the individual bits within the word. You should
see a binary count in progress where the rate of change of each bit is directly related to it's
position within the word. Bit 0 will have the highest rate, while Bit 1 will be 1/2 as fast as Bit 0,
and Bit 2 half as fast as 1 etc. etc.
We want you to add a Lamp Flasher to your program by monitoring the state of one of these
bits with an XIC instruction. I'm going to suggest using Bit 4 for this purpose, but depending
upon the speed of your computer you may elect to substitute another Bit. With an actual AB
PLC, the rate is consistent, but with LogixPro it varies from computer to computer.
Place an XIC instruction addressed to S:4/4 on the rung which controls either the Open or Shut
Lamp in your previous program. Now download and Run this modified program to see the
flashing effect achieved. The Lamp should flash at a reasonable rate whenever your program
energizes the selected Lamp.
Now modify your program so that the following criteria is met:

• If the Door is fully open, the Open lamp will be energized but not flashing as was the
case before.
• If the Door is opening, the Open lamp will flash while the door is in motion.
• If the Door is fully closed, the Shut lamp will be energized but not flashing as was the
case before.
• If the Door is closing, the Shut lamp will flash while the door is in motion.
• The Ajar Lamp will flash if the door is stationary, and is not in the fully open or fully
closed position. The Ajar Lamp will flash at a slower rate (1/4) then the other lamps.
• The Ajar Lamp will be illuminated in a steady state if the door is in motion.
Lab 3
The Silo Lab utilizing Relay Logic
Exercise #1 -- Continuous Operation
Completely design and de-bug a ladder control circuit which will automatically position and fill
the boxes which are continuously sequenced along the conveyor. Ensure that the following
details are also met:

• The sequence can be stopped and re-started at any time using the panel mounted Stop
and Start switches.
• The RUN light will remain energized as long as the system is operating automatically.
• The RUN light, Conveyor Motor and Solenoid will de-energize whenever the system is
halted via the STOP switch.
• The FILL light will be energized while the box is filling.
• The FULL light will energize when the box is full and will remain that way until the box
has moved clear of the proximity sensor.
Exercise #2 -- Container Filling with Manual Restart
• Stop the conveyor when the right edge of the box is first sensed by the prox-sensor.
• With the box in position and the conveyor stopped, open the solenoid valve and allow
the box to fill. Filling should stop when the Level sensor goes true.
• The FILL light will be energized while the box is filling.
• The FULL light will energize when the box is full and will remain that way until the box
has moved clear of the prox-sensor.
• Once the box is full, momentarily pressing the Start Switch will move the box off the
conveyor and bring a new box into position. Forcing the operator to hold the Start
button down until the box clears the prox-sensor is not acceptable.
Lab 1(MATLAB)
Familiarization with MATLAB window environment
Activity 1 Codes:
%part1
Define a set of arbitrary values for theta (in radians)
theta = [0, pi/6, pi/4, pi/3, pi/2, pi, 3*pi/2, 2*pi];

% Calculate sin(theta) and cos(theta)


sin_theta = sin(theta);
cos_theta = cos(theta);

% Calculate sin^2(theta) + cos^2(theta)


identity_check = sin_theta.^2 + cos_theta.^2;

% Display the results


disp('Theta values (in radians):');
disp(theta);
disp('sin^2(theta) + cos^2(theta):');
disp(identity_check);

%part2
% Define an arbitrary value of theta
theta = 1; % You can choose any value

% Calculate the hyperbolic sine using MATLAB's built-in function


lhs = sinh(theta);

% Calculate the right-hand side of the identity


rhs = (exp(1i * theta) - exp(-1i * theta)) / (2 * 1i);

% Display the results


disp(['sinh(' num2str(theta) ') using built-in function: ' num2str(lhs)]);
disp(['Calculated RHS: ' num2str(rhs)]);

% Check if the values are (approximately) equal


tolerance = 1e-10; % Define a tolerance for comparison
if abs(lhs - rhs) < tolerance
disp('The identity is verified for the given value of theta.');
else
disp('The identity is NOT verified for the given value of theta.');
end

% Define a range of theta values


theta = linspace(-pi/2, pi/2, 1000);

%Part3
% Compute the left-hand side of the identity
lhs = tan(theta);
% Compute the right-hand side of the identity
rhs = sqrt((1 - cos(2 * theta)) ./ (1 + cos(2 * theta)));

% Plot the left-hand side and the right-hand side


figure;
plot(theta, lhs, 'b-', 'LineWidth', 2); hold on;
plot(theta, rhs, 'r--', 'LineWidth', 2);
legend('tan(\theta)', 'sqrt((1 - cos(2\theta)) / (1 + cos(2\theta)))');
xlabel('\theta');
ylabel('Value');
title('Verification of tan(\theta) = sqrt((1 - cos(2\theta)) / (1 +
cos(2\theta)))');
grid on;
hold off;

Result:
Activity 2 Codes:
%part1
give value of j
j=4;

%write imaginary values


x=3+4j;
y=3+4*j;
z=3+j*4;

%display values
disp(x)
disp(y)
disp(z)

part2
% Given values
omega = 10 * pi;
T = 0.1;

% Define the complex numbers


G1 = 1 + 1i * omega * T;
G2 = 1 / (1 + 1i * omega * T);

% Calculate magnitude and phase for G1


magnitude_G1 = abs(G1);
phase_G1 = angle(G1);

% Calculate magnitude and phase for G2


magnitude_G2 = abs(G2);
phase_G2 = angle(G2);

% Convert phase to degrees


phase_G1_deg = rad2deg(phase_G1);
phase_G2_deg = rad2deg(phase_G2);

% Display the results


fprintf('G1(jw) = 1 + jwT:\n');
fprintf('Magnitude: %.4f\n', magnitude_G1);
fprintf('Phase (degrees): %.4f\n', phase_G1_deg);

fprintf('\nG2(jw) = 1 / (1 + jwT):\n');
fprintf('Magnitude: %.4f\n', magnitude_G2);
fprintf('Phase (degrees): %.4f\n', phase_G2_deg);

%part3
% Define the angular frequency
omega = 20 * pi;

% Define the complex function G(jomega)


G = @(omega) (1 - 1i * omega) / (1i * omega * (1 + 1i * 2 * omega));

% Substitute omega = 20pi into the function


G_value = G(omega);

% Calculate the magnitude of G(jomega)


magnitude = abs(G_value);

% Calculate the phase of G(jomega)


phase = angle(G_value);

% Display the results


fprintf('Magnitude of G(jomega) at omega = 20pi: %.4f\n', magnitude);
fprintf('Phase of G(jomega) at omega = 20pi: %.4f radians\n', phase);

Results:

Activity 3 Codes:
%part1
%define matrices
A=[2 5 -3; 3 -2 4; 1 6 -4];
B=[6; -2; 3];

%find inverse
x=inv (A)*(B)

%part2
%Define matrices
A=[8 1 6; 3 5 7; 4 9 2];
B=[6 -1 4; 1 3 5; 2 7 0];
C=[3; 5; 8];

%Different solutions
x=A+B;
y=B-C;
z=A*C;
p=A.*B;
q=A./C;
r=(B.*C)^3;

%Display Solutions
disp(x)
disp(y)
disp(z)
disp(p)
disp(q)
disp(r)

%part3
% Step 1: Create the vector t
t = 1:10;

% Step 2: Define the parameters T and k


T = 2;
k = 0.75;

% Step 3: Calculate omega(t)


omega_t = k * (1 - exp(-t / T));

% Display the result


disp('The vector t:');
disp(t);

disp('The omega(t) values:');


disp(omega_t);

Results:
Lab 2(MATLAB)
Designing Control Systems using Control Systems Toolbox and
Symbolic Math Toolbox
Class Codes:
%Code 1
N=[10 40];
D=[1 2 3 0];
[A,P,k]=residue(N,D)

%Code2
N=13;
D=[1 6 22 30 13 0];
(A,P,k)=residue(N,D)

%Code3
n1=[5 1];
n2=[15 1];
d1=[1 0];
d2=[3 1];
d3=[10 1];
num=100*conv(n1,n2);
den=conv(d1,conv(d2,d3));
GH=tf(num,den);

%Code4
syms s a b;
G=b/((s+a)^2+b^2);
pretty(G)
x=ilaplace(G);
Results:
Activity Codes:
%part1
% Define the numerator and denominator coefficients
numerator_coeffs = [2 5 3 6];
denominator_coeffs = [1 6 12 0];

% Use the residue function to find the partial fraction decomposition


[r, p, k] = residue(numerator_coeffs, denominator_coeffs);

% Display the results


disp('Residues (r):');
disp(r);
disp('Poles (p):');
disp(p);
disp('Direct term (k):');
disp(k);

%part2
% Given residues, poles, and direct term
r = [6, -4, 3];
p = [-3, -2, -1];
k = 2;

% Convert partial fractions to the transfer function form


[num, den] = residue(r, p, k);

% Display the numerator and denominator coefficients


disp('Numerator coefficients:');
disp(num);
disp('Denominator coefficients:');
disp(den);

% Create transfer function


sys = tf(num, den);

% Display the transfer function


disp('Transfer function:');
disp(sys);

%code3
% Declare symbolic variables
syms t s

% Define the function g(t)


g = 1 + (1/3)*exp(-4*t) - (4/3)*exp(-t);

% Manual calculation of the Laplace transform


L1 = 1/s; % Laplace transform of 1
L2 = 1/(3*(s + 4)); % Laplace transform of (1/3)*exp(-4*t)
L3 = -4/(3*(s + 1)); % Laplace transform of -(4/3)*exp(-t)

% Sum the manual results


L_manual = L1 + L2 + L3;
% Display the manual result
disp('Manual Laplace transform of g(t):');
disp(L_manual);

% Use the laplace function to calculate the Laplace transform


L_symbolic = laplace(g, t, s);

% Display the result from the laplace function


disp('Laplace transform of g(t) using the laplace function:');
disp(L_symbolic);

% Check if both results are equal


is_equal = simplify(L_manual - L_symbolic) == 0;
disp('Are the manual and symbolic results equal?');
disp(is_equal);

Results:
Lab 4 (MATLAB)
Feedback Control System Simulation
Class Codes:
%code1
num1=[0 0 1];
den1=[500 0 0];
num2=[0 1 1];
den2=[0 1 2];
[num,den]=series(num1,den1,num2,den2);
G=tf(num,den)

%code2
num1=[0 0 1];
den1=[500 0 0];
num2=[0 1 1];
den2=[0 1 2];
[num,den]=parallel(num1,den1,num2,den2);
G=tf(num,den)
%code3
G1=tf([0 1],[1 7]);
G2=tf([0 0 1],[1 2 3]);
G3=tf([0 1],[1 4]);
G4=tf([0 1],[1 0]);
G5=tf([0 5],[1 7]);
G6=tf([0 0 10],[1 5 10]);
G7=tf([0 3],[1 2]);
G8=tf([0 1],[1 6]);
G9=tf([1],[1]);
T1=append(G1,G2,G3,G4,G5,G6,G7,G8,G9);
Q=[1 -2 -5 9
2 1 8 0
3 1 8 0
4 1 8 0
5 3 4 -6
6 7 0 0
7 3 4 -6
8 7 0 0];
inputs=9;
outputs=7;
Ts=connect(T1,Q,inputs,outputs);
T=tf(Ts);

Results:
Activity Codes:
% Define transfer functions
G1 = tf(1, [1 0 0]); % 1/s^2
G2 = tf(50, [1 1]); % 50/(s+1)
G3 = tf(5, 1); % 5
G4 = tf(2, 5); % 2/5
G5 = tf(2, 1); % 2

% Series combination of G1, G2, G3


G123 = series(G1, G2);
G123 = series(G123, G3);

% Series combination of G4 and G5 for the feedback path


H = series(G4, G5);

% Feedback combination
T = feedback(G123, H);

% Display the result


T

Results:

Lab 5 (MATLAB)
Time Response Characteristics of Control Systems
Class Codes:
%code1
num=[0 0 25];
den=[1 4 25];
sys=tf(num,den);
ltiview({'step','impulse','pzmap'})

%Code2
num=[0 0 1];
den=[1 0.2 1];
sys=tf(num,den);
impulse(sys)
grid
title('unit impulse reponse of G(s)')
xlabel('t(sec)')
ylabel('response')

%Code3
num=[25];
den=[1 5 0];
G=tf(num,den);
T=feedback(G,1,-1);
[numt,dent]=tfdata(T,'v');
wn=sqrt(dent(3));
z=dent(2)/(2*wn);
Ts=4/(z*wn);
Tp=pi/(wn*sqrt(1-z^2));
pos=exp(-z*pi/sqrt(1-z^2))*100;
step(T)

Results:
Activity Codes:
% Task 1: Plot step responses and poles/zeros for given transfer functions

% Transfer functions
T1 = tf(400, [1 12 400]);
T2 = tf(900, [1 90 900]);
T3 = tf(225, [1 30 225]);
T4 = tf(625, [1 0 625]);

% Plot step responses


figure;
subplot(2,2,1);
step(T1);
title('Step Response of T(s) = 400/(s^2 + 12s + 400)');
subplot(2,2,2);
step(T2);
title('Step Response of G(s) = 900/(s^2 + 90s + 900)');
subplot(2,2,3);
step(T3);
title('Step Response of Y(s) = 225/(s^2 + 30s + 225)');
subplot(2,2,4);
step(T4);
title('Step Response of X(s) = 625/(s^2 + 625)');

% Plot pole-zero maps


figure;
subplot(2,2,1);
pzmap(T1);
title('Pole-Zero Map of T(s)');
subplot(2,2,2);
pzmap(T2);
title('Pole-Zero Map of G(s)');
subplot(2,2,3);
pzmap(T3);
title('Pole-Zero Map of Y(s)');
subplot(2,2,4);
pzmap(T4);
title('Pole-Zero Map of X(s)');

% Task 2: Response of the system for given input


G = tf([1 10], [1 6 9 10]);
t = 0:0.01:10;
r = exp(-0.5*t);
[y, t_out, x_out] = lsim(G, r, t);

figure;
plot(t_out, y);
title('Response of G(s) = (s+10)/(s^3+6s^2+9s+10) for r(t) = e^{-0.5t}');
xlabel('Time (s)');
ylabel('Response');

% Task 4: Transient response of the given feedback system


H = tf(225, [1 12 0]);
H_cl = feedback(H, 1); % Closed-loop transfer function
figure;
step(H_cl);
title('Transient Response of the Feedback System H(s) = 225/(s(s+12))');

Results:
Lab 7 (MATLAB)
PID Controller Design using MATLAB
Class Codes:
%code1
J=0.01;
b=0.1;
K=0.01;
R=1;
L=0.5;
s=tf('s');
p_motor=K/((J*s+b)*(L*s+R)+K^2)
Kp=100;
C=pid(Kp);
sys_cl=feedback(C*p_motor,1)
t=0:0.01:5;
step(sys_cl,t)
grid
title('step response with proportional control')

%code2
J=0.01;
b=0.1;
K=0.01;
R=1;
L=0.5;
s=tf('s');
p_motor=K/((J*s+b)*(L*s+R)+K^2)
Kp=100;
Ki=1;
Kd=1;
C=pid(Kp,Ki,Kd);
sys_cl=feedback(C*p_motor,1)
t=0:0.01:5;
step(sys_cl,t)
grid
title('step response with proportional control')

Results:
Lab 6 (MATLAB)
Mathematical Modeling for DC Motor Speed Control
Class Codes:
%code1
J=0.01;
b=0.1;
K=0.01;
R=1;
L=0.5;
s=tf('s');
p_motor=K/((J*s+b)*(L*s+R)+K^2)

%Code2
A=[-b/J K/J
-K/L -R/L];
B=[0
1/L];
C=[1 0];
D=0;
motor=ss(A,B,C,D);
motors=ss(p_motor);

Results:

You might also like