CS Lab Report
CS Lab Report
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".
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.
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];
%part2
% Define an arbitrary value of theta
theta = 1; % You can choose any value
%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)));
Result:
Activity 2 Codes:
%part1
give value of j
j=4;
%display values
disp(x)
disp(y)
disp(z)
part2
% Given values
omega = 10 * pi;
T = 0.1;
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;
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;
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];
%part2
% Given residues, poles, and direct term
r = [6, -4, 3];
p = [-3, -2, -1];
k = 2;
%code3
% Declare symbolic variables
syms t s
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
% Feedback combination
T = feedback(G123, H);
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]);
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');
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: